@Override protected void after() { if (this.context != null) { this.context.shutdown(); this.context = null; } }
/** * Shutdown {@link HystrixRequestVariableDefault} objects in this context. * <p> * <b>NOTE: This must be called if <code>initializeContext()</code> was called or a memory leak will occur.</b> * * This method invokes <code>shutdown()</code> */ public void close() { shutdown(); }
private void shutdownContextIfExists() { // instead of storing the reference from initialize we'll just get the current state and shutdown if (HystrixRequestContext.getContextForCurrentThread() != null) { // it could have been set NULL by the test HystrixRequestContext.getContextForCurrentThread().shutdown(); } } private static class DummyHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {}
@After public void tearDown() { context.shutdown(); stream.unsubscribe(); RollingCommandMaxConcurrencyStream.reset(); threadPool.shutdown(); }
@After public void tearDown() { context.shutdown(); stream.unsubscribe(); RollingCommandMaxConcurrencyStream.reset(); threadPool.shutdown(); }
@After public void tearDown() { stream.unsubscribe(); context.shutdown(); RollingCollapserBatchSizeDistributionStream.reset(); }
@After public void tearDown() { context.shutdown(); stream.unsubscribe(); RollingCommandEventCounterStream.reset(); }
@Test(expected = HystrixCachingException.class) public void testGetUserByName_givenNonexistentCacheKeyMethod_shouldThrowException() { HystrixRequestContext context = HystrixRequestContext.initializeContext(); try { User user = userService.getUser(); } finally { context.shutdown(); } }
@After public void tearDown() { stream.unsubscribe(); context.shutdown(); RollingCommandLatencyDistributionStream.reset(); }
@After public void tearDown() { context.shutdown(); stream.unsubscribe(); CumulativeCollapserEventCounterStream.reset(); }
@After public void tearDown() { context.shutdown(); stream.unsubscribe(); RollingCommandEventCounterStream.reset(); }
@Test(expected = HystrixCachingException.class) public void testGetUser_givenWrongCacheKeyMethodReturnType_shouldThrowException() { HystrixRequestContext context = HystrixRequestContext.initializeContext(); try { User user = userService.getUserByName("name"); } finally { context.shutdown(); } }
@After public void tearDown() { context.shutdown(); stream.unsubscribe(); CumulativeCommandEventCounterStream.reset(); }
@After public void tearDown() { context.shutdown(); stream.unsubscribe(); RollingCollapserEventCounterStream.reset(); }
@After public void tearDown() { context.shutdown(); stream.unsubscribe(); RollingCommandEventCounterStream.reset(); }
@After public void tearDown() { context.shutdown(); stream.unsubscribe(); RollingCommandEventCounterStream.reset(); }
@Test public void testClearCache() { HystrixConcurrencyStrategy strategy = HystrixConcurrencyStrategyDefault.getInstance(); HystrixRequestContext context = HystrixRequestContext.initializeContext(); try { HystrixRequestCache cache1 = HystrixRequestCache.getInstance(HystrixCommandKey.Factory.asKey("command1"), strategy); cache1.putIfAbsent("valueA", new TestObservable("a1")); assertEquals("a1", cache1.get("valueA").toObservable().toBlocking().last()); cache1.clear("valueA"); assertNull(cache1.get("valueA")); } catch (Exception e) { fail("Exception: " + e.getMessage()); e.printStackTrace(); } finally { context.shutdown(); } }
/** * HystrixConcurrencyStrategy ** useDefaultRequestContext : true * HystrixCommand ** useRequestCache : true ** useRequestLog : true * * OUTCOME: RequestLog set up properly in command */ @Test public void testCommandRequiresContextConcurrencyStrategyProvidesItContextSetUpCorrectly() { HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(true); HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy); //context is set up properly HystrixRequestContext context = HystrixRequestContext.initializeContext(); HystrixCommand<Boolean> cmd = new TestCommand(true, true); assertTrue(cmd.execute()); printRequestLog(); assertNotNull(HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString()); assertNotNull(cmd.currentRequestLog); context.shutdown(); }
/** * HystrixConcurrencyStrategy ** useDefaultRequestContext : false * HystrixCommand ** useRequestCache : false ** useRequestLog : false * * OUTCOME: RequestLog not set up in command, not available statically */ @Test public void testCommandDoesNotRequireContextConcurrencyStrategyDoesNotProvideItContextSetUpCorrectly() { HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(false); HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy); //context is set up properly HystrixRequestContext context = HystrixRequestContext.initializeContext(); HystrixCommand<Boolean> cmd = new TestCommand(true, true); assertTrue(cmd.execute()); printRequestLog(); assertNull(HystrixRequestLog.getCurrentRequest()); assertNull(HystrixRequestLog.getCurrentRequest(strategy)); assertNull(cmd.currentRequestLog); context.shutdown(); }
/** * HystrixConcurrencyStrategy ** useDefaultRequestContext : false * HystrixCommand ** useRequestCache : true ** useRequestLog : true * * OUTCOME: RequestLog not set up in command, not available statically */ @Test public void testCommandRequiresContextConcurrencyStrategyDoesNotProvideItContextSetUpCorrectly() { HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(false); HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy); //context is set up properly HystrixRequestContext context = HystrixRequestContext.initializeContext(); HystrixCommand<Boolean> cmd = new TestCommand(true, true); assertTrue(cmd.execute()); printRequestLog(); assertNull(HystrixRequestLog.getCurrentRequest()); assertNull(HystrixRequestLog.getCurrentRequest(strategy)); assertNull(cmd.currentRequestLog); context.shutdown(); }