Search in sources :

Example 36 with HystrixCommandGroupKey

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

the class RollingThreadPoolEventCounterStreamTest method testFallbackFailure.

@Test
public void testFallbackFailure() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-J");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-J");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingCounter-J");
    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_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 37 with HystrixCommandGroupKey

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

the class RollingThreadPoolMaxConcurrencyStreamTest method testMultipleCommandsCarryOverMultipleBucketsForMultipleThreadPools.

/**
     * BUCKETS
     *     A    |    B    |    C    |    D    |    E    |
     * 1:  [-------------------------------]              ThreadPool x
     * 2:          [-------------------------------]                 y
     * 3:                      [--]                                  x
     * 4:                              [--]                          x
     *
     * Same input data as above test, just that command 2 runs in a separate threadpool, so concurrency should not get tracked
     * Max concurrency should be 2 for x
     */
@Test
public void testMultipleCommandsCarryOverMultipleBucketsForMultipleThreadPools() throws InterruptedException {
    HystrixCommandGroupKey groupKeyX = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-X");
    HystrixCommandGroupKey groupKeyY = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-Y");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-X");
    HystrixCommandKey keyX = HystrixCommandKey.Factory.asKey("RollingConcurrency-X");
    HystrixCommandKey keyY = HystrixCommandKey.Factory.asKey("RollingConcurrency-Y");
    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(groupKeyX, keyX, HystrixEventType.SUCCESS, 300);
    Command cmd2 = Command.from(groupKeyY, keyY, HystrixEventType.SUCCESS, 300);
    Command cmd3 = Command.from(groupKeyX, keyY, HystrixEventType.SUCCESS, 10);
    Command cmd4 = Command.from(groupKeyX, keyY, HystrixEventType.SUCCESS, 10);
    cmd1.observe();
    //bucket roll
    Thread.sleep(100);
    cmd2.observe();
    Thread.sleep(100);
    cmd3.observe();
    Thread.sleep(100);
    cmd4.observe();
    assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    assertEquals(2, 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 38 with HystrixCommandGroupKey

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

the class RollingThreadPoolMaxConcurrencyStreamTest method testMultipleCommandsCarryOverMultipleBuckets.

/**
     * BUCKETS
     *     A    |    B    |    C    |    D    |    E    |
     * 1:  [-------------------------------]
     * 2:          [-------------------------------]
     * 3:                      [--]
     * 4:                              [--]
     *
     * Max concurrency should be 3
     */
@Test
public void testMultipleCommandsCarryOverMultipleBuckets() throws InterruptedException {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-E");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-E");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-E");
    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, 300);
    Command cmd2 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 300);
    Command cmd3 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10);
    Command cmd4 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10);
    cmd1.observe();
    //bucket roll
    Thread.sleep(100);
    cmd2.observe();
    Thread.sleep(100);
    cmd3.observe();
    Thread.sleep(100);
    cmd4.observe();
    assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    assertEquals(3, 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 39 with HystrixCommandGroupKey

use of com.netflix.hystrix.HystrixCommandGroupKey in project java-chassis by ServiceComb.

the class TestCommandKey method testToHystrixCommandGroupKey.

@Test
public void testToHystrixCommandGroupKey() {
    Invocation invocation = Mockito.mock(Invocation.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
    Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
    Assert.assertNotNull(invocation);
    HystrixCommandGroupKey hystrixCommandGroupKey = CommandKey.toHystrixCommandGroupKey("groupname", invocation);
    Assert.assertNotNull(hystrixCommandGroupKey);
}
Also used : Invocation(io.servicecomb.core.Invocation) OperationMeta(io.servicecomb.core.definition.OperationMeta) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) 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