Search in sources :

Example 11 with HystrixContextScheduler

use of com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler in project Hystrix by Netflix.

the class HystrixObservableCommandTest method testTimeoutRequestContextWithSemaphoreIsolatedAsynchronousObservableAndCapturedContextScheduler.

/**
     * 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()));
    // the user scheduler captures context
    assertTrue(results.isContextInitialized.get());
    // the user provided thread/scheduler
    assertTrue(results.originThread.get().getName().startsWith("RxNewThread"));
    // the user scheduler captures context
    assertTrue(results.isContextInitializedObserveOn.get());
    // timeout schedules on HystrixTimer since the original thread was timed out
    assertTrue(results.observeOnThread.get().getName().startsWith("HystrixTimer"));
    // semaphore isolated
    assertFalse(results.command.isExecutedInThread());
    HystrixCircuitBreaker.Factory.reset();
}
Also used : HystrixContextScheduler(com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler) Test(org.junit.Test)

Example 12 with HystrixContextScheduler

use of com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler in project Hystrix by Netflix.

the class HystrixObservableCommandTest method testSuccessfulRequestContextWithThreadIsolatedAsynchronousObservableAndCapturedContextScheduler.

/**
     * Async Observable and semaphore isolation WITH functioning RequestContext
     *
     * Use HystrixContextScheduler to make the user provided scheduler capture context.
     */
@Test
public void testSuccessfulRequestContextWithThreadIsolatedAsynchronousObservableAndCapturedContextScheduler() {
    RequestContextTestResults results = testRequestContextOnSuccess(ExecutionIsolationStrategy.THREAD, new HystrixContextScheduler(Schedulers.newThread()));
    // the user scheduler captures context
    assertTrue(results.isContextInitialized.get());
    // the user provided thread/scheduler
    assertTrue(results.originThread.get().getName().startsWith("RxNewThread"));
    // the user scheduler captures context
    assertTrue(results.isContextInitializedObserveOn.get());
    assertTrue(results.observeOnThread.get().getName().startsWith("RxNewThread"));
    // thread isolated
    assertTrue(results.command.isExecutedInThread());
}
Also used : HystrixContextScheduler(com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler) Test(org.junit.Test)

Example 13 with HystrixContextScheduler

use of com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler in project Hystrix by Netflix.

the class HystrixObservableCommandTest method testShortCircuitedWithFallbackRequestContextWithThreadIsolatedAsynchronousObservableAndCapturedContextScheduler.

/**
     * Async Observable and semaphore isolation WITH functioning RequestContext
     *
     * Use HystrixContextScheduler to make the user provided scheduler capture context.
     */
@Test
public void testShortCircuitedWithFallbackRequestContextWithThreadIsolatedAsynchronousObservableAndCapturedContextScheduler() {
    RequestContextTestResults results = testRequestContextOnShortCircuitedWithFallback(ExecutionIsolationStrategy.THREAD, new HystrixContextScheduler(Schedulers.newThread()));
    // the user scheduler captures context
    assertTrue(results.isContextInitialized.get());
    // the user provided thread/scheduler
    assertTrue(results.originThread.get().getName().startsWith("RxNewThread"));
    // the user scheduler captures context
    assertTrue(results.isContextInitializedObserveOn.get());
    // the user provided thread/scheduler from getFallback
    assertTrue(results.observeOnThread.get().getName().startsWith("RxNewThread"));
    // thread isolated ... but rejected so not executed in a thread
    assertFalse(results.command.isExecutedInThread());
}
Also used : HystrixContextScheduler(com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler) Test(org.junit.Test)

Example 14 with HystrixContextScheduler

use of com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler in project Hystrix by Netflix.

the class HystrixObservableCommandTest method testGracefulFailureRequestContextWithSemaphoreIsolatedAsynchronousObservableAndCapturedContextScheduler.

/**
     * Async Observable and semaphore isolation WITH functioning RequestContext
     *
     * Use HystrixContextScheduler to make the user provided scheduler capture context.
     */
@Test
public void testGracefulFailureRequestContextWithSemaphoreIsolatedAsynchronousObservableAndCapturedContextScheduler() {
    RequestContextTestResults results = testRequestContextOnGracefulFailure(ExecutionIsolationStrategy.SEMAPHORE, new HystrixContextScheduler(Schedulers.newThread()));
    // the user scheduler captures context
    assertTrue(results.isContextInitialized.get());
    // the user provided thread/scheduler
    assertTrue(results.originThread.get().getName().startsWith("RxNewThread"));
    // the user scheduler captures context
    assertTrue(results.isContextInitializedObserveOn.get());
    // the user provided thread/scheduler
    assertTrue(results.observeOnThread.get().getName().startsWith("RxNewThread"));
    // semaphore isolated
    assertFalse(results.command.isExecutedInThread());
}
Also used : HystrixContextScheduler(com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler) Test(org.junit.Test)

Example 15 with HystrixContextScheduler

use of com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler in project Hystrix by Netflix.

the class HystrixObservableCommandTest method testBadFailureRequestContextWithSemaphoreIsolatedAsynchronousObservableAndCapturedContextScheduler.

/**
     * Async Observable and semaphore isolation WITH functioning RequestContext
     *
     * Use HystrixContextScheduler to make the user provided scheduler capture context.
     */
@Test
public void testBadFailureRequestContextWithSemaphoreIsolatedAsynchronousObservableAndCapturedContextScheduler() {
    RequestContextTestResults results = testRequestContextOnBadFailure(ExecutionIsolationStrategy.SEMAPHORE, new HystrixContextScheduler(Schedulers.newThread()));
    // the user scheduler captures context
    assertTrue(results.isContextInitialized.get());
    // the user provided thread/scheduler
    assertTrue(results.originThread.get().getName().startsWith("RxNewThread"));
    // the user scheduler captures context
    assertTrue(results.isContextInitializedObserveOn.get());
    // the user provided thread/scheduler
    assertTrue(results.observeOnThread.get().getName().startsWith("RxNewThread"));
    // semaphore isolated
    assertFalse(results.command.isExecutedInThread());
}
Also used : HystrixContextScheduler(com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler) Test(org.junit.Test)

Aggregations

HystrixContextScheduler (com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler)16 Test (org.junit.Test)15 TestCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreakerTest.TestCircuitBreaker)1 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Notification (rx.Notification)1 OnSubscribe (rx.Observable.OnSubscribe)1 Subscriber (rx.Subscriber)1 Action1 (rx.functions.Action1)1 Func0 (rx.functions.Func0)1 TestSubscriber (rx.observers.TestSubscriber)1