Search in sources :

Example 11 with ExecutionResult

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

the class HystrixThreadEventStreamTest method testSemaphoreIsolatedSuccess.

@Test
public void testSemaphoreIsolatedSuccess() 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.SUCCESS);
    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 12 with ExecutionResult

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

the class HystrixThreadEventStreamTest method testSemaphoreRejectedCommand.

@Test
public void testSemaphoreRejectedCommand() 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.SEMAPHORE_REJECTED);
    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 13 with ExecutionResult

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

the class HystrixThreadEventStreamTest method testShortCircuit.

@Test
public void testShortCircuit() 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.SHORT_CIRCUITED);
    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 14 with ExecutionResult

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

the class HystrixThreadEventStreamTest method testThreadIsolatedFailure.

@Test
public void testThreadIsolatedFailure() 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).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 15 with ExecutionResult

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

the class HystrixThreadEventStreamTest method testSemaphoreIsolatedBadRequest.

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

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