Skip to content

Commit

Permalink
change test suit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurok1 committed Jan 17, 2025
1 parent cbace64 commit 80a834e
Show file tree
Hide file tree
Showing 39 changed files with 560 additions and 115 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.microsphere.spring.cloud.openfeign.autoconfigure;

import io.microsphere.spring.cloud.openfeign.FeignComponentProvider;
import io.microsphere.spring.cloud.openfeign.autorefresh.FeignClientConfigurationChangedListener;
import io.microsphere.spring.cloud.openfeign.autorefresh.FeignComponentRegistry;
import io.microsphere.spring.cloud.openfeign.components.NoOpRequestInterceptor;
Expand All @@ -10,7 +9,6 @@
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.openfeign.FeignBuilderCustomizer;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.FeignClientSpecification;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.EventListener;
Expand Down Expand Up @@ -51,11 +49,6 @@ public FeignClientSpecificationPostProcessor feignClientSpecificationPostProcess
return new FeignClientSpecificationPostProcessor();
}

@Bean
public FeignComponentProvider feignComponentProvider(NamedContextFactory<FeignClientSpecification> contextFactory) {
return new FeignComponentProvider(contextFactory);
}

private void registerFeignClientConfigurationChangedListener(ApplicationReadyEvent event) {
ConfigurableApplicationContext context = event.getApplicationContext();
FeignComponentRegistry feignComponentRegistry = context.getBean(FeignComponentRegistry.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package io.microsphere.spring.cloud.openfeign.autorefresh;

import feign.Capability;
import feign.Contract;
import feign.QueryMapEncoder;
import feign.RequestInterceptor;
import feign.Retryer;
import feign.*;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.codec.ErrorDecoder;
import io.microsphere.spring.cloud.openfeign.FeignComponentProvider;
import io.microsphere.spring.cloud.openfeign.components.DecoratedContract;
import io.microsphere.spring.cloud.openfeign.components.DecoratedDecoder;
import io.microsphere.spring.cloud.openfeign.components.DecoratedEncoder;
import io.microsphere.spring.cloud.openfeign.components.DecoratedErrorDecoder;
import io.microsphere.spring.cloud.openfeign.components.DecoratedFeignComponent;
import io.microsphere.spring.cloud.openfeign.components.DecoratedQueryMapEncoder;
import io.microsphere.spring.cloud.openfeign.components.DecoratedRetryer;
import io.microsphere.spring.cloud.openfeign.components.*;
import org.springframework.beans.BeansException;
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.FeignClientSpecification;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

Expand All @@ -29,15 +20,15 @@ public class AutoRefreshCapability implements Capability, ApplicationContextAwar

private final FeignComponentRegistry componentRegistry;
//private final FeignClientFactory feignClientFactory;
private final FeignComponentProvider componentProvider;
private final NamedContextFactory<FeignClientSpecification> contextFactory;
private final FeignClientProperties clientProperties;

private String contextId;


public AutoRefreshCapability(FeignClientProperties clientProperties, FeignComponentProvider componentProvider, FeignComponentRegistry componentRegistry) {
public AutoRefreshCapability(FeignClientProperties clientProperties, NamedContextFactory<FeignClientSpecification> contextFactory, FeignComponentRegistry componentRegistry) {
this.clientProperties = clientProperties;
this.componentProvider = componentProvider;
this.contextFactory = contextFactory;
this.componentRegistry = componentRegistry;
}

Expand All @@ -53,7 +44,7 @@ public Retryer enrich(Retryer retryer) {
return null;

DecoratedRetryer decoratedRetryer = DecoratedFeignComponent.instantiate(DecoratedRetryer.class, Retryer.class,
contextId, componentProvider, clientProperties, retryer);
contextId, contextFactory, clientProperties, retryer);

this.componentRegistry.register(contextId, decoratedRetryer);
return decoratedRetryer;
Expand All @@ -65,7 +56,7 @@ public Contract enrich(Contract contract) {
return null;

DecoratedContract decoratedContract = DecoratedFeignComponent.instantiate(DecoratedContract.class, Contract.class,
contextId, componentProvider, clientProperties, contract);
contextId, contextFactory, clientProperties, contract);
this.componentRegistry.register(contextId, decoratedContract);
return decoratedContract;
}
Expand All @@ -76,7 +67,7 @@ public Decoder enrich(Decoder decoder) {
return null;

DecoratedDecoder decoratedDecoder = DecoratedFeignComponent.instantiate(DecoratedDecoder.class, Decoder.class,
contextId, componentProvider, clientProperties, decoder);
contextId, contextFactory, clientProperties, decoder);
this.componentRegistry.register(contextId, decoratedDecoder);
return decoratedDecoder;
}
Expand All @@ -87,7 +78,7 @@ public Encoder enrich(Encoder encoder) {
return null;

DecoratedEncoder decoratedEncoder = DecoratedFeignComponent.instantiate(DecoratedEncoder.class, Encoder.class,
contextId, componentProvider, clientProperties, encoder);
contextId, contextFactory, clientProperties, encoder);
this.componentRegistry.register(contextId, decoratedEncoder);
return decoratedEncoder;
}
Expand All @@ -97,7 +88,7 @@ public ErrorDecoder enrich(ErrorDecoder decoder) {
return null;

DecoratedErrorDecoder decoratedErrorDecoder = DecoratedFeignComponent.instantiate(DecoratedErrorDecoder.class, ErrorDecoder.class,
contextId, componentProvider, clientProperties, decoder);
contextId, contextFactory, clientProperties, decoder);
this.componentRegistry.register(contextId, decoratedErrorDecoder);
return decoratedErrorDecoder;
}
Expand All @@ -113,7 +104,7 @@ public QueryMapEncoder enrich(QueryMapEncoder queryMapEncoder) {
return null;

DecoratedQueryMapEncoder decoratedQueryMapEncoder = DecoratedFeignComponent.instantiate(DecoratedQueryMapEncoder.class, QueryMapEncoder.class,
contextId, componentProvider, clientProperties, queryMapEncoder);
contextId, contextFactory, clientProperties, queryMapEncoder);

