@Test
public void testConcurrencyStreamProperlyFiltersOutSemaphoreRejections() throws InterruptedException {

    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Concurrency-H");
    stream = RollingCommandMaxConcurrencyStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    //10 commands executed concurrently on different caller threads should saturate semaphore
    //once these are in-flight, execute 10 more concurrently on new caller threads.
    //since these are semaphore-rejected, the max concurrency should be 10
    List<Command> saturators = new ArrayList<Command>();
    for (int i = 0; i < 10; i++) {
        saturators.add(Command.from(groupKey, key, HystrixEventType.SUCCESS, 400, HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE));
    }
    final List<Command> rejected = new ArrayList<Command>();
    for (int i = 0; i < 10; i++) {
        rejected.add(Command.from(groupKey, key, HystrixEventType.SUCCESS, 100, HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE));
    }
    for (final Command saturatingCmd: saturators) {
        threadPool.submit(new HystrixContextRunnable(new Runnable() {
            @Override
            public void run() {
                saturatingCmd.observe();
            }
        }));
    }
    Thread.sleep(30);
    for (final Command rejectedCmd: rejected) {
        threadPool.submit(new HystrixContextRunnable(new Runnable() {
            @Override
            public void run() {
                rejectedCmd.observe();
            }
        }));
    }
    assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    assertEquals(10, stream.getLatestRollingMax());
}