Ensured reusability of Feign components

Tests have been refactored to ensure that the custom components registered as beans are working properly

fixes #374
This commit is contained in:
Marcin Grzejszczak
2016-08-16 10:39:03 +02:00
parent e0fbcfe7c6
commit f677be026e
7 changed files with 26 additions and 15 deletions

View File

@@ -21,7 +21,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.springframework.cloud.sleuth.instrument.web.RestTemplateTraceAspectIntegrationTests;
import org.springframework.cloud.sleuth.instrument.web.client.WebClientDiscoveryExceptionTests;
import org.springframework.cloud.sleuth.instrument.web.client.discoveryexception.WebClientDiscoveryExceptionTests;
/**
* A test suite for probing weird ordering problems in the tests.

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.sleuth.instrument.web.client;
package org.springframework.cloud.sleuth.instrument.web.client.discoveryexception;
import java.io.IOException;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.sleuth.instrument.web.client;
package org.springframework.cloud.sleuth.instrument.web.client.exception;
import java.io.IOException;
import java.util.Collections;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.sleuth.instrument.web.client.feign.issues;
package org.springframework.cloud.sleuth.instrument.web.client.feign.issues.issue307;
import java.util.ArrayList;
import java.util.List;

View File

@@ -17,6 +17,8 @@
package org.springframework.cloud.sleuth.instrument.web.client.feign.issues.issue362;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import org.junit.Before;
@@ -42,7 +44,6 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import feign.Client;
import feign.Logger;
import feign.Response;
import feign.RetryableException;
@@ -62,9 +63,11 @@ import static org.assertj.core.api.BDDAssertions.then;
public class Issue362Tests {
RestTemplate template = new RestTemplate();
@Autowired FeignComponentAsserter feignComponentAsserter;
@Before
public void setup() {
this.feignComponentAsserter.executedComponents.clear();
ExceptionUtils.setFail(true);
}
@@ -88,6 +91,8 @@ public class Issue362Tests {
} catch (Exception e) { }
then(ExceptionUtils.getLastException()).isNull();
then(this.feignComponentAsserter.executedComponents)
.containsEntry(ErrorDecoder.class, true);
}
}
@@ -118,17 +123,20 @@ class Application {
}
@Bean
public Client client() {
return new Client.Default(null, null);
}
public FeignComponentAsserter testHolder() { return new FeignComponentAsserter(); }
}
class FeignComponentAsserter {
Map<Class, Boolean> executedComponents = new ConcurrentHashMap<>();
}
@Configuration
class CustomConfig {
@Bean
public ErrorDecoder errorDecoder() {
return new CustomErrorDecoder();
public ErrorDecoder errorDecoder(FeignComponentAsserter feignComponentAsserter) {
return new CustomErrorDecoder(feignComponentAsserter);
}
@Bean
@@ -138,22 +146,25 @@ class CustomConfig {
public static class CustomErrorDecoder extends ErrorDecoder.Default {
public CustomErrorDecoder() {
private final FeignComponentAsserter feignComponentAsserter;
public CustomErrorDecoder(FeignComponentAsserter feignComponentAsserter) {
this.feignComponentAsserter = feignComponentAsserter;
}
@Override
public Exception decode(String methodKey, Response response) {
this.feignComponentAsserter.executedComponents.put(ErrorDecoder.class, true);
if (response.status() == 409) {
return new RetryableException("Article not Ready", new Date());
} else {
return super.decode(methodKey, response);
}
}
}
}
@FeignClient(value="myFeignClient", url="http://localhost:9998",
@FeignClient(name="myFeignClient", url="http://localhost:9998",
configuration = CustomConfig.class)
interface MyFeignClient {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.sleuth.instrument.web.client.feign;
package org.springframework.cloud.sleuth.instrument.web.client.feign.servererrors;
import java.util.ArrayList;
import java.util.Collections;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.sleuth.instrument.web.client;
package org.springframework.cloud.sleuth.instrument.web.client.integration;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;