/** * Test Request scoped caching doesn't prevent different ones from executing */ @Test public void testRequestCache2UsingThreadIsolation() { TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); SuccessfulCacheableCommand<String> command1 = new SuccessfulCacheableCommand<String>(circuitBreaker, true, "A"); SuccessfulCacheableCommand<String> command2 = new SuccessfulCacheableCommand<String>(circuitBreaker, true, "B"); assertTrue(command1.isCommandRunningInThread()); Future<String> f1 = command1.observe().toBlocking().toFuture(); Future<String> f2 = command2.observe().toBlocking().toFuture(); try { assertEquals("A", f1.get()); assertEquals("B", f2.get()); } catch (Exception e) { throw new RuntimeException(e); } assertTrue(command1.executed); // both should execute as they are different assertTrue(command2.executed); assertCommandExecutionEvents(command1, HystrixEventType.EMIT, HystrixEventType.SUCCESS); assertCommandExecutionEvents(command2, HystrixEventType.EMIT, HystrixEventType.SUCCESS); assertTrue(command2.getExecutionTimeInMilliseconds() > -1); assertFalse(command2.isResponseFromCache()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); assertSaneHystrixRequestLog(2); }
assertCommandExecutionEvents(command2, HystrixEventType.EMIT, HystrixEventType.SUCCESS); assertCommandExecutionEvents(command3, HystrixEventType.EMIT, HystrixEventType.SUCCESS, HystrixEventType.RESPONSE_FROM_CACHE); assertTrue(command3.getExecutionTimeInMilliseconds() == -1); assertTrue(command3.isResponseFromCache());
assertTrue(command1.getExecutionTimeInMilliseconds() > -1); assertFalse(command1.isResponseFromCache()); assertNull(command1.getExecutionException()); assertTrue(command2.getExecutionTimeInMilliseconds() == -1); assertTrue(command2.isResponseFromCache()); assertNull(command2.getExecutionException());