@Override protected void before() { this.context = HystrixRequestContext.initializeContext(); Hystrix.reset(); }
@Before public void prepareForTest() { /* we must call this to simulate a new request lifecycle running and clearing caches */ HystrixRequestContext.initializeContext(); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); threadPool = Executors.newFixedThreadPool(20); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); threadPool = Executors.newFixedThreadPool(20); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); }
@Before public void setUp() { context = HystrixRequestContext.initializeContext(); }
@Test(expected = HystrixCachingException.class) public void testGetUser_givenWrongCacheKeyMethodReturnType_shouldThrowException() { HystrixRequestContext context = HystrixRequestContext.initializeContext(); try { User user = userService.getUserByName("name"); } finally { context.shutdown(); } }
@Test(expected = HystrixCachingException.class) public void testGetUserByName_givenNonexistentCacheKeyMethod_shouldThrowException() { HystrixRequestContext context = HystrixRequestContext.initializeContext(); try { User user = userService.getUser(); } finally { context.shutdown(); } }
@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 : 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(); }
/** * HystrixConcurrencyStrategy ** useDefaultRequestContext : true * HystrixCommand ** useRequestCache : false ** useRequestLog : false * * OUTCOME: RequestLog not set up in command, static access works properly */ @Test public void testCommandDoesNotRequireContextConcurrencyStrategyProvidesItContextSetUpCorrectly() { HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(true); HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy); //context is set up properly HystrixRequestContext context = HystrixRequestContext.initializeContext(); HystrixCommand<Boolean> cmd = new TestCommand(false, false); assertTrue(cmd.execute()); printRequestLog(); assertNotNull(HystrixRequestLog.getCurrentRequest()); assertNotNull(HystrixRequestLog.getCurrentRequest(strategy)); assertNull(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(); }