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));
}
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());
}
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());
}
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);
}
Aggregations