Commit d4ba70db by Dave Syer

Merge branch '1.3.x'

parents 484bde10 a59f5e1c
......@@ -23,12 +23,21 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.PreDestroy;
import com.netflix.config.AggregatedConfiguration;
import com.netflix.config.ConcurrentCompositeConfiguration;
import com.netflix.config.ConfigurationManager;
import com.netflix.config.DeploymentContext;
import com.netflix.config.DynamicProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicURLConfiguration;
import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.ConfigurationBuilder;
import org.apache.commons.configuration.EnvironmentConfiguration;
import org.apache.commons.configuration.SystemConfiguration;
import org.apache.commons.configuration.event.ConfigurationEvent;
import org.apache.commons.configuration.event.ConfigurationListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.endpoint.Endpoint;
......@@ -44,14 +53,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.util.ReflectionUtils;
import com.netflix.config.AggregatedConfiguration;
import com.netflix.config.ConcurrentCompositeConfiguration;
import com.netflix.config.ConfigurationManager;
import com.netflix.config.DeploymentContext;
import com.netflix.config.DynamicProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicURLConfiguration;
import static com.netflix.config.ConfigurationManager.APPLICATION_PROPERTIES;
import static com.netflix.config.ConfigurationManager.DISABLE_DEFAULT_ENV_CONFIG;
import static com.netflix.config.ConfigurationManager.DISABLE_DEFAULT_SYS_CONFIG;
......@@ -79,8 +80,13 @@ public class ArchaiusAutoConfiguration {
@Autowired(required = false)
private List<AbstractConfiguration> externalConfigurations = new ArrayList<>();
private DynamicURLConfiguration defaultURLConfig;
@PreDestroy
public void close() {
if (defaultURLConfig != null) {
defaultURLConfig.stopLoading();
}
setStatic(ConfigurationManager.class, "instance", null);
setStatic(ConfigurationManager.class, "customConfigurationInstalled", false);
setStatic(DynamicPropertyFactory.class, "config", null);
......@@ -154,8 +160,7 @@ public class ArchaiusAutoConfiguration {
config.addConfiguration(envConfig,
ConfigurableEnvironmentConfiguration.class.getSimpleName());
// below come from ConfigurationManager.createDefaultConfigInstance()
DynamicURLConfiguration defaultURLConfig = new DynamicURLConfiguration();
defaultURLConfig = new DynamicURLConfiguration();
try {
config.addConfiguration(defaultURLConfig, URL_CONFIG_NAME);
}
......
......@@ -20,11 +20,9 @@ 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.feign.encoding.FeignAcceptEncodingTests;
import org.springframework.cloud.netflix.metrics.servo.ServoMetricReaderTests;
import org.springframework.cloud.netflix.ribbon.RibbonInterceptorTests;
import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClientTests;
import org.springframework.cloud.netflix.zuul.ZuulProxyConfigurationTests;
import org.springframework.cloud.netflix.zuul.FormZuulServletProxyApplicationTests;
import org.springframework.cloud.netflix.zuul.ZuulProxyAutoConfigurationTests;
/**
* A test suite for probing weird ordering problems in the tests.
......@@ -32,8 +30,8 @@ import org.springframework.cloud.netflix.zuul.ZuulProxyConfigurationTests;
* @author Dave Syer
*/
@RunWith(Suite.class)
@SuiteClasses({ RibbonLoadBalancerClientTests.class, RibbonInterceptorTests.class, FeignAcceptEncodingTests.class,
ServoMetricReaderTests.class, ZuulProxyConfigurationTests.class })
@SuiteClasses({ ZuulProxyAutoConfigurationTests.class,
FormZuulServletProxyApplicationTests.class })
@Ignore
public class AdhocTestSuite {
......
......@@ -16,14 +16,16 @@
package org.springframework.cloud.netflix.feign.encoding;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.Collections;
import java.util.List;
import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......@@ -37,11 +39,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* Tests the response compression.
......@@ -50,7 +52,8 @@ import com.netflix.loadbalancer.Server;
*/
@SpringBootTest(classes = FeignAcceptEncodingTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
"feign.compression.response.enabled=true" })
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@DirtiesContext
public class FeignAcceptEncodingTests {
@Autowired
......
......@@ -20,6 +20,7 @@ package org.springframework.cloud.netflix.ribbon;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.ClassPathExclusions;
import org.springframework.cloud.FilteredClassPathRunner;
......@@ -28,12 +29,12 @@ import org.springframework.cloud.FilteredClassPathRunner;
* @author Ryan Baxter
*/
@RunWith(FilteredClassPathRunner.class)
@ClassPathExclusions({"ribbon-{version:\\d.*}.jar"})
@ClassPathExclusions({ "ribbon-{version:\\d.*}.jar" })
public class RibbonDisabledTests {
@Test(expected = ArrayStoreException.class)
public void testRibbonDisabled() {
new SpringApplicationBuilder().web(false)
.sources(RibbonAutoConfiguration.class).run();
new SpringApplicationBuilder().web(false).sources(RibbonAutoConfiguration.class)
.run().close();
}
}
\ No newline at end of file
......@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.zuul;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -26,6 +27,7 @@ import org.springframework.cloud.netflix.zuul.filters.CompositeRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -39,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest
@DirtiesContext
public class ZuulProxyAutoConfigurationTests {
@Autowired
......@@ -53,7 +56,6 @@ public class ZuulProxyAutoConfigurationTests {
assertThat(this.ribbonRoutingFilter).isNotNull();
}
@Configuration
@EnableAutoConfiguration
@EnableZuulProxy
......
......@@ -18,10 +18,15 @@
package org.springframework.cloud.netflix.zuul.filters.route.support;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.context.RequestContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.web.client.TestRestTemplate;
......@@ -47,10 +52,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
/**
......@@ -67,12 +68,10 @@ public abstract class RibbonRetryIntegrationTestBase {
public void setup() {
RequestContext.getCurrentContext().clear();
String uri = "/resetError";
new TestRestTemplate().exchange(
"http://localhost:" + this.port + uri, HttpMethod.GET,
new HttpEntity<>((Void) null), String.class);
new TestRestTemplate().exchange("http://localhost:" + this.port + uri,
HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
}
@Test
public void retryable() {
String uri = "/retryable/everyothererror";
......@@ -147,9 +146,11 @@ public abstract class RibbonRetryIntegrationTestBase {
@RibbonClient(name = "retryable", configuration = RibbonClientConfiguration.class),
@RibbonClient(name = "disableretry", configuration = RibbonClientConfiguration.class),
@RibbonClient(name = "globalretrydisabled", configuration = RibbonClientConfiguration.class),
@RibbonClient(name = "getretryable", configuration = RibbonClientConfiguration.class)})
@RibbonClient(name = "getretryable", configuration = RibbonClientConfiguration.class) })
public static class RetryableTestConfig {
private final Log LOG = LogFactory.getLog(RetryableTestConfig.class);
private boolean error = true;
@RequestMapping("/resetError")
......@@ -162,13 +163,14 @@ public abstract class RibbonRetryIntegrationTestBase {
boolean shouldError = error;
error = !error;
try {
if(shouldError) {
if (shouldError) {
Thread.sleep(80000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
catch (InterruptedException e) {
LOG.info(e);
Thread.currentThread().interrupt();
}
return new ResponseEntity<String>("no error", HttpStatus.OK);
}
......@@ -183,7 +185,7 @@ public abstract class RibbonRetryIntegrationTestBase {
public ResponseEntity<String> fourOFourError() {
boolean shouldError = error;
error = !error;
if(shouldError) {
if (shouldError) {
return new ResponseEntity<String>("not found", HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>("no error", HttpStatus.OK);
......@@ -204,14 +206,17 @@ public abstract class RibbonRetryIntegrationTestBase {
}
@Configuration
public static class FourOFourRetryableRibbonConfiguration extends RibbonClientConfiguration {
public static class FourOFourRetryableRibbonConfiguration
extends RibbonClientConfiguration {
@Bean
public LoadBalancedRetryPolicyFactory loadBalancedRetryPolicyFactory(SpringClientFactory factory) {
public LoadBalancedRetryPolicyFactory loadBalancedRetryPolicyFactory(
SpringClientFactory factory) {
return new MyRibbonRetryPolicyFactory(factory);
}
public static class MyRibbonRetryPolicyFactory extends RibbonLoadBalancedRetryPolicyFactory {
public static class MyRibbonRetryPolicyFactory
extends RibbonLoadBalancedRetryPolicyFactory {
private SpringClientFactory factory;
......@@ -221,21 +226,25 @@ public abstract class RibbonRetryIntegrationTestBase {
}
@Override
public LoadBalancedRetryPolicy create(String serviceId, ServiceInstanceChooser loadBalanceChooser) {
public LoadBalancedRetryPolicy create(String serviceId,
ServiceInstanceChooser loadBalanceChooser) {
RibbonLoadBalancerContext lbContext = this.factory
.getLoadBalancerContext(serviceId);
return new MyLoadBalancedRetryPolicy(serviceId, lbContext, loadBalanceChooser);
return new MyLoadBalancedRetryPolicy(serviceId, lbContext,
loadBalanceChooser);
}
class MyLoadBalancedRetryPolicy extends RibbonLoadBalancedRetryPolicy {
public MyLoadBalancedRetryPolicy(String serviceId, RibbonLoadBalancerContext context, ServiceInstanceChooser loadBalanceChooser) {
public MyLoadBalancedRetryPolicy(String serviceId,
RibbonLoadBalancerContext context,
ServiceInstanceChooser loadBalanceChooser) {
super(serviceId, context, loadBalanceChooser);
}
@Override
public boolean retryableStatusCode( int statusCode) {
if(statusCode == HttpStatus.NOT_FOUND.value()) {
public boolean retryableStatusCode(int statusCode) {
if (statusCode == HttpStatus.NOT_FOUND.value()) {
return true;
}
return super.retryableStatusCode(statusCode);
......
......@@ -27,9 +27,19 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.http.HttpServletRequest;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.BasicErrorController;
......@@ -43,6 +53,7 @@ import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
import org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider;
import org.springframework.cloud.netflix.zuul.filters.route.support.RibbonRetryIntegrationTestBase.RetryableTestConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
......@@ -65,10 +76,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
......@@ -214,12 +221,13 @@ public abstract class ZuulProxyTestBase {
public void ribbonDeleteWithBody() {
this.endpoint.reset();
ResponseEntity<String> result = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/simple/deletewithbody", HttpMethod.DELETE,
new HttpEntity<>("deleterequestbody"), String.class);
"http://localhost:" + this.port + "/simple/deletewithbody",
HttpMethod.DELETE, new HttpEntity<>("deleterequestbody"), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
if (supportsDeleteWithBody()) {
assertEquals("Deleted deleterequestbody", result.getBody());
} else {
}
else {
assertEquals("Deleted null", result.getBody());
}
}
......@@ -307,6 +315,8 @@ public abstract class ZuulProxyTestBase {
public static abstract class AbstractZuulProxyApplication
extends DelegatingWebMvcConfiguration {
private final Log LOG = LogFactory.getLog(RetryableTestConfig.class);
@RequestMapping(value = "/local/{id}", method = RequestMethod.PATCH)
public String patch(@PathVariable final String id,
@RequestBody final String body) {
......@@ -326,7 +336,8 @@ public abstract class ZuulProxyTestBase {
@RequestMapping(value = "/local", method = RequestMethod.POST)
public String postWithFormParam(HttpServletRequest request,
@RequestBody MultiValueMap<String, String> body) {
return "Posted " + body.get("foo") + " and Content-Length was: " + request.getContentLength() + "!";
return "Posted " + body.get("foo") + " and Content-Length was: "
+ request.getContentLength() + "!";
}
@RequestMapping(value = "/deletewithbody", method = RequestMethod.DELETE)
......@@ -371,8 +382,10 @@ public abstract class ZuulProxyTestBase {
public String slow() {
try {
Thread.sleep(80000);
} catch (InterruptedException e) {
e.printStackTrace();
}
catch (InterruptedException e) {
LOG.info(e);
Thread.currentThread().interrupt();
}
return "slow";
}
......@@ -422,7 +435,6 @@ public abstract class ZuulProxyTestBase {
return mapping;
}
}
public static class FallbackProvider implements ZuulFallbackProvider {
......@@ -471,12 +483,14 @@ public abstract class ZuulProxyTestBase {
}
@Configuration
public class FormEncodedMessageConverterConfiguration extends WebMvcConfigurerAdapter {
public class FormEncodedMessageConverterConfiguration
extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
FormHttpMessageConverter converter = new FormHttpMessageConverter();
MediaType mediaType = new MediaType("application", "x-www-form-urlencoded", Charset.forName("UTF-8"));
MediaType mediaType = new MediaType("application", "x-www-form-urlencoded",
Charset.forName("UTF-8"));
converter.setSupportedMediaTypes(Arrays.asList(mediaType));
converters.add(converter);
super.configureMessageConverters(converters);
......@@ -521,7 +535,8 @@ public abstract class ZuulProxyTestBase {
@Override
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
String errorUri = (String) request.getAttribute("javax.servlet.error.request_uri");
String errorUri = (String) request
.getAttribute("javax.servlet.error.request_uri");
if (errorUri != null && errorUri.equals(this.uriToMatch.get())) {
controllerUsed.set(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment