Search in sources :

Example 6 with ExecutionResult

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

the class HystrixThreadEventStreamTest method testThreadIsolatedSuccess.

@Test
public void testThreadIsolatedSuccess() throws InterruptedException {
    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.SUCCESS).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 7 with ExecutionResult

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

the class HystrixThreadEventStreamTest method testSemaphoreIsolatedTimeout.

@Test
public void testSemaphoreIsolatedTimeout() 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);
    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 8 with ExecutionResult

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

the class HystrixThreadEventStreamTest method testSemaphoreIsolatedResponseFromCache.

@Test
public void testSemaphoreIsolatedResponseFromCache() 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);
    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));
    assertFalse(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)

Example 9 with ExecutionResult

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

the class HystrixCommandCompletionStreamTest method testSingleWriteSingleSubscriber.

@Test
public void testSingleWriteSingleSubscriber() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    Subscriber<HystrixCommandCompletion> subscriber = getLatchedSubscriber(latch);
    commandStream.observe().take(1).subscribe(subscriber);
    ExecutionResult result = ExecutionResult.from(HystrixEventType.SUCCESS).setExecutedInThread();
    HystrixCommandCompletion event = HystrixCommandCompletion.from(result, commandKey, threadPoolKey);
    commandStream.write(event);
    assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
}
Also used : ExecutionResult(com.netflix.hystrix.ExecutionResult) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 10 with ExecutionResult

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

the class HystrixCommandCompletionStreamTest method testSingleWriteMultipleSubscribers.

@Test
public void testSingleWriteMultipleSubscribers() throws InterruptedException {
    CountDownLatch latch1 = new CountDownLatch(1);
    Subscriber<HystrixCommandCompletion> subscriber1 = getLatchedSubscriber(latch1);
    CountDownLatch latch2 = new CountDownLatch(1);
    Subscriber<HystrixCommandCompletion> subscriber2 = getLatchedSubscriber(latch2);
    commandStream.observe().take(1).subscribe(subscriber1);
    commandStream.observe().take(1).subscribe(subscriber2);
    ExecutionResult result = ExecutionResult.from(HystrixEventType.SUCCESS).setExecutedInThread();
    HystrixCommandCompletion event = HystrixCommandCompletion.from(result, commandKey, threadPoolKey);
    commandStream.write(event);
    assertTrue(latch1.await(1000, TimeUnit.MILLISECONDS));
    assertTrue(latch2.await(10, TimeUnit.MILLISECONDS));
}
Also used : 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