@Test
public void testRejectedThreadUsingQueueSize() {

    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("Rejection-B");
    TestCircuitBreaker circuitBreaker = new TestCircuitBreaker();
    SingleThreadedPoolWithQueue pool = new SingleThreadedPoolWithQueue(10, 1);
    // put 1 item in the queue
    // the thread pool won't pick it up because we're bypassing the pool and adding to the queue directly so this will keep the queue full
    pool.queue.add(new Runnable() {
        @Override
        public void run() {
            System.out.println("**** queue filler1 ****");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    TestCommandRejection command = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_NOT_IMPLEMENTED);
    try {
        // this should fail as we already have 1 in the queue
        command.queue();
        fail("we shouldn't get here");
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(command.isResponseRejected());
        assertFalse(command.isResponseShortCircuited());
        assertFalse(command.isResponseTimedOut());
        assertNotNull(command.getExecutionException());
        if (e instanceof HystrixRuntimeException && e.getCause() instanceof RejectedExecutionException) {
            HystrixRuntimeException de = (HystrixRuntimeException) e;
            assertNotNull(de.getFallbackException());
            assertTrue(de.getFallbackException() instanceof UnsupportedOperationException);
            assertNotNull(de.getImplementingClass());
            assertNotNull(de.getCause());
            assertTrue(de.getCause() instanceof RejectedExecutionException);
        } else {
            fail("the exception should be HystrixRuntimeException with cause as RejectedExecutionException");
        }
    }
    assertCommandExecutionEvents(command, HystrixEventType.THREAD_POOL_REJECTED, HystrixEventType.FALLBACK_MISSING);
    assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount());
    assertSaneHystrixRequestLog(1);
}