use of com.netflix.hystrix.metric.CachedValuesHistogram in project Hystrix by Netflix.
the class RollingCommandLatencyDistributionStreamTest method testThreadPoolRejectedCommandDoesNotGetLatencyTracked.
@Test
public void testThreadPoolRejectedCommandDoesNotGetLatencyTracked() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Latency-E");
stream = RollingCommandLatencyDistributionStream.getInstance(key, 10, 100);
stream.startCachingStreamValuesIfUnstarted();
//10 commands with latency should occupy the entire threadpool. execute those, then wait for bucket to roll
//next command should be a thread-pool rejection
List<Command> commands = new ArrayList<Command>();
for (int i = 0; i < 10; i++) {
commands.add(Command.from(groupKey, key, HystrixEventType.SUCCESS, 200));
}
final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(new Subscriber<CachedValuesHistogram>() {
@Override
public void onCompleted() {
latch.countDown();
}
@Override
public void onError(Throwable e) {
fail(e.getMessage());
}
@Override
public void onNext(CachedValuesHistogram distribution) {
System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " Received distribution with count : " + distribution.getTotalCount() + " and mean : " + distribution.getMean());
// if (distribution.getTotalCount() > 0) {
// assertBetween(200, 250, (int) distribution.getMean());
// }
}
});
for (Command cmd : commands) {
cmd.observe();
}
Command threadPoolRejected = Command.from(groupKey, key, HystrixEventType.SUCCESS);
try {
Thread.sleep(40);
threadPoolRejected.observe();
} catch (InterruptedException ie) {
fail(ie.getMessage());
}
try {
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
} catch (InterruptedException ex) {
fail("Interrupted ex");
}
assertEquals(10, stream.getLatest().getTotalCount());
assertBetween(200, 250, stream.getLatestMean());
System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
assertTrue(threadPoolRejected.isResponseThreadPoolRejected());
}
use of com.netflix.hystrix.metric.CachedValuesHistogram in project Hystrix by Netflix.
the class RollingCommandLatencyDistributionStreamTest method testShortCircuitedCommandDoesNotGetLatencyTracked.
@Test
public void testShortCircuitedCommandDoesNotGetLatencyTracked() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Latency-D");
stream = RollingCommandLatencyDistributionStream.getInstance(key, 10, 100);
stream.startCachingStreamValuesIfUnstarted();
//3 failures is enough to trigger short-circuit. execute those, then wait for bucket to roll
//next command should be a short-circuit
List<Command> commands = new ArrayList<Command>();
for (int i = 0; i < 3; i++) {
commands.add(Command.from(groupKey, key, HystrixEventType.FAILURE, 0));
}
final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(new Subscriber<CachedValuesHistogram>() {
@Override
public void onCompleted() {
latch.countDown();
}
@Override
public void onError(Throwable e) {
fail(e.getMessage());
}
@Override
public void onNext(CachedValuesHistogram distribution) {
System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " Received distribution with count : " + distribution.getTotalCount() + " and mean : " + distribution.getMean());
assertBetween(0, 30, (int) distribution.getMean());
}
});
for (Command cmd : commands) {
cmd.observe();
}
Command shortCircuit = Command.from(groupKey, key, HystrixEventType.SUCCESS);
try {
Thread.sleep(200);
shortCircuit.observe();
} catch (InterruptedException ie) {
fail(ie.getMessage());
}
try {
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
} catch (InterruptedException ex) {
fail("Interrupted ex");
}
assertEquals(3, stream.getLatest().getTotalCount());
assertBetween(0, 30, stream.getLatestMean());
System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
assertTrue(shortCircuit.isResponseShortCircuited());
}
Aggregations