Search in sources :

Example 31 with HystrixCommandGroupKey

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

the class RollingThreadPoolMaxConcurrencyStreamTest method testStartsAndEndsInSameBucketSemaphoreIsolated.

@Test
public void testStartsAndEndsInSameBucketSemaphoreIsolated() throws InterruptedException {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-C");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-C");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-C");
    stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    Command cmd1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10, HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);
    Command cmd2 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 14, HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);
    cmd1.observe();
    Thread.sleep(1);
    cmd2.observe();
    assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    //since commands run in semaphore isolation, they are not tracked by threadpool metrics
    assertEquals(0, stream.getLatestRollingMax());
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) 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 32 with HystrixCommandGroupKey

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

the class RollingThreadPoolEventCounterStreamTest method testFallbackMissing.

@Test
public void testFallbackMissing() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-K");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-K");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingCounter-K");
    stream = RollingThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 500);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(5).subscribe(getSubscriber(latch));
    CommandStreamTest.Command cmd = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20, HystrixEventType.FALLBACK_MISSING);
    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 33 with HystrixCommandGroupKey

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

the class RollingThreadPoolEventCounterStreamTest method testSingleSuccess.

@Test
public void testSingleSuccess() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-B");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-B");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingCounter-B");
    stream = RollingThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 500);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(5).subscribe(getSubscriber(latch));
    CommandStreamTest.Command cmd = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS, 20);
    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 34 with HystrixCommandGroupKey

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

the class RollingThreadPoolEventCounterStreamTest method testFallbackRejection.

@Test
public void testFallbackRejection() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-L");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-L");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingCounter-L");
    stream = RollingThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 500);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(5).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 35 with HystrixCommandGroupKey

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

the class RollingThreadPoolEventCounterStreamTest method testRequestFromCache.

@Test
public void testRequestFromCache() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-F");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-F");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingCounter-F");
    stream = RollingThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 500);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(5).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)

Aggregations

HystrixCommandGroupKey (com.netflix.hystrix.HystrixCommandGroupKey)39 HystrixCommandKey (com.netflix.hystrix.HystrixCommandKey)38 HystrixThreadPoolKey (com.netflix.hystrix.HystrixThreadPoolKey)38 Test (org.junit.Test)38 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)37 CountDownLatch (java.util.concurrent.CountDownLatch)37 ArrayList (java.util.ArrayList)9 HystrixContextRunnable (com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable)3 HystrixCommand (com.netflix.hystrix.HystrixCommand)1 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)1 HystrixThreadPoolProperties (com.netflix.hystrix.HystrixThreadPoolProperties)1 Invocation (io.servicecomb.core.Invocation)1 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 Processor (org.apache.camel.Processor)1 HystrixConfigurationDefinition (org.apache.camel.model.HystrixConfigurationDefinition)1