Search in sources :

Example 6 with HystrixCommandKey

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

the class CumulativeThreadPoolEventCounterStreamTest method testShortCircuited.

@Test
public void testShortCircuited() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("Cumulative-ThreadPool-G");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("Cumulative-ThreadPool-G");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("Cumulative-Counter-G");
    stream = CumulativeThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    //3 failures in a row will trip circuit.  let bucket roll once then submit 2 requests.
    //should see 3 FAILUREs and 2 SHORT_CIRCUITs and each should see a FALLBACK_SUCCESS
    CommandStreamTest.Command failure1 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20);
    CommandStreamTest.Command failure2 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20);
    CommandStreamTest.Command failure3 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20);
    CommandStreamTest.Command shortCircuit1 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS);
    CommandStreamTest.Command shortCircuit2 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS);
    failure1.observe();
    failure2.observe();
    failure3.observe();
    try {
        Thread.sleep(100);
    } catch (InterruptedException ie) {
        fail(ie.getMessage());
    }
    shortCircuit1.observe();
    shortCircuit2.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    assertTrue(shortCircuit1.isResponseShortCircuited());
    assertTrue(shortCircuit2.isResponseShortCircuited());
    //only the FAILUREs should show up in thread pool counters
    assertEquals(2, stream.getLatest().length);
    assertEquals(3, stream.getLatestCount(HystrixEventType.ThreadPool.EXECUTED));
    assertEquals(0, stream.getLatestCount(HystrixEventType.ThreadPool.REJECTED));
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) CountDownLatch(java.util.concurrent.CountDownLatch) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 7 with HystrixCommandKey

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

the class CumulativeThreadPoolEventCounterStreamTest method testRequestFromCache.

@Test
public void testRequestFromCache() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("Cumulative-ThreadPool-F");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("Cumulative-ThreadPool-F");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("Cumulative-Counter-F");
    stream = CumulativeThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    CommandStreamTest.Command cmd1 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS, 20);
    CommandStreamTest.Command cmd2 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.RESPONSE_FROM_CACHE);
    CommandStreamTest.Command cmd3 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.RESPONSE_FROM_CACHE);
    cmd1.observe();
    cmd2.observe();
    cmd3.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    //RESPONSE_FROM_CACHE should not show up at all in thread pool counters - just the success
    assertEquals(2, stream.getLatest().length);
    assertEquals(1, stream.getLatestCount(HystrixEventType.ThreadPool.EXECUTED));
    assertEquals(0, stream.getLatestCount(HystrixEventType.ThreadPool.REJECTED));
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) CountDownLatch(java.util.concurrent.CountDownLatch) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 8 with HystrixCommandKey

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

the class CumulativeThreadPoolEventCounterStreamTest method testFallbackRejection.

@Test
public void testFallbackRejection() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("Cumulative-ThreadPool-L");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("Cumulative-ThreadPool-L");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("Cumulative-Counter-L");
    stream = CumulativeThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    //fallback semaphore size is 5.  So let 5 commands saturate that semaphore, then
    //let 2 more commands go to fallback.  they should get rejected by the fallback-semaphore
    List<CommandStreamTest.Command> fallbackSaturators = new ArrayList<CommandStreamTest.Command>();
    for (int i = 0; i < 5; i++) {
        fallbackSaturators.add(CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20, HystrixEventType.FALLBACK_SUCCESS, 400));
    }
    CommandStreamTest.Command rejection1 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20, HystrixEventType.FALLBACK_SUCCESS, 0);
    CommandStreamTest.Command rejection2 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20, HystrixEventType.FALLBACK_SUCCESS, 0);
    for (CommandStreamTest.Command saturator : fallbackSaturators) {
        saturator.observe();
    }
    try {
        Thread.sleep(70);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    rejection1.observe();
    rejection2.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    //all 7 commands executed on-thread, so should be executed according to thread-pool metrics
    assertEquals(2, stream.getLatest().length);
    assertEquals(7, stream.getLatestCount(HystrixEventType.ThreadPool.EXECUTED));
    assertEquals(0, stream.getLatestCount(HystrixEventType.ThreadPool.REJECTED));
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) ArrayList(java.util.ArrayList) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) CountDownLatch(java.util.concurrent.CountDownLatch) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 9 with HystrixCommandKey

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

the class CumulativeThreadPoolEventCounterStreamTest method testFallbackFailure.

@Test
public void testFallbackFailure() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("Cumulative-ThreadPool-J");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("Cumulative-ThreadPool-J");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("Cumulative-Counter-J");
    stream = CumulativeThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    CommandStreamTest.Command cmd = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20, HystrixEventType.FALLBACK_FAILURE);
    cmd.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(2, stream.getLatest().length);
    assertEquals(1, stream.getLatestCount(HystrixEventType.ThreadPool.EXECUTED));
    assertEquals(0, stream.getLatestCount(HystrixEventType.ThreadPool.REJECTED));
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) CountDownLatch(java.util.concurrent.CountDownLatch) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 10 with HystrixCommandKey

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

the class CumulativeThreadPoolEventCounterStreamTest method testMultipleEventsOverTimeGetStoredAndDoNotAgeOut.

//in a rolling window, take(30) would age out all counters.  in the cumulative count, we expect them to remain non-zero forever
@Test
public void testMultipleEventsOverTimeGetStoredAndDoNotAgeOut() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("Cumulative-ThreadPool-M");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("Cumulative-ThreadPool-M");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("Cumulative-Counter-M");
    stream = CumulativeThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(30).subscribe(getSubscriber(latch));
    CommandStreamTest.Command cmd1 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS, 20);
    CommandStreamTest.Command cmd2 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 10);
    cmd1.observe();
    cmd2.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    //all commands should have aged out
    assertEquals(2, stream.getLatest().length);
    assertEquals(2, stream.getLatestCount(HystrixEventType.ThreadPool.EXECUTED));
    assertEquals(0, stream.getLatestCount(HystrixEventType.ThreadPool.REJECTED));
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) CountDownLatch(java.util.concurrent.CountDownLatch) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Aggregations

HystrixCommandKey (com.netflix.hystrix.HystrixCommandKey)113 Test (org.junit.Test)106 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)99 CountDownLatch (java.util.concurrent.CountDownLatch)99 HystrixThreadPoolKey (com.netflix.hystrix.HystrixThreadPoolKey)42 HystrixCommandGroupKey (com.netflix.hystrix.HystrixCommandGroupKey)38 ArrayList (java.util.ArrayList)25 CachedValuesHistogram (com.netflix.hystrix.metric.CachedValuesHistogram)9 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)8 HystrixContextRunnable (com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable)8 HystrixCommandMetrics (com.netflix.hystrix.HystrixCommandMetrics)7 HystrixCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreaker)5 HystrixCommand (com.netflix.hystrix.HystrixCommand)4 Map (java.util.Map)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 HystrixPropertiesCommandDefault (com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault)3 StringWriter (java.io.StringWriter)3 HystrixCollapserKey (com.netflix.hystrix.HystrixCollapserKey)2 HystrixCollapserConfiguration (com.netflix.hystrix.config.HystrixCollapserConfiguration)2 HystrixCommandConfiguration (com.netflix.hystrix.config.HystrixCommandConfiguration)2