From 16ec936e1b7240b5f13e07e9b85169e9b105285f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 19 Jan 2025 22:05:54 +0800 Subject: [PATCH] Merge dev branch --- ...ot.autoconfigure.AutoConfiguration.imports | 3 +- ...viceRegistrationAutoConfigurationTest.java | 5 -- .../autoconfigure/EnableFeignAutoRefresh.java | 2 + ...ignClientAutoRefreshAutoConfiguration.java | 21 +++-- .../autorefresh/AutoRefreshCapability.java | 2 + ...ignClientConfigurationChangedListener.java | 5 +- .../CompositedRequestInterceptor.java | 5 ++ .../spring/cloud/openfeign/BaseClient.java | 2 +- .../spring/cloud/openfeign/BaseTest.java | 19 +++-- .../cloud/openfeign/FeignComponentAssert.java | 19 +++++ .../cloud/openfeign/MockCapability.java | 18 +++++ .../ObservableFeignInvocationHandler.java | 78 +++++++++++++++++++ .../cloud/openfeign/decoder/ADecoder.java | 21 +++++ .../cloud/openfeign/decoder/BDecoder.java | 21 +++++ .../openfeign/decoder/DecoderChangedTest.java | 36 +++++++++ .../decoder/DecoderComponentAssert.java | 21 +++++ .../cloud/openfeign/encoder/AEncoder.java | 1 - .../cloud/openfeign/encoder/BEncoder.java | 1 - .../openfeign/encoder/EncoderChangedTest.java | 12 +++ .../encoder/EncoderComponentAssert.java | 27 +++++++ .../openfeign/errordecoder/AErrorDecoder.java | 1 - .../openfeign/errordecoder/BErrorEncoder.java | 16 ++++ .../errordecoder/ErrorDecoderChangedTest.java | 13 +++- .../ErrorDecoderComponentAssert.java | 22 ++++++ .../querymapencoder/AQueryMapEncoder.java | 1 - .../querymapencoder/BQueryMapEncoder.java | 1 - .../QueryMapEncoderChangedTest.java | 11 +++ .../QueryMapEncoderComponentAssert.java | 22 ++++++ .../ARequestInterceptor.java | 1 - .../BRequestInterceptor.java | 1 - .../RequestInterceptorChangedTest.java | 14 +++- .../RequestInterceptorComponentAssert.java | 38 +++++++++ .../cloud/openfeign/retryer/BRetry.java | 21 +++++ .../openfeign/retryer/RetryerChangedTest.java | 13 +++- .../retryer/RetryerComponentAssert.java | 21 +++++ 35 files changed, 480 insertions(+), 35 deletions(-) create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/FeignComponentAssert.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/MockCapability.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/ObservableFeignInvocationHandler.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/ADecoder.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/BDecoder.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/DecoderChangedTest.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/DecoderComponentAssert.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderComponentAssert.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/BErrorEncoder.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderComponentAssert.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderComponentAssert.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorComponentAssert.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/BRetry.java create mode 100644 microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerComponentAssert.java diff --git a/microsphere-spring-cloud-commons/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/microsphere-spring-cloud-commons/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 7be8d06..55c28f6 100644 --- a/microsphere-spring-cloud-commons/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/microsphere-spring-cloud-commons/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -3,4 +3,5 @@ io.microsphere.spring.cloud.client.service.registry.autoconfigure.ServiceRegistr io.microsphere.spring.cloud.client.service.registry.autoconfigure.WebMvcServiceRegistryAutoConfiguration io.microsphere.spring.cloud.client.service.registry.autoconfigure.WebFluxServiceRegistryAutoConfiguration io.microsphere.spring.cloud.client.service.registry.autoconfigure.SimpleAutoServiceRegistrationAutoConfiguration -io.microsphere.spring.cloud.client.service.registry.actuate.autoconfigure.ServiceRegistrationEndpointAutoConfiguration \ No newline at end of file +io.microsphere.spring.cloud.client.service.registry.actuate.autoconfigure.ServiceRegistrationEndpointAutoConfiguration +io.microsphere.spring.cloud.fault.tolerance.tomcat.autoconfigure.TomcatFaultToleranceAutoConfiguration \ No newline at end of file diff --git a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfigurationTest.java b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfigurationTest.java index 7406277..76f6070 100644 --- a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfigurationTest.java +++ b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfigurationTest.java @@ -5,7 +5,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; @@ -41,9 +40,6 @@ public class SimpleAutoServiceRegistrationAutoConfigurationTest { @Autowired private SimpleAutoServiceRegistration simpleAutoServiceRegistration; - @LocalServerPort - private Integer port; - @Test public void test() { assertEquals("test-service", registration.getServiceId()); @@ -52,7 +48,6 @@ public void test() { assertNotNull(registration.getUri()); assertNotNull(registration.getInstanceId()); assertNotNull(registration.getMetadata()); - assertNotNull(port); } } \ No newline at end of file diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/EnableFeignAutoRefresh.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/EnableFeignAutoRefresh.java index 7433fb0..da5ab51 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/EnableFeignAutoRefresh.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/EnableFeignAutoRefresh.java @@ -4,6 +4,7 @@ import java.lang.annotation.Documented; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -19,6 +20,7 @@ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Documented +@Inherited @Import(EnableFeignAutoRefresh.Marker.class) public @interface EnableFeignAutoRefresh { diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/FeignClientAutoRefreshAutoConfiguration.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/FeignClientAutoRefreshAutoConfiguration.java index 93c5e36..46f2e3d 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/FeignClientAutoRefreshAutoConfiguration.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/FeignClientAutoRefreshAutoConfiguration.java @@ -4,12 +4,13 @@ import io.microsphere.spring.cloud.openfeign.autorefresh.FeignComponentRegistry; import io.microsphere.spring.cloud.openfeign.components.NoOpRequestInterceptor; import org.springframework.beans.factory.BeanFactory; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.cloud.openfeign.FeignBuilderCustomizer; import org.springframework.cloud.openfeign.FeignClientProperties; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.context.event.EventListener; /** * The Auto-Configuration class for {@link EnableFeignAutoRefresh} @@ -20,7 +21,6 @@ * @since 0.0.1 */ @ConditionalOnBean(EnableFeignAutoRefresh.Marker.class) -@AutoConfigureAfter(ConfigurationPropertiesRebinderAutoConfiguration.class) public class FeignClientAutoRefreshAutoConfiguration { @Bean @@ -30,9 +30,12 @@ public FeignBuilderCustomizer addDefaultRequestInterceptorCustomizer() { }; } - @Bean - public FeignClientConfigurationChangedListener feignClientConfigurationChangedListener(FeignComponentRegistry registry) { - return new FeignClientConfigurationChangedListener(registry); + @EventListener(ApplicationReadyEvent.class) + public void onApplicationReadyEvent(ApplicationReadyEvent event) { + /** + * Make sure the FeignClientConfigurationChangedListener is registered after the ConfigurationPropertiesRebinder + */ + registerFeignClientConfigurationChangedListener(event); } @Bean @@ -45,4 +48,10 @@ public FeignClientSpecificationPostProcessor feignClientSpecificationPostProcess return new FeignClientSpecificationPostProcessor(); } + private void registerFeignClientConfigurationChangedListener(ApplicationReadyEvent event) { + ConfigurableApplicationContext context = event.getApplicationContext(); + FeignComponentRegistry feignComponentRegistry = context.getBean(FeignComponentRegistry.class); + context.addApplicationListener(new FeignClientConfigurationChangedListener(feignComponentRegistry)); + } + } diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/AutoRefreshCapability.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/AutoRefreshCapability.java index 0e29d0b..4189159 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/AutoRefreshCapability.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/AutoRefreshCapability.java @@ -28,7 +28,9 @@ public class AutoRefreshCapability implements Capability, ApplicationContextAware { private final FeignComponentRegistry componentRegistry; + private final FeignContext feignContext; + private final FeignClientProperties clientProperties; private String contextId; diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/FeignClientConfigurationChangedListener.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/FeignClientConfigurationChangedListener.java index c4cede8..b75371b 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/FeignClientConfigurationChangedListener.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/FeignClientConfigurationChangedListener.java @@ -24,8 +24,9 @@ public FeignClientConfigurationChangedListener(FeignComponentRegistry registry) @Override public void onApplicationEvent(EnvironmentChangeEvent event) { Map> effectiveClients = resolveChangedClient(event); - effectiveClients.forEach(registry::refresh); - + if (!effectiveClients.isEmpty()) { + effectiveClients.forEach(registry::refresh); + } } protected Map> resolveChangedClient(EnvironmentChangeEvent event) { diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/CompositedRequestInterceptor.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/CompositedRequestInterceptor.java index 4cb3cf9..c4d4065 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/CompositedRequestInterceptor.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/CompositedRequestInterceptor.java @@ -8,6 +8,7 @@ import org.springframework.util.CollectionUtils; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -29,6 +30,10 @@ public CompositedRequestInterceptor(String contextId, BeanFactory beanFactory) { this.contextId = contextId; } + public Set getRequestInterceptors() { + return Collections.unmodifiableSet(set); + } + @Override public void apply(RequestTemplate template) { diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseClient.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseClient.java index 3a4edcf..47de7f4 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseClient.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseClient.java @@ -9,7 +9,7 @@ * @author 韩超 * @since 0.0.1 */ -@FeignClient(contextId = "my-client", name = "my-client") +@FeignClient(contextId = "my-client", name = "my-client", configuration = {MockCapability.class}) public interface BaseClient { @GetMapping("echo") diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseTest.java index 7197e84..5b67141 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseTest.java @@ -5,9 +5,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.cloud.endpoint.event.RefreshEvent; import org.springframework.cloud.openfeign.EnableFeignClients; @@ -31,6 +28,10 @@ @TestPropertySource(properties = { "spring.main.allow-bean-definition-overriding=true", "feign.client.config.default.encoder=io.microsphere.spring.cloud.openfeign.encoder.AEncoder", + "feign.client.config.default.error-decoder=io.microsphere.spring.cloud.openfeign.errordecoder.AErrorDecoder", + "feign.client.config.default.query-map-encoder=io.microsphere.spring.cloud.openfeign.querymapencoder.AQueryMapEncoder", + "feign.client.config.default.retryer=io.microsphere.spring.cloud.openfeign.retryer.ARetry", + "feign.client.config.default.decoder=io.microsphere.spring.cloud.openfeign.decoder.ADecoder", "feign.client.config.default.request-interceptors[0]=io.microsphere.spring.cloud.openfeign.requestInterceptor.ARequestInterceptor", "feign.client.config.default.default-request-headers.app=my-app", "feign.client.config.default.default-query-parameters.sign=my-sign", @@ -38,7 +39,6 @@ @ComponentScan(basePackages = "io.microsphere.spring.cloud.openfeign") @EnableFeignClients(clients = BaseClient.class) @EnableFeignAutoRefresh -@AutoConfigureAfter(ConfigurationPropertiesRebinderAutoConfiguration.class) public abstract class BaseTest { private static final Logger log = LoggerFactory.getLogger(BaseTest.class); @@ -50,7 +50,9 @@ public abstract class BaseTest { private BaseClient client; protected abstract String afterTestComponentConfigKey(); + protected abstract Class beforeTestComponentClass(); protected abstract Class afterTestComponent(); + protected abstract FeignComponentAssert loadFeignComponentAssert(); public void replaceConfig() { final String key = afterTestComponentConfigKey(); @@ -71,20 +73,21 @@ public void replaceConfig() { @Test public void testInternal() { + ObservableFeignInvocationHandler.componentAssert = loadFeignComponentAssert(); + + ObservableFeignInvocationHandler.expectComponentClass = beforeTestComponentClass(); try { this.client.echo("hello", "1.0"); - } catch (Exception ignored) { - } replaceConfig(); + + ObservableFeignInvocationHandler.expectComponentClass = afterTestComponent(); try { this.client.echo("world", "1.0"); } catch (Exception ignored) { } - - } protected void triggerRefreshEvent() { diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/FeignComponentAssert.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/FeignComponentAssert.java new file mode 100644 index 0000000..ad783ae --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/FeignComponentAssert.java @@ -0,0 +1,19 @@ +package io.microsphere.spring.cloud.openfeign; + +import feign.InvocationHandlerFactory; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public abstract class FeignComponentAssert { + + + protected abstract T loadCurrentComponent(InvocationHandlerFactory.MethodHandler methodHandler) throws Exception; + + public boolean expect(InvocationHandlerFactory.MethodHandler methodHandler, Class expectedClass) throws Exception { + T component = loadCurrentComponent(methodHandler); + return expectedClass.equals(component.getClass()); + } + +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/MockCapability.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/MockCapability.java new file mode 100644 index 0000000..53562b7 --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/MockCapability.java @@ -0,0 +1,18 @@ +package io.microsphere.spring.cloud.openfeign; + +import feign.Capability; +import feign.InvocationHandlerFactory; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class MockCapability implements Capability { + + @Override + public InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) { + return ObservableFeignInvocationHandler::new; + } + + +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/ObservableFeignInvocationHandler.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/ObservableFeignInvocationHandler.java new file mode 100644 index 0000000..e5396b5 --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/ObservableFeignInvocationHandler.java @@ -0,0 +1,78 @@ +package io.microsphere.spring.cloud.openfeign; + +import feign.InvocationHandlerFactory; +import feign.Target; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.Assert; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Map; + +import static feign.Util.checkNotNull; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class ObservableFeignInvocationHandler implements InvocationHandler { + + + private static final Logger log = LoggerFactory.getLogger(ObservableFeignInvocationHandler.class); + public static FeignComponentAssert componentAssert; + public static Class expectComponentClass; + + private final Target target; + private final Map dispatch; + + ObservableFeignInvocationHandler(Target target, Map dispatch) { + this.target = checkNotNull(target, "target"); + this.dispatch = checkNotNull(dispatch, "dispatch for %s", target); + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if ("equals".equals(method.getName())) { + try { + Object otherHandler = + args.length > 0 && args[0] != null ? Proxy.getInvocationHandler(args[0]) : null; + return equals(otherHandler); + } catch (IllegalArgumentException e) { + return false; + } + } else if ("hashCode".equals(method.getName())) { + return hashCode(); + } else if ("toString".equals(method.getName())) { + return toString(); + } else if (!dispatch.containsKey(method)) { + throw new UnsupportedOperationException( + String.format("Method \"%s\" should not be called", method.getName())); + } + + InvocationHandlerFactory.MethodHandler methodHandler = dispatch.get(method); + Assert.isTrue(componentAssert.expect(methodHandler, expectComponentClass), "unexpected component"); + log.info("component validation is True"); + return dispatch.get(method).invoke(args); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ObservableFeignInvocationHandler) { + ObservableFeignInvocationHandler other = (ObservableFeignInvocationHandler) obj; + return target.equals(other.target); + } + return false; + } + + @Override + public int hashCode() { + return target.hashCode(); + } + + @Override + public String toString() { + return target.toString(); + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/ADecoder.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/ADecoder.java new file mode 100644 index 0000000..14b8535 --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/ADecoder.java @@ -0,0 +1,21 @@ +package io.microsphere.spring.cloud.openfeign.decoder; + +import feign.FeignException; +import feign.Response; +import feign.codec.DecodeException; +import feign.codec.Decoder; + +import java.io.IOException; +import java.lang.reflect.Type; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class ADecoder implements Decoder { + + @Override + public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException { + return null; + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/BDecoder.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/BDecoder.java new file mode 100644 index 0000000..7762fe7 --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/BDecoder.java @@ -0,0 +1,21 @@ +package io.microsphere.spring.cloud.openfeign.decoder; + +import feign.FeignException; +import feign.Response; +import feign.codec.DecodeException; +import feign.codec.Decoder; + +import java.io.IOException; +import java.lang.reflect.Type; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class BDecoder implements Decoder { + + @Override + public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException { + return null; + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/DecoderChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/DecoderChangedTest.java new file mode 100644 index 0000000..bbbb810 --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/DecoderChangedTest.java @@ -0,0 +1,36 @@ +package io.microsphere.spring.cloud.openfeign.decoder; + +import feign.codec.Decoder; +import io.microsphere.spring.cloud.openfeign.BaseTest; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +/** + * @author 韩超 + * @since 0.0.1 + */ +@SpringBootTest(classes = DecoderChangedTest.class) +@EnableAutoConfiguration +public class DecoderChangedTest extends BaseTest { + + @Override + protected String afterTestComponentConfigKey() { + return "spring.cloud.openfeign.client.config.my-client.decoder"; + } + + @Override + protected Class beforeTestComponentClass() { + return ADecoder.class; + } + + @Override + protected Class afterTestComponent() { + return BDecoder.class; + } + + @Override + protected FeignComponentAssert loadFeignComponentAssert() { + return new DecoderComponentAssert(); + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/DecoderComponentAssert.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/DecoderComponentAssert.java new file mode 100644 index 0000000..1b43f0e --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/DecoderComponentAssert.java @@ -0,0 +1,21 @@ +package io.microsphere.spring.cloud.openfeign.decoder; + +import feign.InvocationHandlerFactory; +import feign.codec.Decoder; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; +import io.microsphere.spring.cloud.openfeign.components.DecoratedDecoder; + +import static io.microsphere.reflect.FieldUtils.getFieldValue; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class DecoderComponentAssert extends FeignComponentAssert { + + @Override + protected Decoder loadCurrentComponent(InvocationHandlerFactory.MethodHandler methodHandler) throws Exception { + DecoratedDecoder decoder = getFieldValue(methodHandler, "decoder"); + return decoder.delegate(); + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/AEncoder.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/AEncoder.java index a9883ba..23abbb8 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/AEncoder.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/AEncoder.java @@ -14,7 +14,6 @@ public class AEncoder implements Encoder { @Override public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException { - System.out.println("AEncoder is working..."); template.body(object.toString()); } } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/BEncoder.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/BEncoder.java index 302c04e..1d3300d 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/BEncoder.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/BEncoder.java @@ -14,7 +14,6 @@ public class BEncoder implements Encoder { @Override public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException { - System.out.println("BEncoder is working..."); template.body(object.toString()); } } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderChangedTest.java index 938ea9f..dcae367 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderChangedTest.java @@ -2,6 +2,7 @@ import feign.codec.Encoder; import io.microsphere.spring.cloud.openfeign.BaseTest; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @@ -13,6 +14,17 @@ @EnableAutoConfiguration public class EncoderChangedTest extends BaseTest { + + @Override + protected Class beforeTestComponentClass() { + return AEncoder.class; + } + + @Override + protected FeignComponentAssert loadFeignComponentAssert() { + return EncoderComponentAssert.INSTANCE; + } + @Override protected String afterTestComponentConfigKey() { return "feign.client.config.my-client.encoder"; diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderComponentAssert.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderComponentAssert.java new file mode 100644 index 0000000..35831ed --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderComponentAssert.java @@ -0,0 +1,27 @@ +package io.microsphere.spring.cloud.openfeign.encoder; + +import feign.InvocationHandlerFactory; +import feign.codec.Encoder; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; +import io.microsphere.spring.cloud.openfeign.components.DecoratedEncoder; + +import static io.microsphere.reflect.FieldUtils.getFieldValue; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class EncoderComponentAssert extends FeignComponentAssert { + + public static final EncoderComponentAssert INSTANCE = new EncoderComponentAssert(); + + private EncoderComponentAssert() { + } + + @Override + protected Encoder loadCurrentComponent(InvocationHandlerFactory.MethodHandler methodHandler) throws Exception { + Object buildTemplateFromArgsValue = getFieldValue(methodHandler, "buildTemplateFromArgs"); + DecoratedEncoder encoder = getFieldValue(buildTemplateFromArgsValue, "encoder"); + return encoder.delegate(); + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/AErrorDecoder.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/AErrorDecoder.java index 7fb72d9..b9a9d2a 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/AErrorDecoder.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/AErrorDecoder.java @@ -15,7 +15,6 @@ public class AErrorDecoder implements ErrorDecoder { @Override public Exception decode(String methodKey, Response response) { - log.trace("Error decoding {}", methodKey); return new IllegalArgumentException(""); } } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/BErrorEncoder.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/BErrorEncoder.java new file mode 100644 index 0000000..4c7bac0 --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/BErrorEncoder.java @@ -0,0 +1,16 @@ +package io.microsphere.spring.cloud.openfeign.errordecoder; + +import feign.Response; +import feign.codec.ErrorDecoder; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class BErrorEncoder implements ErrorDecoder { + + @Override + public Exception decode(String methodKey, Response response) { + return null; + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderChangedTest.java index e431c1f..18b7871 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderChangedTest.java @@ -2,6 +2,7 @@ import feign.codec.ErrorDecoder; import io.microsphere.spring.cloud.openfeign.BaseTest; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @@ -13,6 +14,16 @@ @EnableAutoConfiguration public class ErrorDecoderChangedTest extends BaseTest { + @Override + protected Class beforeTestComponentClass() { + return AErrorDecoder.class; + } + + @Override + protected FeignComponentAssert loadFeignComponentAssert() { + return new ErrorDecoderComponentAssert(); + } + @Override protected String afterTestComponentConfigKey() { return "feign.client.config.my-client.error-decoder"; @@ -20,6 +31,6 @@ protected String afterTestComponentConfigKey() { @Override protected Class afterTestComponent() { - return AErrorDecoder.class; + return BErrorEncoder.class; } } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderComponentAssert.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderComponentAssert.java new file mode 100644 index 0000000..34012de --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderComponentAssert.java @@ -0,0 +1,22 @@ +package io.microsphere.spring.cloud.openfeign.errordecoder; + +import feign.InvocationHandlerFactory; +import feign.codec.ErrorDecoder; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; +import io.microsphere.spring.cloud.openfeign.components.DecoratedErrorDecoder; + +import static io.microsphere.reflect.FieldUtils.getFieldValue; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class ErrorDecoderComponentAssert extends FeignComponentAssert { + + @Override + protected ErrorDecoder loadCurrentComponent(InvocationHandlerFactory.MethodHandler methodHandler) throws Exception { + Object asyncResponseHandler = getFieldValue(methodHandler, "asyncResponseHandler"); + DecoratedErrorDecoder errorDecoder = getFieldValue(asyncResponseHandler, "errorDecoder"); + return errorDecoder.delegate(); + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/AQueryMapEncoder.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/AQueryMapEncoder.java index 4cde8f0..79e20f1 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/AQueryMapEncoder.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/AQueryMapEncoder.java @@ -18,7 +18,6 @@ public class AQueryMapEncoder implements QueryMapEncoder { @Override public Map encode(Object object) { - log.trace("AQueryMapEncoder.encode({})", object); return new HashMap<>(); } } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/BQueryMapEncoder.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/BQueryMapEncoder.java index 0803269..7d271d4 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/BQueryMapEncoder.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/BQueryMapEncoder.java @@ -18,7 +18,6 @@ public class BQueryMapEncoder implements QueryMapEncoder { @Override public Map encode(Object object) { - log.trace("AQueryMapEncoder.encode({})", object); return new HashMap<>(); } } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderChangedTest.java index 69928a6..d95796e 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderChangedTest.java @@ -2,6 +2,7 @@ import feign.QueryMapEncoder; import io.microsphere.spring.cloud.openfeign.BaseTest; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @@ -13,6 +14,16 @@ @EnableAutoConfiguration public class QueryMapEncoderChangedTest extends BaseTest { + @Override + protected Class beforeTestComponentClass() { + return AQueryMapEncoder.class; + } + + @Override + protected FeignComponentAssert loadFeignComponentAssert() { + return new QueryMapEncoderComponentAssert(); + } + @Override protected String afterTestComponentConfigKey() { return "feign.client.config.my-client.query-map-encoder"; diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderComponentAssert.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderComponentAssert.java new file mode 100644 index 0000000..4c5e4cd --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderComponentAssert.java @@ -0,0 +1,22 @@ +package io.microsphere.spring.cloud.openfeign.querymapencoder; + +import feign.InvocationHandlerFactory; +import feign.QueryMapEncoder; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; +import io.microsphere.spring.cloud.openfeign.components.DecoratedQueryMapEncoder; + +import static io.microsphere.reflect.FieldUtils.getFieldValue; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class QueryMapEncoderComponentAssert extends FeignComponentAssert { + + @Override + protected QueryMapEncoder loadCurrentComponent(InvocationHandlerFactory.MethodHandler methodHandler) throws Exception { + Object buildTemplateFromArgsValue = getFieldValue(methodHandler, "buildTemplateFromArgs"); + DecoratedQueryMapEncoder encoder = getFieldValue(buildTemplateFromArgsValue, "queryMapEncoder"); + return encoder.delegate(); + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/ARequestInterceptor.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/ARequestInterceptor.java index 84ffa4d..d7e8fc0 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/ARequestInterceptor.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/ARequestInterceptor.java @@ -11,6 +11,5 @@ public class ARequestInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate template) { - System.out.println(getClass() + ": A is working..."); } } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/BRequestInterceptor.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/BRequestInterceptor.java index 108f58c..b06dd60 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/BRequestInterceptor.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/BRequestInterceptor.java @@ -11,6 +11,5 @@ public class BRequestInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate template) { - System.out.println(getClass() + "B is working..."); } } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorChangedTest.java index 870b94a..58137cb 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorChangedTest.java @@ -2,11 +2,9 @@ import feign.RequestInterceptor; import io.microsphere.spring.cloud.openfeign.BaseTest; -import org.junit.jupiter.api.extension.ExtendWith; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; /** * @author 韩超 @@ -16,6 +14,16 @@ @EnableAutoConfiguration public class RequestInterceptorChangedTest extends BaseTest { + @Override + protected Class beforeTestComponentClass() { + return ARequestInterceptor.class; + } + + @Override + protected FeignComponentAssert loadFeignComponentAssert() { + return new RequestInterceptorComponentAssert(); + } + @Override protected String afterTestComponentConfigKey() { return "feign.client.config.my-client.request-interceptors[0]"; diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorComponentAssert.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorComponentAssert.java new file mode 100644 index 0000000..58d919c --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorComponentAssert.java @@ -0,0 +1,38 @@ +package io.microsphere.spring.cloud.openfeign.requestInterceptor; + +import feign.InvocationHandlerFactory; +import feign.RequestInterceptor; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; +import io.microsphere.spring.cloud.openfeign.components.CompositedRequestInterceptor; + +import java.util.List; + +import static io.microsphere.reflect.FieldUtils.getFieldValue; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class RequestInterceptorComponentAssert extends FeignComponentAssert { + + @Override + protected CompositedRequestInterceptor loadCurrentComponent(InvocationHandlerFactory.MethodHandler methodHandler) throws Exception { + List retryer = getFieldValue(methodHandler, "requestInterceptors"); + for (RequestInterceptor interceptor : retryer) { + if (interceptor instanceof CompositedRequestInterceptor) { + return (CompositedRequestInterceptor) interceptor; + } + } + return null; + } + + @Override + public boolean expect(InvocationHandlerFactory.MethodHandler methodHandler, Class expectedClass) throws Exception { + CompositedRequestInterceptor requestInterceptor = loadCurrentComponent(methodHandler); + for (RequestInterceptor interceptor : requestInterceptor.getRequestInterceptors()) { + if (expectedClass.equals(interceptor.getClass())) + return true; + } + return false; + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/BRetry.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/BRetry.java new file mode 100644 index 0000000..b8ac51c --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/BRetry.java @@ -0,0 +1,21 @@ +package io.microsphere.spring.cloud.openfeign.retryer; + +import feign.RetryableException; +import feign.Retryer; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class BRetry implements Retryer { + + @Override + public void continueOrPropagate(RetryableException e) { + + } + + @Override + public Retryer clone() { + return this; + } +} diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerChangedTest.java index 5c66d25..03aabf1 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerChangedTest.java @@ -2,6 +2,7 @@ import feign.Retryer; import io.microsphere.spring.cloud.openfeign.BaseTest; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @@ -13,6 +14,16 @@ @EnableAutoConfiguration public class RetryerChangedTest extends BaseTest { + @Override + protected Class beforeTestComponentClass() { + return ARetry.class; + } + + @Override + protected FeignComponentAssert loadFeignComponentAssert() { + return new RetryerComponentAssert(); + } + @Override protected String afterTestComponentConfigKey() { return "feign.client.config.my-client.retryer"; @@ -20,6 +31,6 @@ protected String afterTestComponentConfigKey() { @Override protected Class afterTestComponent() { - return ARetry.class; + return BRetry.class; } } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerComponentAssert.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerComponentAssert.java new file mode 100644 index 0000000..4d2b2db --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerComponentAssert.java @@ -0,0 +1,21 @@ +package io.microsphere.spring.cloud.openfeign.retryer; + +import feign.InvocationHandlerFactory; +import feign.Retryer; +import io.microsphere.spring.cloud.openfeign.FeignComponentAssert; +import io.microsphere.spring.cloud.openfeign.components.DecoratedRetryer; + +import static io.microsphere.reflect.FieldUtils.getFieldValue; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class RetryerComponentAssert extends FeignComponentAssert { + + @Override + protected Retryer loadCurrentComponent(InvocationHandlerFactory.MethodHandler methodHandler) throws Exception { + DecoratedRetryer retryer = getFieldValue(methodHandler, "retryer"); + return retryer.delegate(); + } +}