/** * Synchronous Observable and semaphore isolation. Only [Main] thread is involved in this. */ @Test public void testTimeoutRequestContextWithSemaphoreIsolatedSynchronousObservable() { RequestContextTestResults results = testRequestContextOnTimeout(ExecutionIsolationStrategy.SEMAPHORE, Schedulers.immediate()); assertTrue(results.isContextInitialized.get()); assertTrue(results.originThread.get().equals(Thread.currentThread())); // all synchronous assertTrue(results.isContextInitializedObserveOn.get()); assertTrue(results.observeOnThread.get().getName().startsWith("HystrixTimer")); // timeout schedules on HystrixTimer since the original thread was timed out // semaphore isolated assertFalse(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
/** * Synchronous Observable and thread isolation. Work done on [hystrix-OWNER_ONE] thread and then observed on [HystrixTimer] */ @Test public void testTimeoutWithFallbackRequestContextWithThreadIsolatedSynchronousObservable() { RequestContextTestResults results = testRequestContextOnTimeoutWithFallback(ExecutionIsolationStrategy.THREAD, Schedulers.immediate()); assertTrue(results.isContextInitialized.get()); assertTrue(results.originThread.get().getName().startsWith("HystrixTimer")); // timeout uses HystrixTimer thread for fallback assertTrue(results.isContextInitializedObserveOn.get()); assertTrue(results.observeOnThread.get().getName().startsWith("HystrixTimer")); // fallback uses the timeout thread // thread isolated assertTrue(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
/** * Synchronous Observable and semaphore isolation. */ @Test public void testTimeoutWithFallbackRequestContextWithSemaphoreIsolatedSynchronousObservable() { RequestContextTestResults results = testRequestContextOnTimeoutWithFallback(ExecutionIsolationStrategy.SEMAPHORE, Schedulers.immediate()); assertTrue(results.isContextInitialized.get()); assertTrue(results.originThread.get().getName().startsWith("HystrixTimer")); // timeout uses HystrixTimer thread //(this use case is a little odd as it should generally not be the case that we are "timing out" a synchronous observable on semaphore isolation) assertTrue(results.isContextInitializedObserveOn.get()); assertTrue(results.observeOnThread.get().getName().startsWith("HystrixTimer")); // timeout uses HystrixTimer thread // semaphore isolated assertFalse(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
/** * Reset logic that doesn't have time/TimeUnit arguments. */ private static void _reset() { // clear metrics HystrixCommandMetrics.reset(); HystrixThreadPoolMetrics.reset(); HystrixCollapserMetrics.reset(); // clear collapsers HystrixCollapser.reset(); // clear circuit breakers HystrixCircuitBreaker.Factory.reset(); HystrixPlugins.reset(); HystrixPropertiesFactory.reset(); currentCommand.set(new ConcurrentStack<HystrixCommandKey>()); }
/** * Async Observable and thread isolation. User provided thread [RxNetThread] executes Observable and then [RxComputation] observes the onNext calls. * * NOTE: RequestContext will NOT exist on that thread. * * An async Observable running on its own thread will not have access to the request context unless the user manages the context. */ @Test public void testTimeoutWithFallbackRequestContextWithThreadIsolatedAsynchronousObservable() { RequestContextTestResults results = testRequestContextOnTimeoutWithFallback(ExecutionIsolationStrategy.THREAD, Schedulers.newThread()); assertFalse(results.isContextInitialized.get()); // it won't have request context as it's on a user provided thread/scheduler assertTrue(results.originThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler assertTrue(results.isContextInitializedObserveOn.get()); // the timeout captures the context so it exists assertTrue(results.observeOnThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler // thread isolated assertTrue(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
/** * Async Observable and semaphore isolation. User provided thread [RxNewThread] does everything. * * NOTE: RequestContext will NOT exist on that thread. * * An async Observable running on its own thread will not have access to the request context unless the user manages the context. */ @Test public void testTimeoutWithFallbackRequestContextWithSemaphoreIsolatedAsynchronousObservable() { RequestContextTestResults results = testRequestContextOnTimeoutWithFallback(ExecutionIsolationStrategy.SEMAPHORE, Schedulers.newThread()); assertFalse(results.isContextInitialized.get()); // it won't have request context as it's on a user provided thread/scheduler assertTrue(results.originThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler assertTrue(results.isContextInitializedObserveOn.get()); // the timeout captures the context so it exists assertTrue(results.observeOnThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler // semaphore isolated assertFalse(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
/** * Async Observable and semaphore isolation. User provided thread [RxNewThread] does everything. * * NOTE: RequestContext will NOT exist on that thread. * * An async Observable running on its own thread will not have access to the request context unless the user manages the context. */ @Test public void testTimeoutRequestContextWithSemaphoreIsolatedAsynchronousObservable() { RequestContextTestResults results = testRequestContextOnTimeout(ExecutionIsolationStrategy.SEMAPHORE, Schedulers.newThread()); assertFalse(results.isContextInitialized.get()); // it won't have request context as it's on a user provided thread/scheduler assertTrue(results.originThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler assertTrue(results.isContextInitializedObserveOn.get()); // the timeout captures the context so it exists assertTrue(results.observeOnThread.get().getName().startsWith("HystrixTimer")); // timeout schedules on HystrixTimer since the original thread was timed out // semaphore isolated assertFalse(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
/** * Async Observable and semaphore isolation WITH functioning RequestContext * * Use HystrixContextScheduler to make the user provided scheduler capture context. */ @Test public void testTimeoutWithFallbackRequestContextWithSemaphoreIsolatedAsynchronousObservableAndCapturedContextScheduler() { RequestContextTestResults results = testRequestContextOnTimeoutWithFallback(ExecutionIsolationStrategy.SEMAPHORE, new HystrixContextScheduler(Schedulers.newThread())); assertTrue(results.isContextInitialized.get()); // the user scheduler captures context assertTrue(results.originThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler assertTrue(results.isContextInitializedObserveOn.get()); // the user scheduler captures context assertTrue(results.observeOnThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler // semaphore isolated assertFalse(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
/** * Reset logic that doesn't have time/TimeUnit arguments. */ private static void _reset() { // clear metrics HystrixCommandMetrics.reset(); HystrixThreadPoolMetrics.reset(); HystrixCollapserMetrics.reset(); // clear collapsers HystrixCollapser.reset(); // clear circuit breakers HystrixCircuitBreaker.Factory.reset(); HystrixPlugins.reset(); HystrixPropertiesFactory.reset(); currentCommand.set(new ConcurrentStack<HystrixCommandKey>()); }
/** * Async Observable and semaphore isolation WITH functioning RequestContext * * Use HystrixContextScheduler to make the user provided scheduler capture context. */ @Test public void testTimeoutRequestContextWithSemaphoreIsolatedAsynchronousObservableAndCapturedContextScheduler() { RequestContextTestResults results = testRequestContextOnTimeout(ExecutionIsolationStrategy.SEMAPHORE, new HystrixContextScheduler(Schedulers.newThread())); assertTrue(results.isContextInitialized.get()); // the user scheduler captures context assertTrue(results.originThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler assertTrue(results.isContextInitializedObserveOn.get()); // the user scheduler captures context assertTrue(results.observeOnThread.get().getName().startsWith("HystrixTimer")); // timeout schedules on HystrixTimer since the original thread was timed out // semaphore isolated assertFalse(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
@Before public void init() { for (HystrixCommandMetrics metricsInstance: HystrixCommandMetrics.getInstances()) { metricsInstance.resetStream(); } HystrixCommandMetrics.reset(); HystrixCircuitBreaker.Factory.reset(); Hystrix.reset(); }