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; @@ -20,9 +20,6 @@ import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
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.
@ -30,8 +27,10 @@ import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientR @@ -30,8 +27,10 @@ import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientR
* @author Dave Syer
*/
@RunWith(Suite.class)
@SuiteClasses({ DiscoveryClientRouteLocatorTests.class,
CustomHostRoutingFilterTests.class, ProxyRequestHelperTests.class })
@SuiteClasses({
org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelperTests.class,
org.springframework.cloud.netflix.zuul.SampleZuulProxyApplicationTests.class,
org.springframework.cloud.netflix.zuul.FormZuulProxyApplicationTests.class })
@Ignore
public class AdhocTestSuite {

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

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

Loading…
Cancel
Save