From 519b6adb71cd7bf57d18a1e85af13ffd8dfbb8b9 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Thu, 5 Feb 2015 17:25:11 -0800 Subject: [PATCH] Made HystrixCollapserMetrics resettable --- .../src/main/java/com/netflix/hystrix/Hystrix.java | 1 + .../hystrix/HystrixObservableCollapserTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java b/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java index 3d5d8570a..837bae223 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java @@ -54,6 +54,7 @@ private static void _reset() { // clear metrics HystrixCommandMetrics.reset(); HystrixThreadPoolMetrics.reset(); + HystrixCollapserMetrics.reset(); // clear collapsers HystrixCollapser.reset(); // clear circuit breakers diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCollapserTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCollapserTest.java index c6fe5bb71..2c394fa83 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCollapserTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCollapserTest.java @@ -46,6 +46,7 @@ public class HystrixObservableCollapserTest { public void init() { // since we're going to modify properties of the same class between tests, wipe the cache each time HystrixCollapser.reset(); + Hystrix.reset(); /* we must call this to simulate a new request lifecycle running and clearing caches */ HystrixRequestContext.initializeContext(); } @@ -80,6 +81,15 @@ public void testTwoRequests() throws Exception { assertEquals(0L, metrics.getRollingCount(HystrixRollingNumberEvent.RESPONSE_FROM_CACHE)); } + @Test + public void stressTestRequestCollapser() throws Exception { + for(int i = 0; i < 1000; i++) { + init(); + testTwoRequests(); + cleanup(); + } + } + private static class TestRequestCollapser extends HystrixObservableCollapser { private final String value;