在我的集成测试中,我使用BlockHound捕获任何阻塞调用。为了设置数据,我正在执行阻塞调用,因为在运行每个测试时,我希望数据被持久化到DB中。在运行集成测试时,Blockhound在设置方法上抛出一个错误:reactor.blockhound.BlockingOperationError:阻塞调用!java.io.FileInputStream#readBytes
如何避免这种情况?
@BeforeAll
public static void blockHoundSetup() {
BlockHound.install();
}
@BeforeEach
public void setUp() {
stagingAreaAdapter.deleteAll()
.thenMany(Flux.fromIterable(data))
.flatMap(stagingAreaAdapter::save)
.blockLast();
}发布于 2022-01-13 13:19:04
检查BlockHound自定义以允许和禁止方法中的阻塞调用:https://github.com/reactor/BlockHound/blob/master/docs/customization.md#dis-allowing-blocking-calls-inside-methods
1.在@BeforeAll方法中使用构建器的(如 @KrisKris1):
@BeforeAll
public static void blockHoundSetup() {
BlockHound.builder().allowBlockingCallsInside(
TestClass.class.getName(), "setUp").install();
} 或
2.通过实现BlockHoundIntegration接口(仍然适用于全球):
public class BlockHoundCustomConfiguration implements BlockHoundIntegration {
@Override
public void applyTo(BlockHound.Builder builder) {
builder.allowBlockingCallsInside("java.base/java.io.RandomAccessFile", "readBytes");
}
}并使用自定义类创建以下文件:<project dir>/src/test/resources/META-INF/services/reactor.blockhound.integration.BlockHoundIntegration:
com.example.config.BlockHoundCustomConfiguration发布于 2022-08-03 21:36:05
您需要允许在java.util.zip.InflaterInputStream#read中对调用堆栈进行阻塞方法调用。
添加您的BlockHound自定义配置。
public class ReactorBlockHoundIntegration implements BlockHoundIntegration {
@Override
public void applyTo(BlockHound.Builder builder) {
builder.allowBlockingCallsInside(InflaterInputStream.class.getName(), "read");
}
}https://docs.oracle.com/javase/8/docs/api/index.html?java/util/zip/package-summary.html
https://stackoverflow.com/questions/66674587
复制相似问题