Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add BlockHound to a spring boot app to detect blocking calls?

How to add BlockHound to spring boot app to detect blocking calls ?

I didn't find any examples for spring boot apps: https://github.com/reactor/BlockHound/blob/master/docs/quick_start.md

Any help will be appreciated.

like image 257
vkm Avatar asked Sep 19 '19 14:09

vkm


1 Answers

IMHO, the wisest choice would be to enable BlockHound while the code is being exercised by JUnit tests.

To do so you simply need to import the https://mvnrepository.com/artifact/io.projectreactor.tools/blockhound-junit-platform dependency with test scope, which automatically initializes BlockHound when you launch your JUnit tests suite:

<dependency>
  <groupId>io.projectreactor.tools</groupId>
  <artifactId>blockhound-junit-platform</artifactId>
  <version>1.0.0.RC1</version>
  <scope>test</scope>
</dependency>


Alternatively, if you intend to use BlockHound at all times - and not only during tests - you should instead import the following dependency:

<dependency>
  <groupId>io.projectreactor.tools</groupId>
  <artifactId>blockhound</artifactId>
  <version>1.0.0.RC1</version>
</dependency>

And call BlockHound.install() in your main method, just before bootstrapping your Spring Boot application:

@SpringBootApplication
public class BlockhoundDemoApplication {

    public static void main(String[] args) {
        BlockHound.install();

        SpringApplication.run(BlockhoundDemoApplication.class, args);
    }

}

For further reference you can refer to:

  • my article @ https://medium.com/@domenicosibilio/blockhound-detect-blocking-calls-in-reactive-code-before-its-too-late-6472f8ad50c1 where I explain how to integrate and customize BlockHound for JUnit testing in a Spring Boot 2.2 application;
  • my demo project over at GitHub that integrates and customizes BlockHound for JUnit testing;
  • the BlockHound docs (see the supported testing frameworks section);
  • the BlockHound Gitter channel, where you can ask questions about BlockHound.
like image 182
Domenico Sibilio Avatar answered Oct 13 '22 23:10

Domenico Sibilio