HystrixCommandKey key = HystrixCommandKey.Factory.asKey("Rejection-A"); TestCommandRejection command1 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_FAILURE); //this should pass through the queue and sit in the pool TestCommandRejection command2 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_SUCCESS); //this should sit in the queue TestCommandRejection command3 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_FAILURE); //this should observe full queue and get rejected Future<Boolean> f1 = null; Future<Boolean> f2 = null; try { f1 = command1.queue(); f2 = command2.queue(); assertEquals(false, command3.queue().get()); //should get thread-pool rejected fail("we shouldn't get here"); } catch (Exception e) {
@Test public void testCancelledTasksInQueueGetRemoved() throws Exception { HystrixCommandKey key = HystrixCommandKey.Factory.asKey("Cancellation-A"); TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); SingleThreadedPoolWithQueue pool = new SingleThreadedPoolWithQueue(10, 1); TestCommandRejection command1 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_NOT_IMPLEMENTED); TestCommandRejection command2 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_NOT_IMPLEMENTED); // this should go through the queue and into the thread pool Future<Boolean> poolFiller = command1.queue(); // this command will stay in the queue until the thread pool is empty Observable<Boolean> cmdInQueue = command2.observe(); Subscription s = cmdInQueue.subscribe(); assertEquals(1, pool.queue.size()); s.unsubscribe(); assertEquals(0, pool.queue.size()); //make sure we wait for the command to finish so the state is clean for next test poolFiller.get(); assertCommandExecutionEvents(command1, HystrixEventType.SUCCESS); assertCommandExecutionEvents(command2, HystrixEventType.CANCELLED); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString()); assertSaneHystrixRequestLog(2); }
TestCommandRejection command2 = null; try { command1 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_NOT_IMPLEMENTED); f = command1.queue(); command2 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_NOT_IMPLEMENTED); command2.queue(); fail("we shouldn't get here"); } catch (Exception e) { e.printStackTrace(); System.out.println("command.getExecutionTimeInMilliseconds(): " + command2.getExecutionTimeInMilliseconds()); assertTrue(command2.isResponseRejected()); assertFalse(command2.isResponseShortCircuited()); assertFalse(command2.isResponseTimedOut()); assertNotNull(command2.getExecutionException());
TestCommandRejection command = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_NOT_IMPLEMENTED); try { 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());
TestCommandRejection command1 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_SUCCESS); TestCommandRejection command2 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_SUCCESS); TestCommandRejection command3 = new TestCommandRejection(key, circuitBreaker, pool, 500, 600, TestCommandRejection.FALLBACK_SUCCESS); Observable<Boolean> result1 = command1.observe(); Observable<Boolean> result2 = command2.observe(); assertFalse(command3.execute()); assertTrue(command3.isResponseRejected()); assertFalse(command1.isResponseRejected()); assertFalse(command2.isResponseRejected()); assertTrue(command3.isResponseFromFallback()); assertNotNull(command3.getExecutionException());