Skip to content

Commit

Permalink
Merge pull request #1184 from caarlos0/context-rule
Browse files Browse the repository at this point in the history
migrating all hystrix-javanica tests to hystrix-junit
  • Loading branch information
mattrjacobs committed Apr 20, 2016
2 parents bd2a6ee + 16e1af1 commit f59728a
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 36 deletions.
1 change: 1 addition & 0 deletions hystrix-contrib/hystrix-javanica/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public abstract class BasicCacheTest extends BasicHystrixTest {

@Before
public void setUp() throws Exception {
super.setUp();
userService = createUserService();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public abstract class BasicCollapserTest extends BasicHystrixTest {

@Before
public void setUp() throws Exception {
super.setUp();
userService = createUserService();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public abstract class BasicCommandTest extends BasicHystrixTest {

@Before
public void setUp() throws Exception {
super.setUp();
userService = createUserService();
advancedUserService = createAdvancedUserServiceService();
genericUserService = createGenericUserService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public abstract class BasicCollapserPropertiesTest extends BasicHystrixTest {

@Before
public void setUp() throws Exception {
super.setUp();
userService = createUserService();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public abstract class BasicCommandPropertiesTest extends BasicHystrixTest {
@Before
public void setUp() throws Exception {
userService = createUserService();
super.setUp();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public abstract class BasicCommandFallbackTest extends BasicHystrixTest {

@Before
public void setUp() throws Exception {
super.setUp();
userService = createUserService();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public abstract class BasicObservableTest extends BasicHystrixTest {

@Before
public void setUp() throws Exception {
super.setUp();
userService = createUserService();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -50,4 +52,9 @@ protected void after() {
public HystrixRequestContext context() {
return this.context;
}

public void reset() {
after();
before();
}
}

0 comments on commit f59728a

Please sign in to comment.