Download it from repo.spring.io or Maven Central repositories (stable releases only):
repositories {
mavenCentral()
// maven { url 'https://repo.spring.io/milestone' }
// maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
testCompile 'io.projectreactor.tools:blockhound:$LATEST_RELEASE'
// testCompile 'io.projectreactor.tools:blockhound:$LATEST_MILESTONE'
// testCompile 'io.projectreactor.tools:blockhound:$LATEST_SNAPSHOT'
}
Where:
$LATEST_RELEASE |
|
$LATEST_MILESTONE |
|
$LATEST_SNAPSHOT |
BlockHound is a JVM agent. You need to "install" it before it starts detecting the issues:
BlockHound.install();
On install, it will discover all known integrations (see writing custom integrations for details) and perform a one time instrumentation (see how it works). The method is idempotent, you can call it multiple times.
The best place to put this line is before any code gets executed, e.g. @BeforeClass
, or static {}
block, or test listener.
BlockHound also supports some testing frameworks.
NB: it is highly recommended to add a dummy test with a well-known blocking call to ensure that it installed correctly.
Something like this will work:
Mono.delay(Duration.ofMillis(1))
.doOnNext(it -> {
try {
Thread.sleep(10);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
})
.block(); // should throw an exception about Thread.sleep
You can further customize Blockhound's behavior, see customization.