我正在尝试将 BlockHound ( https://github.com/reactor/BlockHound ) 集成到我的项目中。使用 SecureRandom 时,我需要一个自定义配置来跳过阻塞。我尝试了以下设置。在我的测试资源中,我有一门课:
@AutoService(BlockHoundIntegration.class)
public class BlockHoundSecureRandom implements BlockHoundIntegration {
@Override
public void applyTo(Builder builder) {
builder.allowBlockingCallsInside("java.security.SecureRandom", "next");
}
}
在我的 build.gradle 文件中我添加了:
testImplementation 'org.junit.platform:junit-platform-launcher'
testImplementation 'com.google.auto.service:auto-service-annotations:1.0'
testAnnotationProcessor 'com.google.auto.service:auto-service:1.0'
testImplementation 'io.projectreactor.tools:blockhound-junit-platform:1.0.6.RELEASE'
我遇到的问题是我的自定义 BlockHoundSecureRandom 未注册。AutoService 注释和注释处理器应该在 META-INF/services 下创建具有服务注册的文件。但是,没有生成任何内容并且测试失败。当我手动创建服务注册时,一切都按预期工作。知道缺少什么以便 AutoService 可以注册我的服务吗?
编辑:我启用了调试模式并看到文件已生成但位置错误:
构建/类/java/test/...
对于 gradle 项目,它应该位于:
构建/资源/测试/...