TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); TestSemaphoreCommandWithSlowFallback command1 = new TestSemaphoreCommandWithSlowFallback(circuitBreaker, 1, 200); boolean result = command1.queue().get(); assertTrue(result); try { System.out.println("c2 start: " + System.currentTimeMillis()); command2 = new TestSemaphoreCommandWithSlowFallback(circuitBreaker, 1, 800); result2 = command2.queue(); System.out.println("c2 after queue: " + System.currentTimeMillis()); command3 = new TestSemaphoreCommandWithSlowFallback(circuitBreaker, 1, 200); Future<Boolean> result3 = command3.queue(); System.out.println("c3 after queue: " + System.currentTimeMillis()); result3.get();
private TestSemaphoreCommandWithSlowFallback(TestCircuitBreaker circuitBreaker, int fallbackSemaphoreExecutionCount, long fallbackSleep) { super(testPropsBuilder().setCircuitBreaker(circuitBreaker).setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withFallbackIsolationSemaphoreMaxConcurrentRequests(fallbackSemaphoreExecutionCount).withExecutionIsolationThreadInterruptOnTimeout(false))); this.fallbackSleep = fallbackSleep; }