reactor.blockhound.BlockHound Java Examples

The following examples show how to use reactor.blockhound.BlockHound. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardOutputIntegration.java    From BlockHound with Apache License 2.0 6 votes vote down vote up
@Override
public void applyTo(BlockHound.Builder builder) {
	System.setOut(new PrintStreamDelegate(System.out));
	System.setErr(new PrintStreamDelegate(System.err));

	for (String method : new String[]{
			"flush",
			"close",
			"checkError",
			"write",
			"print",
			"println",
			"printf",
			"format",
			"append",
			"write"
	}) {
		builder.allowBlockingCallsInside(PrintStreamDelegate.class.getName(), method);
	}
}
 
Example #2
Source File: LoggingIntegration.java    From BlockHound with Apache License 2.0 5 votes vote down vote up
@Override
public void applyTo(BlockHound.Builder builder) {
    try {
        Class.forName("org.gradle.internal.io.LineBufferingOutputStream");
        builder.allowBlockingCallsInside("org.gradle.internal.io.LineBufferingOutputStream", "write");
    } catch (ClassNotFoundException __) {
    }

    try {
        Class.forName("ch.qos.logback.classic.Logger");
        builder.allowBlockingCallsInside("ch.qos.logback.classic.Logger", "callAppenders");
    } catch (ClassNotFoundException e) {
    }
}
 
Example #3
Source File: RxJava2Integration.java    From BlockHound with Apache License 2.0 5 votes vote down vote up
@Override
public void applyTo(BlockHound.Builder builder) {
    try {
        Class.forName("io.reactivex.Flowable");
    }
    catch (ClassNotFoundException ignored) {
        return;
    }

    builder.nonBlockingThreadPredicate(current -> current.or(NonBlockingThread.class::isInstance));
}
 
Example #4
Source File: ReactorBlockHoundIntegration.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void applyTo(BlockHound.Builder builder) {
    builder.nonBlockingThreadPredicate(current -> current.or(NonBlocking.class::isInstance));

    builder.allowBlockingCallsInside(ScheduledThreadPoolExecutor.class.getName() + "$DelayedWorkQueue", "offer");
    builder.allowBlockingCallsInside(ScheduledThreadPoolExecutor.class.getName() + "$DelayedWorkQueue", "take");

    // Calls ScheduledFutureTask#cancel that may short park in DelayedWorkQueue#remove for getting a lock
    builder.allowBlockingCallsInside(SchedulerTask.class.getName(), "dispose");

    builder.allowBlockingCallsInside(ThreadPoolExecutor.class.getName(), "processWorkerExit");
}
 
Example #5
Source File: CustomBlockHoundIntegration.java    From spring-cloud-gateway with Apache License 2.0 4 votes vote down vote up
@Override
public void applyTo(BlockHound.Builder builder) {
	// builder.blockingMethodCallback(it -> {
	// Error error = new Error(it.toString());
	// error.printStackTrace();
	// throw error;
	// });

	// Uses Unsafe#park
	builder.allowBlockingCallsInside("reactor.core.scheduler.SchedulerTask",
			"dispose");

	// Uses
	// ch.qos.logback.classic.spi.PackagingDataCalculator#getImplementationVersion
	builder.allowBlockingCallsInside(
			"org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler",
			"logError");
	builder.allowBlockingCallsInside("reactor.util.Loggers$Slf4JLogger", "debug");
	builder.allowBlockingCallsInside("reactor.util.Loggers$Slf4JLogger", "info");
	builder.allowBlockingCallsInside("reactor.util.Loggers$Slf4JLogger", "error");

	// Uses org.springframework.util.JdkIdGenerator#generateId
	// Uses UUID#randomUUID
	builder.allowBlockingCallsInside(
			"org.springframework.web.server.session.InMemoryWebSessionStore",
			"lambda$createWebSession$0");

	// Uses java.util.Random#nextInt
	builder.allowBlockingCallsInside("org.springframework.util.MimeTypeUtils",
			"generateMultipartBoundary");

	// SPRING DATA REDIS RELATED

	// Uses Unsafe#park
	builder.allowBlockingCallsInside(
			"org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory",
			"getReactiveConnection");

	// NETTY RELATED

	// Uses Thread#sleep
	builder.allowBlockingCallsInside("io.netty.channel.nio.NioEventLoop",
			"handleLoopException");
	builder.allowBlockingCallsInside(
			"io.netty.util.concurrent.SingleThreadEventExecutor", "confirmShutdown");

	// Uses Unsafe#park
	builder.allowBlockingCallsInside("io.netty.util.concurrent.GlobalEventExecutor",
			"execute");
	builder.allowBlockingCallsInside(
			"io.netty.util.concurrent.SingleThreadEventExecutor$6", "run");
	// builder.allowBlockingCallsInside("io.netty.util.concurrent.GlobalEventExecutor",
	// "takeTask");
	// builder.allowBlockingCallsInside("io.netty.util.concurrent.GlobalEventExecutor",
	// "addTask");
	builder.allowBlockingCallsInside(
			"io.netty.util.concurrent.FastThreadLocalRunnable", "run");

	// SECURITY RELATED

	// For HTTPS traffic
	builder.allowBlockingCallsInside("io.netty.handler.ssl.SslHandler",
			"channelActive");
	builder.allowBlockingCallsInside("io.netty.handler.ssl.SslHandler",
			"channelInactive");
	builder.allowBlockingCallsInside("io.netty.handler.ssl.SslHandler", "unwrap");
	builder.allowBlockingCallsInside("io.netty.handler.ssl.SslContext",
			"newClientContextInternal");

	// Uses org.springframework.security.crypto.bcrypt.BCrypt#gensalt
	// Uses java.security.SecureRandom#nextBytes
	builder.allowBlockingCallsInside(
			"org.springframework.security.authentication.AbstractUserDetailsReactiveAuthenticationManager",
			"lambda$authenticate$4");
}
 
Example #6
Source File: BoundedElasticSchedulerBlockhoundTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() {
	BlockHound.install();
}
 
Example #7
Source File: RetryOperatorTest.java    From resilience4j with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() {
    BlockHound.install(new ReactorIntegration());
}
 
Example #8
Source File: BlockHoundIntegration.java    From BlockHound with Apache License 2.0 2 votes vote down vote up
/**
 * Lets an integration apply the customizations (see {@link BlockHound.Builder})
 * before BlockHound is installed.
 *
 * @param builder an instance of {@link BlockHound.Builder} that is being installed
 */
void applyTo(BlockHound.Builder builder);