Search in sources :

Example 1 with ExecutionResult

use of com.netflix.hystrix.ExecutionResult in project Hystrix by Netflix.

the class HystrixThreadEventStreamTest method testSemaphoreIsolatedFailure.

@Test
public void testSemaphoreIsolatedFailure() throws Exception {
    CountDownLatch commandLatch = new CountDownLatch(1);
    CountDownLatch threadPoolLatch = new CountDownLatch(1);
    Subscriber<HystrixCommandCompletion> commandSubscriber = getLatchedSubscriber(commandLatch);
    readCommandStream.observe().take(1).subscribe(commandSubscriber);
    Subscriber<HystrixCommandCompletion> threadPoolSubscriber = getLatchedSubscriber(threadPoolLatch);
    readThreadPoolStream.observe().take(1).subscribe(threadPoolSubscriber);
    ExecutionResult result = ExecutionResult.from(HystrixEventType.FAILURE);
    writeToStream.executionDone(result, commandKey, threadPoolKey);
    assertTrue(commandLatch.await(1000, TimeUnit.MILLISECONDS));
    assertFalse(threadPoolLatch.await(1000, TimeUnit.MILLISECONDS));
}
Also used : ExecutionResult(com.netflix.hystrix.ExecutionResult) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with ExecutionResult

use of com.netflix.hystrix.ExecutionResult in project Hystrix by Netflix.

the class HystrixThreadEventStreamTest method testThreadIsolatedBadRequest.

@Test
public void testThreadIsolatedBadRequest() throws Exception {
    CountDownLatch commandLatch = new CountDownLatch(1);
    CountDownLatch threadPoolLatch = new CountDownLatch(1);
    Subscriber<HystrixCommandCompletion> commandSubscriber = getLatchedSubscriber(commandLatch);
    readCommandStream.observe().take(1).subscribe(commandSubscriber);
    Subscriber<HystrixCommandCompletion> threadPoolSubscriber = getLatchedSubscriber(threadPoolLatch);
    readThreadPoolStream.observe().take(1).subscribe(threadPoolSubscriber);
    ExecutionResult result = ExecutionResult.from(HystrixEventType.BAD_REQUEST).setExecutedInThread();
    writeToStream.executionDone(result, commandKey, threadPoolKey);
    assertTrue(commandLatch.await(1000, TimeUnit.MILLISECONDS));
    assertTrue(threadPoolLatch.await(1000, TimeUnit.MILLISECONDS));
}
Also used : ExecutionResult(com.netflix.hystrix.ExecutionResult) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with ExecutionResult

use of com.netflix.hystrix.ExecutionResult in project Hystrix by Netflix.

the class HystrixThreadEventStreamTest method testThreadIsolatedTimeout.

@Test
public void testThreadIsolatedTimeout() throws Exception {
    CountDownLatch commandLatch = new CountDownLatch(1);
    CountDownLatch threadPoolLatch = new CountDownLatch(1);
    Subscriber<HystrixCommandCompletion> commandSubscriber = getLatchedSubscriber(commandLatch);
    readCommandStream.observe().take(1).subscribe(commandSubscriber);
    Subscriber<HystrixCommandCompletion> threadPoolSubscriber = getLatchedSubscriber(threadPoolLatch);
    readThreadPoolStream.observe().take(1).subscribe(threadPoolSubscriber);
    ExecutionResult result = ExecutionResult.from(HystrixEventType.TIMEOUT).setExecutedInThread();
    writeToStream.executionDone(result, commandKey, threadPoolKey);
    assertTrue(commandLatch.await(1000, TimeUnit.MILLISECONDS));
    assertTrue(threadPoolLatch.await(1000, TimeUnit.MILLISECONDS));
}
Also used : ExecutionResult(com.netflix.hystrix.ExecutionResult) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with ExecutionResult

use of com.netflix.hystrix.ExecutionResult in project Hystrix by Netflix.

the class HystrixThreadEventStreamTest method testThreadRejectedCommand.

@Test
public void testThreadRejectedCommand() throws Exception {
    CountDownLatch commandLatch = new CountDownLatch(1);
    CountDownLatch threadPoolLatch = new CountDownLatch(1);
    Subscriber<HystrixCommandCompletion> commandSubscriber = getLatchedSubscriber(commandLatch);
    readCommandStream.observe().take(1).subscribe(commandSubscriber);
    Subscriber<HystrixCommandCompletion> threadPoolSubscriber = getLatchedSubscriber(threadPoolLatch);
    readThreadPoolStream.observe().take(1).subscribe(threadPoolSubscriber);
    ExecutionResult result = ExecutionResult.from(HystrixEventType.THREAD_POOL_REJECTED);
    writeToStream.executionDone(result, commandKey, threadPoolKey);
    assertTrue(commandLatch.await(1000, TimeUnit.MILLISECONDS));
    assertTrue(threadPoolLatch.await(1000, TimeUnit.MILLISECONDS));
}
Also used : ExecutionResult(com.netflix.hystrix.ExecutionResult) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with ExecutionResult

use of com.netflix.hystrix.ExecutionResult in project Hystrix by Netflix.

the class HystrixThreadEventStreamTest method testThreadIsolatedResponseFromCache.

@Test
public void testThreadIsolatedResponseFromCache() throws Exception {
    CountDownLatch commandLatch = new CountDownLatch(1);
    CountDownLatch threadPoolLatch = new CountDownLatch(1);
    Subscriber<List<HystrixCommandCompletion>> commandListSubscriber = getLatchedSubscriber(commandLatch);
    readCommandStream.observe().buffer(500, TimeUnit.MILLISECONDS).take(1).doOnNext(new Action1<List<HystrixCommandCompletion>>() {

        @Override
        public void call(List<HystrixCommandCompletion> hystrixCommandCompletions) {
            System.out.println("LIST : " + hystrixCommandCompletions);
            assertEquals(3, hystrixCommandCompletions.size());
        }
    }).subscribe(commandListSubscriber);
    Subscriber<HystrixCommandCompletion> threadPoolSubscriber = getLatchedSubscriber(threadPoolLatch);
    readThreadPoolStream.observe().take(1).subscribe(threadPoolSubscriber);
    ExecutionResult result = ExecutionResult.from(HystrixEventType.SUCCESS).setExecutedInThread();
    ExecutionResult cache1 = ExecutionResult.from(HystrixEventType.RESPONSE_FROM_CACHE);
    ExecutionResult cache2 = ExecutionResult.from(HystrixEventType.RESPONSE_FROM_CACHE);
    writeToStream.executionDone(result, commandKey, threadPoolKey);
    writeToStream.executionDone(cache1, commandKey, threadPoolKey);
    writeToStream.executionDone(cache2, commandKey, threadPoolKey);
    assertTrue(commandLatch.await(1000, TimeUnit.MILLISECONDS));
    assertTrue(threadPoolLatch.await(1000, TimeUnit.MILLISECONDS));
}
Also used : Action1(rx.functions.Action1) List(java.util.List) ExecutionResult(com.netflix.hystrix.ExecutionResult) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ExecutionResult (com.netflix.hystrix.ExecutionResult)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 Test (org.junit.Test)15 List (java.util.List)2 Action1 (rx.functions.Action1)2