/** * Retrieve instance of {@link HystrixConcurrencyStrategy} to use based on order of precedence as * defined in {@link HystrixPlugins} class header. * * <p>Override default by using {@link #registerConcurrencyStrategy(HystrixConcurrencyStrategy)} * or setting property: <code>hystrix.plugin.HystrixConcurrencyStrategy.implementation</code> with * the full classname to load. * * @return {@link HystrixConcurrencyStrategy} implementation to use */ public HystrixConcurrencyStrategy getConcurrencyStrategy() { if (concurrencyStrategy.get() == null) { // check for an implementation from System.getProperty first Object impl = getPluginImplementationViaProperty(HystrixConcurrencyStrategy.class); if (impl == null) { // nothing set via properties so initialize with default concurrencyStrategy.compareAndSet(null, HystrixConcurrencyStrategyDefault.getInstance()); // we don't return from here but call get() again in case of thread-race so the winner will // always get returned } else { // we received an implementation from the system property so use it concurrencyStrategy.compareAndSet(null, (HystrixConcurrencyStrategy) impl); } } return concurrencyStrategy.get(); }
@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").toBlocking().last()); cache1.clear("valueA"); assertNull(cache1.get("valueA")); } catch (Exception e) { fail("Exception: " + e.getMessage()); e.printStackTrace(); } finally { context.shutdown(); } }