diff --git a/hystrix-contrib/hystrix-javanica/build.gradle b/hystrix-contrib/hystrix-javanica/build.gradle index f29921274..3f1b1c289 100644 --- a/hystrix-contrib/hystrix-javanica/build.gradle +++ b/hystrix-contrib/hystrix-javanica/build.gradle @@ -105,6 +105,7 @@ dependencies { compile 'com.google.code.findbugs:jsr305:2.0.0' compile 'org.ow2.asm:asm:5.0.4' testCompile 'junit:junit-dep:4.10' + testCompile project(':hystrix-junit') testCompile 'org.springframework:spring-core:4.0.0.RELEASE' testCompile 'org.springframework:spring-context:4.0.0.RELEASE' testCompile 'org.springframework:spring-aop:4.0.0.RELEASE' diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/BasicHystrixTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/BasicHystrixTest.java index cba8c018a..d1dbfa35b 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/BasicHystrixTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/BasicHystrixTest.java @@ -15,43 +15,22 @@ */ package com.netflix.hystrix.contrib.javanica.test.common; -import com.netflix.hystrix.Hystrix; +import com.hystrix.junit.HystrixRequestContextRule; import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; /** * Created by dmgcodevil */ public abstract class BasicHystrixTest { - - private HystrixRequestContext context; + @Rule + public HystrixRequestContextRule request = new HystrixRequestContextRule(); protected final HystrixRequestContext getHystrixContext() { - return context; - } - - @Before - public void setUp() throws Exception { - context = createContext(); - } - - @After - public void tearDown() throws Exception { - context.shutdown(); - } - - private HystrixRequestContext createContext() { - HystrixRequestContext c = HystrixRequestContext.initializeContext(); - Hystrix.reset(); - return c; + return request.context(); } - protected void resetContext() { - if (context != null) { - context.shutdown(); - } - context = createContext(); + request.reset(); } } diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/cache/BasicCacheTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/cache/BasicCacheTest.java index b8840bce5..620f6ecdb 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/cache/BasicCacheTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/cache/BasicCacheTest.java @@ -48,7 +48,6 @@ public abstract class BasicCacheTest extends BasicHystrixTest { @Before public void setUp() throws Exception { - super.setUp(); userService = createUserService(); } diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/collapser/BasicCollapserTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/collapser/BasicCollapserTest.java index dbddc4ca8..7a15839a7 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/collapser/BasicCollapserTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/collapser/BasicCollapserTest.java @@ -46,7 +46,6 @@ public abstract class BasicCollapserTest extends BasicHystrixTest { @Before public void setUp() throws Exception { - super.setUp(); userService = createUserService(); } diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/command/BasicCommandTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/command/BasicCommandTest.java index bf23085d9..1fbb1407a 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/command/BasicCommandTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/command/BasicCommandTest.java @@ -40,7 +40,6 @@ public abstract class BasicCommandTest extends BasicHystrixTest { @Before public void setUp() throws Exception { - super.setUp(); userService = createUserService(); advancedUserService = createAdvancedUserServiceService(); genericUserService = createGenericUserService(); diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/configuration/collapser/BasicCollapserPropertiesTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/configuration/collapser/BasicCollapserPropertiesTest.java index c1d73b1e4..cbf9b3c3e 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/configuration/collapser/BasicCollapserPropertiesTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/configuration/collapser/BasicCollapserPropertiesTest.java @@ -46,7 +46,6 @@ public abstract class BasicCollapserPropertiesTest extends BasicHystrixTest { @Before public void setUp() throws Exception { - super.setUp(); userService = createUserService(); } diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/configuration/command/BasicCommandPropertiesTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/configuration/command/BasicCommandPropertiesTest.java index a3e9ea5b3..b4792ff3b 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/configuration/command/BasicCommandPropertiesTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/configuration/command/BasicCommandPropertiesTest.java @@ -67,7 +67,6 @@ public abstract class BasicCommandPropertiesTest extends BasicHystrixTest { @Before public void setUp() throws Exception { userService = createUserService(); - super.setUp(); } @Test diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/error/BasicErrorPropagationTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/error/BasicErrorPropagationTest.java index 73857e3a8..beba54c38 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/error/BasicErrorPropagationTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/error/BasicErrorPropagationTest.java @@ -61,7 +61,6 @@ public abstract class BasicErrorPropagationTest extends BasicHystrixTest { @Before public void setUp() throws Exception { - super.setUp(); MockitoAnnotations.initMocks(this); userService = createUserService(); userService.setFailoverService(failoverService); diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/fallback/BasicCommandFallbackTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/fallback/BasicCommandFallbackTest.java index 5f15587e3..99153fd3e 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/fallback/BasicCommandFallbackTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/fallback/BasicCommandFallbackTest.java @@ -46,7 +46,6 @@ public abstract class BasicCommandFallbackTest extends BasicHystrixTest { @Before public void setUp() throws Exception { - super.setUp(); userService = createUserService(); } diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/observable/BasicObservableTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/observable/BasicObservableTest.java index ab34f4ea2..a6e88517e 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/observable/BasicObservableTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/observable/BasicObservableTest.java @@ -46,7 +46,6 @@ public abstract class BasicObservableTest extends BasicHystrixTest { @Before public void setUp() throws Exception { - super.setUp(); userService = createUserService(); } diff --git a/hystrix-contrib/hystrix-junit/src/main/java/com/hystrix/junit/HystrixRequestContextRule.java b/hystrix-contrib/hystrix-junit/src/main/java/com/hystrix/junit/HystrixRequestContextRule.java index d362335a1..eaf258005 100644 --- a/hystrix-contrib/hystrix-junit/src/main/java/com/hystrix/junit/HystrixRequestContextRule.java +++ b/hystrix-contrib/hystrix-junit/src/main/java/com/hystrix/junit/HystrixRequestContextRule.java @@ -15,6 +15,7 @@ */ package com.hystrix.junit; +import com.netflix.hystrix.Hystrix; import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; import org.junit.rules.ExternalResource; @@ -35,8 +36,9 @@ public final class HystrixRequestContextRule extends ExternalResource { private HystrixRequestContext context; @Override - protected void before() throws Throwable { + protected void before() { this.context = HystrixRequestContext.initializeContext(); + Hystrix.reset(); } @Override @@ -50,4 +52,9 @@ protected void after() { public HystrixRequestContext context() { return this.context; } + + public void reset() { + after(); + before(); + } }