From 9b8d9d1eb3932995b56816ba9156abfe3cb5fd39 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Mon, 19 Oct 2015 16:13:51 -0700 Subject: [PATCH] Add unit test for behavior of HystrixRequestCache without a HystrixRequestContext --- .../netflix/hystrix/HystrixRequestCacheTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixRequestCacheTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixRequestCacheTest.java index 338cc766d..dbc66c172 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixRequestCacheTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixRequestCacheTest.java @@ -84,6 +84,21 @@ public void testClearCache() { } } + @Test + public void testCacheWithoutRequestContext() { + HystrixConcurrencyStrategy strategy = HystrixConcurrencyStrategyDefault.getInstance(); + //HystrixRequestContext context = HystrixRequestContext.initializeContext(); + try { + HystrixRequestCache cache1 = HystrixRequestCache.getInstance(HystrixCommandKey.Factory.asKey("command1"), strategy); + //this should fail, as there's no HystrixRequestContext instance to place the cache into + cache1.putIfAbsent("valueA", new TestObservable("a1")); + fail("should throw an exception on cache put"); + } catch (Exception e) { + //expected + e.printStackTrace(); + } + } + private static class TestObservable extends Observable { public TestObservable(final String value) { super(new OnSubscribe() {