public void TestCacheWithoutRequestContext() { HystrixConcurrencyStrategy strategy = HystrixConcurrencyStrategyDefault.GetInstance(); context.Dispose(); HystrixRequestCache cache1 = HystrixRequestCache.GetInstance(HystrixCommandKeyDefault.AsKey("command1")); Task <string> t1 = Task.FromResult("a1"); // this should fail, as there's no HystrixRequestContext instance to place the cache into Assert.Throws <InvalidOperationException>(() => { cache1.PutIfAbsent("valueA", t1); }); }
public void TestClearCache() { HystrixConcurrencyStrategy strategy = HystrixConcurrencyStrategyDefault.GetInstance(); try { HystrixRequestCache cache1 = HystrixRequestCache.GetInstance(HystrixCommandKeyDefault.AsKey("command1")); Task <string> t1 = Task.FromResult("a1"); cache1.PutIfAbsent("valueA", t1); Assert.Equal("a1", cache1.Get <Task <string> >("valueA").Result); cache1.Clear("valueA"); Assert.Null(cache1.Get <Task <string> >("valueA")); } catch (Exception e) { Assert.False(true, "Exception: " + e.Message); output.WriteLine(e.ToString()); } }