@Test
public void testSingleBucketWithMultipleEventTypes() {

    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Latency-C");
    stream = RollingCommandLatencyDistributionStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    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() < 4 && distribution.getTotalCount() > 0) { //buckets before timeout latency registers
                    assertBetween(10, 50, (int) distribution.getMean());
                } else if (distribution.getTotalCount() == 4){
                    assertBetween(150, 250, (int) distribution.getMean()); //now timeout latency of 600ms is there
                }
        }
    });
    Command cmd1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10);
    Command cmd2 = Command.from(groupKey, key, HystrixEventType.TIMEOUT); //latency = 600
    Command cmd3 = Command.from(groupKey, key, HystrixEventType.FAILURE, 30);
    Command cmd4 = Command.from(groupKey, key, HystrixEventType.BAD_REQUEST, 40);
    cmd1.observe();
    cmd2.observe();
    cmd3.observe();
    cmd4.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertBetween(150, 350, stream.getLatestMean()); //now timeout latency of 600ms is there
    assertBetween(10, 40, stream.getLatestPercentile(0.0));
    assertBetween(600, 800, stream.getLatestPercentile(100.0));
}