Search in sources :

Example 11 with HystrixCommandGroupKey

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

the class RollingThreadPoolEventCounterStreamTest method testThreadPoolRejected.

@Test
public void testThreadPoolRejected() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-I");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-I");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingCounter-I");
    stream = RollingThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 500);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(5).subscribe(getSubscriber(latch));
    //10 commands will saturate threadpools when called concurrently.
    //submit 2 more requests and they should be THREADPOOL_REJECTED
    //should see 10 SUCCESSes, 2 THREADPOOL_REJECTED and 2 FALLBACK_SUCCESSes
    List<CommandStreamTest.Command> saturators = new ArrayList<CommandStreamTest.Command>();
    for (int i = 0; i < 10; i++) {
        saturators.add(CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS, 200));
    }
    CommandStreamTest.Command rejected1 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS, 0);
    CommandStreamTest.Command rejected2 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS, 0);
    for (final CommandStreamTest.Command saturator : saturators) {
        saturator.observe();
    }
    try {
        Thread.sleep(100);
    } catch (InterruptedException ie) {
        fail(ie.getMessage());
    }
    rejected1.observe();
    rejected2.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    assertTrue(rejected1.isResponseThreadPoolRejected());
    assertTrue(rejected2.isResponseThreadPoolRejected());
    //all 12 commands got submitted to thread pool, 10 accepted, 2 rejected is expected
    assertEquals(2, stream.getLatest().length);
    assertEquals(10, stream.getLatestCount(HystrixEventType.ThreadPool.EXECUTED));
    assertEquals(2, 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 12 with HystrixCommandGroupKey

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

the class RollingThreadPoolEventCounterStreamTest method testSingleBadRequest.

@Test
public void testSingleBadRequest() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-E");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-E");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingCounter-E");
    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.BAD_REQUEST);
    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 13 with HystrixCommandGroupKey

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

the class RollingThreadPoolEventCounterStreamTest method testShortCircuited.

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

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

the class RollingThreadPoolEventCounterStreamTest method testEmptyStreamProducesZeros.

@Test
public void testEmptyStreamProducesZeros() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-A");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-A");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingCounter-A");
    stream = RollingThreadPoolEventCounterStream.getInstance(threadPoolKey, 10, 500);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(5).subscribe(getSubscriber(latch));
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(2, stream.getLatest().length);
    assertEquals(0, stream.getLatestCount(HystrixEventType.ThreadPool.EXECUTED) + stream.getLatestCount(HystrixEventType.ThreadPool.REJECTED));
}
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 15 with HystrixCommandGroupKey

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

the class RollingThreadPoolEventCounterStreamTest method testSingleTimeout.

@Test
public void testSingleTimeout() {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-D");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-D");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingCounter-D");
    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.TIMEOUT);
    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)

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