BlockHound JUnit Platform Integration

Integrates the BlockHound Java agent to detect blocking calls in JUnit Platform-based tests.

License

License

Categories

Categories

JUnit Unit Testing React User Interface Web Frameworks ORM Data Reactor Container Microservices Reactive libraries
GroupId

GroupId

io.projectreactor.tools
ArtifactId

ArtifactId

blockhound-junit-platform
Last Version

Last Version

1.0.6.RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

BlockHound JUnit Platform Integration
Integrates the BlockHound Java agent to detect blocking calls in JUnit Platform-based tests.
Project URL

Project URL

https://github.com/reactor/BlockHound
Source Code Management

Source Code Management

https://github.com/reactor/BlockHound/

Download blockhound-junit-platform

How to add to project

<!-- https://jarcasting.com/artifacts/io.projectreactor.tools/blockhound-junit-platform/ -->
<dependency>
    <groupId>io.projectreactor.tools</groupId>
    <artifactId>blockhound-junit-platform</artifactId>
    <version>1.0.6.RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/io.projectreactor.tools/blockhound-junit-platform/
implementation 'io.projectreactor.tools:blockhound-junit-platform:1.0.6.RELEASE'
// https://jarcasting.com/artifacts/io.projectreactor.tools/blockhound-junit-platform/
implementation ("io.projectreactor.tools:blockhound-junit-platform:1.0.6.RELEASE")
'io.projectreactor.tools:blockhound-junit-platform:jar:1.0.6.RELEASE'
<dependency org="io.projectreactor.tools" name="blockhound-junit-platform" rev="1.0.6.RELEASE">
  <artifact name="blockhound-junit-platform" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.projectreactor.tools', module='blockhound-junit-platform', version='1.0.6.RELEASE')
)
libraryDependencies += "io.projectreactor.tools" % "blockhound-junit-platform" % "1.0.6.RELEASE"
[io.projectreactor.tools/blockhound-junit-platform "1.0.6.RELEASE"]

Dependencies

compile (1)

Group / Artifact Type Version
io.projectreactor.tools : blockhound jar 1.0.6.RELEASE

Project Modules

There are no modules declared in this project.

BlockHound

Travis CI Gitter

Java agent to detect blocking calls from non-blocking threads.

How it works

BlockHound will transparently instrument the JVM classes and intercept blocking calls (e.g. IO) if they are performed from threads marked as "non-blocking operations only" (ie. threads implementing Reactor's NonBlocking marker interface, like those started by Schedulers.parallel()). If and when this happens (but remember, this should never happen! 😜 ), an error will be thrown. Here is an example:

// Example.java
BlockHound.install();

Mono.delay(Duration.ofSeconds(1))
    .doOnNext(it -> {
        try {
            Thread.sleep(10);
        }
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    })
    .block();

Will result in:

reactor.blockhound.BlockingOperationError: Blocking call! java.lang.Thread.sleep
	at java.base/java.lang.Thread.sleep(Native Method)
	at com.example.Example.lambda$exampleTest$0(Example.java:16)

Note that it points to the exact place where the blocking call got triggered. In this example it was Example.java:16.

Getting it

Download it from Maven Central repositories (stable releases only) or repo.spring.io:

Gradle

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'
}

Maven

<dependencies>
  <dependency>
    <groupId>io.projectreactor.tools</groupId>
    <artifactId>blockhound</artifactId>
    <version>$LATEST_RELEASE</version>
  </dependency>
</dependencies>

Where:

$LATEST_RELEASE
$LATEST_MILESTONE
$LATEST_SNAPSHOT

Built-in integrations

Although BlockHound supports the SPI mechanism to integrate with, it comes with a few built-in integrations:

  1. Project Reactor
    Version 3.2.x is supported out of the box.
    Starting with reactor-core version 3.3.0, there is a built-in integration in Reactor itself that uses the SPI.
  2. RxJava 2 is supported.
    RxJava 3 and further versions of RxJava will require an SPI to be implemented, either by the framework or user. See this PR to RxJava with an example of the SPI's implementation.

Quick Start

See the docs.


Licensed under Apache Software License 2.0

Sponsored by Pivotal

io.projectreactor.tools

Reactor

Reactive Streams based projects for backpressure-ready asynchronous message passing.

Versions

Version
1.0.6.RELEASE
1.0.5.RELEASE
1.0.4.RELEASE
1.0.3.RELEASE
1.0.2.RELEASE
1.0.1.RELEASE
1.0.0.RELEASE