Browse Source

Reset Zuul state some more

Tests are very sensitive to the Zuul RequestContext which is
thread bound.
pull/6/head
Dave Syer 9 years ago
parent
commit
cb13b9dd77
  1. 9
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java
  2. 32
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulProxyApplicationTests.java
  3. 7
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java

9
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java

@ -20,9 +20,6 @@ import org.junit.Ignore;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Suite; import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; import org.junit.runners.Suite.SuiteClasses;
import org.springframework.cloud.netflix.zuul.filters.CustomHostRoutingFilterTests;
import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelperTests;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocatorTests;
/** /**
* A test suite for probing weird ordering problems in the tests. * A test suite for probing weird ordering problems in the tests.
@ -30,8 +27,10 @@ import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientR
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(Suite.class) @RunWith(Suite.class)
@SuiteClasses({ DiscoveryClientRouteLocatorTests.class, @SuiteClasses({
CustomHostRoutingFilterTests.class, ProxyRequestHelperTests.class }) org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelperTests.class,
org.springframework.cloud.netflix.zuul.SampleZuulProxyApplicationTests.class,
org.springframework.cloud.netflix.zuul.FormZuulProxyApplicationTests.class })
@Ignore @Ignore
public class AdhocTestSuite { public class AdhocTestSuite {

32
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulProxyApplicationTests.java

@ -16,14 +16,11 @@
package org.springframework.cloud.netflix.zuul; package org.springframework.cloud.netflix.zuul;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map; import java.util.Map;
import lombok.extern.slf4j.Slf4j; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -59,6 +56,11 @@ import org.springframework.web.multipart.MultipartFile;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList; import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
import lombok.extern.slf4j.Slf4j;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = FormZuulProxyApplication.class) @SpringApplicationConfiguration(classes = FormZuulProxyApplication.class)
@ -70,6 +72,12 @@ public class FormZuulProxyApplicationTests {
@Value("${local.server.port}") @Value("${local.server.port}")
private int port; private int port;
@Before
public void setTestRequestcontext() {
RequestContext context = new RequestContext();
RequestContext.testSetCurrentContext(context);
}
@Test @Test
public void postWithForm() { public void postWithForm() {
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
@ -120,8 +128,8 @@ public class FormZuulProxyApplicationTests {
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.set("foo", "bar"); form.set("foo", "bar");
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType headers.setContentType(MediaType.valueOf(
.valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE + "; charset=UTF-8")); MediaType.APPLICATION_FORM_URLENCODED_VALUE + "; charset=UTF-8"));
ResponseEntity<String> result = new TestRestTemplate().exchange( ResponseEntity<String> result = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/simple/form", HttpMethod.POST, "http://localhost:" + this.port + "/simple/form", HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers), new HttpEntity<MultiValueMap<String, String>>(form, headers),
@ -211,11 +219,11 @@ class FormZuulProxyApplication {
} }
public static void main(String[] args) { public static void main(String[] args) {
new SpringApplicationBuilder(FormZuulProxyApplication.class).properties( new SpringApplicationBuilder(FormZuulProxyApplication.class)
"zuul.routes.simple:/simple/**", .properties("zuul.routes.simple:/simple/**",
"zuul.routes.direct.url:http://localhost:9999", "zuul.routes.direct.url:http://localhost:9999",
"multipart.maxFileSize:4096MB", "multipart.maxRequestSize:4096MB").run( "multipart.maxFileSize:4096MB", "multipart.maxRequestSize:4096MB")
args); .run(args);
} }
} }
@ -229,7 +237,7 @@ class FormRibbonClientConfiguration {
@Bean @Bean
public ServerList<Server> ribbonServerList() { public ServerList<Server> ribbonServerList() {
return new StaticServerList<>(new Server("localhost", port)); return new StaticServerList<>(new Server("localhost", this.port));
} }
} }

7
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java

@ -23,6 +23,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -88,6 +89,12 @@ public class SampleZuulProxyApplicationTests {
@Autowired @Autowired
private RibbonCommandFactory<?> ribbonCommandFactory; private RibbonCommandFactory<?> ribbonCommandFactory;
@Before
public void setTestRequestcontext() {
RequestContext context = new RequestContext();
RequestContext.testSetCurrentContext(context);
}
private String getRoute(String path) { private String getRoute(String path) {
for (Route route : this.routes.getRoutes()) { for (Route route : this.routes.getRoutes()) {
if (path.equals(route.getFullPath())) { if (path.equals(route.getFullPath())) {

Loading…
Cancel
Save