this.componentRegistry.register(contextId, decoratedQueryMapEncoder);
return decoratedQueryMapEncoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* @author <a href="mailto:[email protected]">韩超</a>
Expand All @@ -29,6 +25,10 @@ public CompositedRequestInterceptor(String contextId, BeanFactory beanFactory) {
this.contextId = contextId;
}

public Set<RequestInterceptor> getRequestInterceptors() {
return Collections.unmodifiableSet(set);
}


@Override
public void apply(RequestTemplate template) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import feign.Contract;
import feign.MethodMetadata;
import io.microsphere.spring.cloud.openfeign.FeignComponentProvider;
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.FeignClientSpecification;

import java.util.List;

Expand All @@ -13,8 +14,8 @@
*/
public class DecoratedContract extends DecoratedFeignComponent<Contract> implements Contract {

public DecoratedContract(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, Contract delegate) {
super(contextId, feignComponentProvider, clientProperties, delegate);
public DecoratedContract(String contextId, NamedContextFactory<FeignClientSpecification> contextFactory, FeignClientProperties clientProperties, Contract delegate) {
super(contextId, contextFactory, clientProperties, delegate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import feign.Response;
import feign.codec.DecodeException;
import feign.codec.Decoder;
import io.microsphere.spring.cloud.openfeign.FeignComponentProvider;
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.FeignClientSpecification;

import java.io.IOException;
import java.lang.reflect.Type;
Expand All @@ -16,8 +17,8 @@
*/
public class DecoratedDecoder extends DecoratedFeignComponent<Decoder> implements Decoder {

public DecoratedDecoder(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, Decoder delegate) {
super(contextId, feignComponentProvider, clientProperties, delegate);
public DecoratedDecoder(String contextId, NamedContextFactory<FeignClientSpecification> contextFactory, FeignClientProperties clientProperties, Decoder delegate) {
super(contextId, contextFactory, clientProperties, delegate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import feign.RequestTemplate;
import feign.codec.EncodeException;
import feign.codec.Encoder;
import io.microsphere.spring.cloud.openfeign.FeignComponentProvider;
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.FeignClientSpecification;

import java.lang.reflect.Type;

Expand All @@ -14,8 +15,8 @@
*/
public class DecoratedEncoder extends DecoratedFeignComponent<Encoder> implements Encoder {

public DecoratedEncoder(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, Encoder delegate) {
super(contextId, feignComponentProvider, clientProperties, delegate);
public DecoratedEncoder(String contextId, NamedContextFactory<FeignClientSpecification> contextFactory, FeignClientProperties clientProperties, Encoder delegate) {
super(contextId, contextFactory, clientProperties, delegate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import feign.Response;
import feign.codec.ErrorDecoder;
import io.microsphere.spring.cloud.openfeign.FeignComponentProvider;
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.FeignClientSpecification;

/**
* @author <a href="mailto:[email protected]">韩超</a>
* @since 0.0.1
*/
public class DecoratedErrorDecoder extends DecoratedFeignComponent<ErrorDecoder> implements ErrorDecoder {

public DecoratedErrorDecoder(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, ErrorDecoder delegate) {
super(contextId, feignComponentProvider, clientProperties, delegate);
public DecoratedErrorDecoder(String contextId, NamedContextFactory<FeignClientSpecification> contextFactory, FeignClientProperties clientProperties, ErrorDecoder delegate) {
super(contextId, contextFactory, clientProperties, delegate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.microsphere.spring.cloud.openfeign.components;

import io.microsphere.spring.cloud.openfeign.FeignComponentProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.FeignClientSpecification;
import org.springframework.lang.NonNull;

import java.lang.reflect.Constructor;
Expand All @@ -20,7 +21,7 @@ public abstract class DecoratedFeignComponent<T> implements Refreshable {
private final Logger log = LoggerFactory.getLogger(getClass());

//private final FeignClientFactory feignClientFactory;
private final FeignComponentProvider componentProvider;
private final NamedContextFactory<FeignClientSpecification> contextFactory;
private final String contextId;

private final FeignClientProperties clientProperties;
Expand All @@ -33,9 +34,9 @@ public abstract class DecoratedFeignComponent<T> implements Refreshable {
private final ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
private final ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();

public DecoratedFeignComponent(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, T delegate) {
public DecoratedFeignComponent(String contextId, NamedContextFactory<FeignClientSpecification> contextFactory, FeignClientProperties clientProperties, T delegate) {
this.contextId = contextId;
this.componentProvider = feignComponentProvider;
this.contextFactory = contextFactory;
this.clientProperties = clientProperties;
this.delegate = delegate;
}
Expand All @@ -53,9 +54,12 @@ public T delegate() {
}

@NonNull
public FeignComponentProvider getFeignComponentProvider() {
return this.componentProvider;
};
public <T> T loadInstanceFromContextFactory(String contextId, Class<T> componentType) {
T component = this.contextFactory.getInstance(contextId, componentType);
if (component == null)
return this.contextFactory.getParent().getAutowireCapableBeanFactory().createBean(componentType);
return component;
}

@NonNull
public String contextId() {
Expand Down Expand Up @@ -84,9 +88,7 @@ protected T loadInstance() {
String contextId = contextId();
writeLock.lock();
try {
T component = getFeignComponentProvider().getInstance(contextId, componentType);
if (component == null)
component = BeanUtils.instantiateClass(componentType);
T component = loadInstanceFromContextFactory(contextId, componentType);
this.delegate = component;
return component;
} catch (Throwable ex) {
Expand All @@ -113,10 +115,10 @@ public String toString() {
}

public static <W extends DecoratedFeignComponent<T>, T> W instantiate(Class<W> decoratedClass, Class<T> componentClass,
String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, T delegate) {
String contextId, NamedContextFactory<FeignClientSpecification> contextFactory, FeignClientProperties clientProperties, T delegate) {
try {
Constructor<W> constructor = decoratedClass.getConstructor(String.class, FeignComponentProvider.class, FeignClientProperties.class, componentClass);
return BeanUtils.instantiateClass(constructor, contextId, feignComponentProvider, clientProperties, delegate);
Constructor<W> constructor = decoratedClass.getConstructor(String.class, NamedContextFactory.class, FeignClientProperties.class, componentClass);
return BeanUtils.instantiateClass(constructor, contextId, contextFactory, clientProperties, delegate);
} catch (NoSuchMethodException noSuchMethodException) {
throw new BeanInstantiationException(decoratedClass, noSuchMethodException.getLocalizedMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import feign.QueryMapEncoder;
import io.microsphere.logging.Logger;
import io.microsphere.spring.cloud.openfeign.FeignComponentProvider;
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.FeignClientSpecification;

import java.lang.invoke.MethodHandle;
import java.util.Map;
Expand All @@ -23,8 +24,8 @@ public class DecoratedQueryMapEncoder extends DecoratedFeignComponent<QueryMapEn

private static final MethodHandle getQueryMapEncoderMethodHandle = findVirtual(FeignClientProperties.FeignClientConfiguration.class, getQueryMapEncoderMethodName);

public DecoratedQueryMapEncoder(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, QueryMapEncoder delegate) {
super(contextId, feignComponentProvider, clientProperties, delegate);
public DecoratedQueryMapEncoder(String contextId, NamedContextFactory<FeignClientSpecification> contextFactory, FeignClientProperties clientProperties, QueryMapEncoder delegate) {
super(contextId, contextFactory, clientProperties, delegate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import feign.RetryableException;
import feign.Retryer;
import io.microsphere.spring.cloud.openfeign.FeignComponentProvider;
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.FeignClientSpecification;

/**
* @author <a href="mailto:[email protected]">韩超</a>
* @since 0.0.1
*/
public class DecoratedRetryer extends DecoratedFeignComponent<Retryer> implements Retryer {

public DecoratedRetryer(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, Retryer delegate) {
super(contextId, feignComponentProvider, clientProperties, delegate);
public DecoratedRetryer(String contextId, NamedContextFactory<FeignClientSpecification> contextFactory, FeignClientProperties clientProperties, Retryer delegate) {
super(contextId, contextFactory, clientProperties, delegate);
}

@Override
Expand Down
Loading

0 comments on commit 80a834e

Please sign in to comment.