Java Code Examples for reactor.core.scheduler.Schedulers#removeExecutorServiceDecorator()
The following examples show how to use
reactor.core.scheduler.Schedulers#removeExecutorServiceDecorator() .
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: TraceReactorAutoConfiguration.java From spring-cloud-sleuth with Apache License 2.0 | 6 votes |
@PreDestroy public void cleanupHooks() { if (log.isTraceEnabled()) { log.trace("Cleaning up hooks"); } SleuthReactorProperties reactorProperties = this.springContext .getBean(SleuthReactorProperties.class); if (reactorProperties.isDecorateOnEach()) { if (log.isTraceEnabled()) { log.trace("Resetting onEach operator instrumentation"); } Hooks.resetOnEachOperator(SLEUTH_TRACE_REACTOR_KEY); } else { if (log.isTraceEnabled()) { log.trace("Resetting onLast operator instrumentation"); } Hooks.resetOnLastOperator(SLEUTH_TRACE_REACTOR_KEY); } Schedulers .removeExecutorServiceDecorator(SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY); }
Example 2
Source File: TraceReactorAutoConfigurationAccessorConfiguration.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
public static void close() { if (log.isTraceEnabled()) { log.trace("Cleaning up hooks"); } Hooks.resetOnEachOperator(SLEUTH_TRACE_REACTOR_KEY); Hooks.resetOnLastOperator(SLEUTH_TRACE_REACTOR_KEY); Schedulers.removeExecutorServiceDecorator(SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY); }
Example 3
Source File: ScopePassingSpanSubscriberTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Before public void resetHooks() { // There's an assumption some other test is leaking hooks, so we clear them all to // prevent should_not_scope_scalar_subscribe from being interfered with. Hooks.resetOnEachOperator(SLEUTH_TRACE_REACTOR_KEY); Hooks.resetOnLastOperator(SLEUTH_TRACE_REACTOR_KEY); Schedulers.removeExecutorServiceDecorator(SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY); }
Example 4
Source File: TraceReactorAutoConfigurationAccessorConfiguration.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
public static void close() { if (log.isTraceEnabled()) { log.trace("Cleaning up hooks"); } Hooks.resetOnEachOperator(SLEUTH_TRACE_REACTOR_KEY); Hooks.resetOnLastOperator(SLEUTH_TRACE_REACTOR_KEY); Schedulers.removeExecutorServiceDecorator(SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY); }
Example 5
Source File: ReactorTracingAutoConfiguration.java From java-spring-cloud with Apache License 2.0 | 4 votes |
@PreDestroy public void cleanupHooks() { Hooks.resetOnEachOperator(HOOK_KEY); Schedulers.removeExecutorServiceDecorator(EXECUTOR_SERVICE_DECORATOR_KEY); }
Example 6
Source File: WingtipsSpringBoot2WebfluxConfigurationTest.java From wingtips with Apache License 2.0 | 4 votes |
@Before public void beforeMethod() { Schedulers.removeExecutorServiceDecorator(WingtipsReactorInitializer.WINGTIPS_SCHEDULER_KEY); resetTracing(); }
Example 7
Source File: WingtipsSpringBoot2WebfluxConfigurationTest.java From wingtips with Apache License 2.0 | 4 votes |
@After public void afterMethod() { Schedulers.removeExecutorServiceDecorator(WingtipsReactorInitializer.WINGTIPS_SCHEDULER_KEY); resetTracing(); }
Example 8
Source File: WingtipsSpringBoot2WebfluxConfigurationTest.java From wingtips with Apache License 2.0 | 4 votes |
@DataProvider(value = { "MANUAL_IMPORT_ONLY", "COMPONENT_SCAN_ONLY", "BOTH_MANUAL_AND_COMPONENT_SCAN" }) @Test public void component_test(ComponentTestSetup componentTestSetup) { // given int serverPort = findFreePort(); Class<?> mainClass = componentTestSetup.mainClass; ConfigurableApplicationContext serverAppContext = SpringApplication.run(mainClass, "--server.port=" + serverPort); try { // when WingtipsSpringBoot2WebfluxConfiguration config = serverAppContext.getBean(WingtipsSpringBoot2WebfluxConfiguration.class); WingtipsSpringBoot2WebfluxProperties props = serverAppContext.getBean(WingtipsSpringBoot2WebfluxProperties.class); String[] someComponentScannedClassBeanNames = serverAppContext.getBeanNamesForType(SomeComponentScannedClass.class); // then // Sanity check that we component scanned (or not) as appropriate. if (componentTestSetup.expectComponentScannedObjects) { assertThat(someComponentScannedClassBeanNames).isNotEmpty(); } else { assertThat(someComponentScannedClassBeanNames).isEmpty(); } // WingtipsSpringBoot2WebfluxConfiguration and WingtipsSpringBoot2WebfluxProperties should be available as // beans, and the config should use the same props we received. assertThat(config).isNotNull(); assertThat(props).isNotNull(); assertThat(config.wingtipsProperties).isSameAs(props); // The config should not have any custom WingtipsSpringWebfluxWebFilter. Spring will populate // the config.customSpringWebfluxWebFilter field with whatever wingtipsSpringWebfluxWebFilter() // produces - so they should be the same. Map<String, WingtipsSpringWebfluxWebFilter> filtersFromSpring = serverAppContext.getBeansOfType(WingtipsSpringWebfluxWebFilter.class); assertThat(filtersFromSpring).isEqualTo( Collections.singletonMap("wingtipsSpringWebfluxWebFilter", config.customSpringWebfluxWebFilter) ); } finally { Schedulers.removeExecutorServiceDecorator(WingtipsReactorInitializer.WINGTIPS_SCHEDULER_KEY); SpringApplication.exit(serverAppContext); } }
Example 9
Source File: WingtipsSpringBoot2WebfluxConfigurationTest.java From wingtips with Apache License 2.0 | 4 votes |
@DataProvider(value = { "MANUAL_IMPORT_ONLY | true", "COMPONENT_SCAN_ONLY | true", "COMPONENT_SCAN_WITHOUT_REACTOR_SUPPORT | false", "BOTH_MANUAL_AND_COMPONENT_SCAN | true" }, splitBy = "\\|") @Test public void project_reactor_wingtips_integration_should_work_as_expected_when_using_subscribeOn( ComponentTestSetup componentTestSetup, boolean expectTracingToPropagate ) { // given int serverPort = findFreePort(); Class<?> mainClass = componentTestSetup.mainClass; ConfigurableApplicationContext serverAppContext = SpringApplication.run( mainClass, "--server.port=" + serverPort ); try { // given // Setup the mono before we even start the trace. Mono<Pair<Long, Span>> asyncThreadAndTraceId = Mono.just("test") // Return the thread ID and current span. .map(s -> Pair.of(Thread.currentThread().getId(), Tracer.getInstance().getCurrentSpan())) // Set up an async boundary using subscribeOn(...). // WARNING: This MUST be a new*() (e.g. newElastic()), rather than the built-in defaults // like Schedulers.elastic(). Otherwise it's a race condition, as the schedulers are cached // after they are created and used, so setting the Wingtips+Reactor scheduler hook after // a default scheduler has been used won't work. Think one test running without the hook, and // then a different test trying to run with the hook. The second test won't work. // By using a new scheduler, we guarantee that it will receive whatever hook we setup as part // of *this* test. .subscribeOn(Schedulers.newElastic("someNewElasticScheduler")); // Start the trace and track the thread ID we're on. final Span rootSpan = Tracer.getInstance().startRequestWithRootSpan("root"); final long mainThreadId = Thread.currentThread().getId(); // when // This block() is where the subscription occurs, and therefore where the // ProjectReactor+Wingtips magic occurs. It should take the tracing state on the current thread here // when block() is called, and propagate it into the Mono execution. Pair<Long, Span> result = asyncThreadAndTraceId.block(); // then // The thread in the Mono.map(...) should always be different than our main thread // thanks to the subscribeOn(...). assertThat(result.getLeft()).isNotEqualTo(mainThreadId); // If expectTracingToPropagate is true, then we expect the span in the Mono.map(...) to match the root span. // Otherwise, the current span when Mono.map(...) executed should be null. if (expectTracingToPropagate) { assertThat(result.getRight()).isEqualTo(rootSpan); } else { assertThat(result.getRight()).isNull(); } Tracer.getInstance().completeRequestSpan(); } finally { Schedulers.removeExecutorServiceDecorator(WingtipsReactorInitializer.WINGTIPS_SCHEDULER_KEY); SpringApplication.exit(serverAppContext); } }
Example 10
Source File: WingtipsSpringBoot2WebfluxConfigurationTest.java From wingtips with Apache License 2.0 | 4 votes |
@DataProvider(value = { "MANUAL_IMPORT_ONLY | true", "COMPONENT_SCAN_ONLY | true", "COMPONENT_SCAN_WITHOUT_REACTOR_SUPPORT | false", "BOTH_MANUAL_AND_COMPONENT_SCAN | true" }, splitBy = "\\|") @Test public void project_reactor_wingtips_integration_should_work_as_expected_when_using_publishOn( ComponentTestSetup componentTestSetup, boolean expectTracingToPropagate ) { // given int serverPort = findFreePort(); Class<?> mainClass = componentTestSetup.mainClass; ConfigurableApplicationContext serverAppContext = SpringApplication.run( mainClass, "--server.port=" + serverPort ); try { // given // Setup the mono before we even start the trace. Mono<Pair<Long, Span>> asyncThreadAndTraceId = Mono.just("test") // Set up an async boundary using publishOn(...). // WARNING: This MUST be a new*() (e.g. newElastic()), rather than the built-in defaults // like Schedulers.elastic(). Otherwise it's a race condition, as the schedulers are cached // after they are created and used, so setting the Wingtips+Reactor scheduler hook after // a default scheduler has been used won't work. Think one test running without the hook, and // then a different test trying to run with the hook. The second test won't work. // By using a new scheduler, we guarantee that it will receive whatever hook we setup as part // of *this* test. .publishOn(Schedulers.newElastic("someNewElasticScheduler")) // Return the thread ID and current span. .map(s -> Pair.of(Thread.currentThread().getId(), Tracer.getInstance().getCurrentSpan())); // Start the trace and track the thread ID we're on. final Span rootSpan = Tracer.getInstance().startRequestWithRootSpan("root"); final long mainThreadId = Thread.currentThread().getId(); // when // This block() is where the subscription occurs, and therefore where the // ProjectReactor+Wingtips magic occurs. It should take the tracing state on the current thread here // when block() is called, and propagate it into the Mono execution. Pair<Long, Span> result = asyncThreadAndTraceId.block(); // then // The thread in the Mono.map(...) should always be different than our main thread // thanks to the publishOn(...). assertThat(result.getLeft()).isNotEqualTo(mainThreadId); // If expectTracingToPropagate is true, then we expect the span in the Mono.map(...) to match the root span. // Otherwise, the current span when Mono.map(...) executed should be null. if (expectTracingToPropagate) { assertThat(result.getRight()).isEqualTo(rootSpan); } else { assertThat(result.getRight()).isNull(); } Tracer.getInstance().completeRequestSpan(); } finally { Schedulers.removeExecutorServiceDecorator(WingtipsReactorInitializer.WINGTIPS_SCHEDULER_KEY); SpringApplication.exit(serverAppContext); } }