@Test
public void testConcurrencyStreamProperlyFiltersOutShortCircuits() throws InterruptedException {

    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-H");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-H");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-H");
    stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    //after 3 failures, next command should short-circuit.
    //to prove short-circuited commands don't contribute to concurrency, execute 3 FAILURES in the first bucket sequentially
    //then when circuit is open, execute 20 concurrent commands.  they should all get short-circuited, and max concurrency should be 1
    Command failure1 = Command.from(groupKey, key, HystrixEventType.FAILURE);
    Command failure2 = Command.from(groupKey, key, HystrixEventType.FAILURE);
    Command failure3 = Command.from(groupKey, key, HystrixEventType.FAILURE);
    List<Command> shortCircuited = new ArrayList<Command>();
    for (int i = 0; i < 20; i++) {
        shortCircuited.add(Command.from(groupKey, key, HystrixEventType.SUCCESS, 100));
    }
    failure1.execute();
    failure2.execute();
    failure3.execute();
    Thread.sleep(150);
    for (Command cmd: shortCircuited) {
        cmd.observe();
    }
    assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    for (Command cmd: shortCircuited) {
        assertTrue(cmd.isResponseShortCircuited());
    }
    assertEquals(1, stream.getLatestRollingMax());
}