Bumping versions
This commit is contained in:
@@ -95,8 +95,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@Conditional(ZonePreferenceConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier zonePreferenceDiscoveryClientServiceInstanceListSupplier(
|
||||
ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withDiscoveryClient().withCaching().withZonePreference()
|
||||
.build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withDiscoveryClient()
|
||||
.withCaching()
|
||||
.withZonePreference()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -121,8 +124,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@Conditional(RequestBasedStickySessionConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier requestBasedStickySessionDiscoveryClientServiceInstanceListSupplier(
|
||||
ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withDiscoveryClient().withCaching()
|
||||
.withRequestBasedStickySession().build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withDiscoveryClient()
|
||||
.withCaching()
|
||||
.withRequestBasedStickySession()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -131,8 +137,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@Conditional(SameInstancePreferenceConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier sameInstancePreferenceServiceInstanceListSupplier(
|
||||
ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withDiscoveryClient().withCaching()
|
||||
.withSameInstancePreference().build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withDiscoveryClient()
|
||||
.withCaching()
|
||||
.withSameInstancePreference()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -140,8 +149,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
@Conditional(WeightedConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier weightedServiceInstanceListSupplier(ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withDiscoveryClient().withCaching().withWeighted()
|
||||
.build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withDiscoveryClient()
|
||||
.withCaching()
|
||||
.withWeighted()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -149,8 +161,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
@Conditional(SubsetConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier subsetServiceInstanceListSupplier(ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withDiscoveryClient().withSubset().withCaching()
|
||||
.build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withDiscoveryClient()
|
||||
.withSubset()
|
||||
.withCaching()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -175,8 +190,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@Conditional(ZonePreferenceConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier zonePreferenceDiscoveryClientServiceInstanceListSupplier(
|
||||
ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withCaching()
|
||||
.withZonePreference().build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withBlockingDiscoveryClient()
|
||||
.withCaching()
|
||||
.withZonePreference()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -185,8 +203,10 @@ public class LoadBalancerClientConfiguration {
|
||||
@Conditional(HealthCheckConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier healthCheckDiscoveryClientServiceInstanceListSupplier(
|
||||
ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withBlockingHealthChecks()
|
||||
.build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withBlockingDiscoveryClient()
|
||||
.withBlockingHealthChecks()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -195,8 +215,10 @@ public class LoadBalancerClientConfiguration {
|
||||
@Conditional(HealthCheckConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier healthCheckRestClientDiscoveryClientServiceInstanceListSupplier(
|
||||
ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient()
|
||||
.withBlockingRestClientHealthChecks().build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withBlockingDiscoveryClient()
|
||||
.withBlockingRestClientHealthChecks()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -205,8 +227,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@Conditional(RequestBasedStickySessionConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier requestBasedStickySessionDiscoveryClientServiceInstanceListSupplier(
|
||||
ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withCaching()
|
||||
.withRequestBasedStickySession().build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withBlockingDiscoveryClient()
|
||||
.withCaching()
|
||||
.withRequestBasedStickySession()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -215,8 +240,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@Conditional(SameInstancePreferenceConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier sameInstancePreferenceServiceInstanceListSupplier(
|
||||
ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withCaching()
|
||||
.withSameInstancePreference().build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withBlockingDiscoveryClient()
|
||||
.withCaching()
|
||||
.withSameInstancePreference()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -224,8 +252,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
@Conditional(WeightedConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier weightedServiceInstanceListSupplier(ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withCaching().withWeighted()
|
||||
.build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withBlockingDiscoveryClient()
|
||||
.withCaching()
|
||||
.withWeighted()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -233,8 +264,11 @@ public class LoadBalancerClientConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
@Conditional(SubsetConfigurationCondition.class)
|
||||
public ServiceInstanceListSupplier subsetServiceInstanceListSupplier(ConfigurableApplicationContext context) {
|
||||
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withSubset().withCaching()
|
||||
.build(context);
|
||||
return ServiceInstanceListSupplier.builder()
|
||||
.withBlockingDiscoveryClient()
|
||||
.withSubset()
|
||||
.withCaching()
|
||||
.build(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class LoadBalancerClientConfigurationRegistrar implements ImportBeanDefin
|
||||
private static void registerClientConfiguration(BeanDefinitionRegistry registry, Object name,
|
||||
Object configuration) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(LoadBalancerClientSpecification.class);
|
||||
.genericBeanDefinition(LoadBalancerClientSpecification.class);
|
||||
builder.addConstructorArgValue(name);
|
||||
builder.addConstructorArgValue(configuration);
|
||||
registry.registerBeanDefinition(name + ".LoadBalancerClientSpecification", builder.getBeanDefinition());
|
||||
|
||||
@@ -74,8 +74,8 @@ public class LoadBalancerChildContextInitializer implements BeanRegistrationAotP
|
||||
contextIds.addAll(getContextIdsFromConfig());
|
||||
contextIds.addAll(getEagerLoadContextIds());
|
||||
Map<String, GenericApplicationContext> childContextAotContributions = contextIds.stream()
|
||||
.map(contextId -> Map.entry(contextId, buildChildContext(contextId)))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
.map(contextId -> Map.entry(contextId, buildChildContext(contextId)))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
return new AotContribution(childContextAotContributions);
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ public class LoadBalancerChildContextInitializer implements BeanRegistrationAotP
|
||||
|
||||
private Set<String> getEagerLoadContextIds() {
|
||||
return Binder.get(applicationContext.getEnvironment())
|
||||
.bind("spring.cloud.loadbalancer.eager-load.clients", Bindable.setOf(String.class))
|
||||
.orElse(Collections.emptySet());
|
||||
.bind("spring.cloud.loadbalancer.eager-load.clients", Bindable.setOf(String.class))
|
||||
.orElse(Collections.emptySet());
|
||||
}
|
||||
|
||||
private GenericApplicationContext buildChildContext(String contextId) {
|
||||
@@ -101,9 +101,11 @@ public class LoadBalancerChildContextInitializer implements BeanRegistrationAotP
|
||||
private final Map<String, GenericApplicationContext> childContexts;
|
||||
|
||||
AotContribution(Map<String, GenericApplicationContext> childContexts) {
|
||||
this.childContexts = childContexts.entrySet().stream().filter(entry -> entry.getValue() != null)
|
||||
.map(entry -> Map.entry(entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
this.childContexts = childContexts.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> entry.getValue() != null)
|
||||
.map(entry -> Map.entry(entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,22 +115,22 @@ public class LoadBalancerChildContextInitializer implements BeanRegistrationAotP
|
||||
name = name.replaceAll("[-]", "_");
|
||||
GenerationContext childGenerationContext = generationContext.withName(name);
|
||||
ClassName initializerClassName = new ApplicationContextAotGenerator()
|
||||
.processAheadOfTime(entry.getValue(), childGenerationContext);
|
||||
.processAheadOfTime(entry.getValue(), childGenerationContext);
|
||||
return Map.entry(entry.getKey(), initializerClassName);
|
||||
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
GeneratedMethod postProcessorMethod = beanRegistrationCode.getMethods().add("addChildContextInitializer",
|
||||
method -> {
|
||||
method.addJavadoc("Use AOT child context management initialization")
|
||||
.addModifiers(Modifier.PRIVATE, Modifier.STATIC)
|
||||
.addParameter(RegisteredBean.class, "registeredBean")
|
||||
.addParameter(LoadBalancerClientFactory.class, "instance")
|
||||
.returns(LoadBalancerClientFactory.class)
|
||||
.addStatement("$T<String, Object> initializers = new $T<>()", Map.class, HashMap.class);
|
||||
generatedInitializerClassNames.keySet()
|
||||
.forEach(contextId -> method.addStatement("initializers.put($S, new $L())", contextId,
|
||||
generatedInitializerClassNames.get(contextId)));
|
||||
method.addStatement("return instance.withApplicationContextInitializers(initializers)");
|
||||
});
|
||||
GeneratedMethod postProcessorMethod = beanRegistrationCode.getMethods()
|
||||
.add("addChildContextInitializer", method -> {
|
||||
method.addJavadoc("Use AOT child context management initialization")
|
||||
.addModifiers(Modifier.PRIVATE, Modifier.STATIC)
|
||||
.addParameter(RegisteredBean.class, "registeredBean")
|
||||
.addParameter(LoadBalancerClientFactory.class, "instance")
|
||||
.returns(LoadBalancerClientFactory.class)
|
||||
.addStatement("$T<String, Object> initializers = new $T<>()", Map.class, HashMap.class);
|
||||
generatedInitializerClassNames.keySet()
|
||||
.forEach(contextId -> method.addStatement("initializers.put($S, new $L())", contextId,
|
||||
generatedInitializerClassNames.get(contextId)));
|
||||
method.addStatement("return instance.withApplicationContextInitializers(initializers)");
|
||||
});
|
||||
beanRegistrationCode.addInstancePostProcessor(postProcessorMethod.toMethodReference());
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ public class BlockingLoadBalancerClient implements LoadBalancerClient {
|
||||
supportedLifecycleProcessors.forEach(lifecycle -> lifecycle.onStart(lbRequest));
|
||||
ServiceInstance serviceInstance = choose(serviceId, lbRequest);
|
||||
if (serviceInstance == null) {
|
||||
supportedLifecycleProcessors.forEach(lifecycle -> lifecycle.onComplete(
|
||||
new CompletionContext<>(CompletionContext.Status.DISCARD, lbRequest, new EmptyResponse())));
|
||||
supportedLifecycleProcessors.forEach(lifecycle -> lifecycle
|
||||
.onComplete(new CompletionContext<>(CompletionContext.Status.DISCARD, lbRequest, new EmptyResponse())));
|
||||
throw new IllegalStateException("No instances available for " + serviceId);
|
||||
}
|
||||
return execute(serviceId, serviceInstance, lbRequest);
|
||||
@@ -101,13 +101,13 @@ public class BlockingLoadBalancerClient implements LoadBalancerClient {
|
||||
Set<LoadBalancerLifecycle> supportedLifecycleProcessors = getSupportedLifecycleProcessors(serviceId);
|
||||
Request lbRequest = request instanceof Request ? (Request) request : new DefaultRequest<>();
|
||||
supportedLifecycleProcessors
|
||||
.forEach(lifecycle -> lifecycle.onStartRequest(lbRequest, new DefaultResponse(serviceInstance)));
|
||||
.forEach(lifecycle -> lifecycle.onStartRequest(lbRequest, new DefaultResponse(serviceInstance)));
|
||||
try {
|
||||
T response = request.apply(serviceInstance);
|
||||
Object clientResponse = getClientResponse(response);
|
||||
supportedLifecycleProcessors
|
||||
.forEach(lifecycle -> lifecycle.onComplete(new CompletionContext<>(CompletionContext.Status.SUCCESS,
|
||||
lbRequest, defaultResponse, clientResponse)));
|
||||
.forEach(lifecycle -> lifecycle.onComplete(new CompletionContext<>(CompletionContext.Status.SUCCESS,
|
||||
lbRequest, defaultResponse, clientResponse)));
|
||||
return response;
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
|
||||
@@ -97,8 +97,10 @@ public class BlockingLoadBalancedRetryPolicy implements LoadBalancedRetryPolicy
|
||||
if (properties.getRetry().isRetryOnAllExceptions()) {
|
||||
return true;
|
||||
}
|
||||
return properties.getRetry().getRetryableExceptions().stream()
|
||||
.anyMatch(exception -> exception.isInstance(throwable) || exception.isInstance(throwable.getCause()));
|
||||
return properties.getRetry()
|
||||
.getRetryableExceptions()
|
||||
.stream()
|
||||
.anyMatch(exception -> exception.isInstance(throwable) || exception.isInstance(throwable.getCause()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,8 +41,10 @@ public class CaffeineBasedLoadBalancerCacheManager extends CaffeineCacheManager
|
||||
setCacheSpecification(properties.getCaffeine().getSpec());
|
||||
}
|
||||
else {
|
||||
setCaffeine(Caffeine.newBuilder().initialCapacity(properties.getCapacity())
|
||||
.expireAfterWrite(properties.getTtl()).softValues());
|
||||
setCaffeine(Caffeine.newBuilder()
|
||||
.initialCapacity(properties.getCapacity())
|
||||
.expireAfterWrite(properties.getTtl())
|
||||
.softValues());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class DefaultLoadBalancerCacheManager implements LoadBalancerCacheManager
|
||||
public DefaultLoadBalancerCacheManager(LoadBalancerCacheProperties loadBalancerCacheProperties,
|
||||
String... cacheNames) {
|
||||
cacheMap.putAll(createCaches(cacheNames, loadBalancerCacheProperties).stream()
|
||||
.collect(Collectors.toMap(DefaultLoadBalancerCache::getName, cache -> cache)));
|
||||
.collect(Collectors.toMap(DefaultLoadBalancerCache::getName, cache -> cache)));
|
||||
}
|
||||
|
||||
public DefaultLoadBalancerCacheManager(LoadBalancerCacheProperties loadBalancerCacheProperties) {
|
||||
@@ -63,12 +63,13 @@ public class DefaultLoadBalancerCacheManager implements LoadBalancerCacheManager
|
||||
|
||||
private Set<DefaultLoadBalancerCache> createCaches(String[] cacheNames,
|
||||
LoadBalancerCacheProperties loadBalancerCacheProperties) {
|
||||
return Arrays.stream(cacheNames).distinct()
|
||||
.map(name -> new DefaultLoadBalancerCache(name,
|
||||
new ConcurrentHashMapWithTimedEviction<>(loadBalancerCacheProperties.getCapacity(),
|
||||
new DelayedTaskEvictionScheduler<>(aScheduledDaemonThreadExecutor())),
|
||||
loadBalancerCacheProperties.getTtl().toMillis(), false))
|
||||
.collect(Collectors.toSet());
|
||||
return Arrays.stream(cacheNames)
|
||||
.distinct()
|
||||
.map(name -> new DefaultLoadBalancerCache(name,
|
||||
new ConcurrentHashMapWithTimedEviction<>(loadBalancerCacheProperties.getCapacity(),
|
||||
new DelayedTaskEvictionScheduler<>(aScheduledDaemonThreadExecutor())),
|
||||
loadBalancerCacheProperties.getTtl().toMillis(), false))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private ScheduledExecutorService aScheduledDaemonThreadExecutor() {
|
||||
|
||||
@@ -179,21 +179,21 @@ class CaffeineHints implements RuntimeHintsRegistrar {
|
||||
return;
|
||||
}
|
||||
hints.reflection()
|
||||
.registerType(TypeReference.of(Caffeine.class),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.registerType(TypeReference.of("com.github.benmanes.caffeine.cache.BoundedLocalCache"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.registerType(TypeReference.of("com.github.benmanes.caffeine.cache.LocalCacheFactory"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.registerType(TypeReference.of("com.github.benmanes.caffeine.cache.Node"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
|
||||
getCaffeineSubtypes().forEach(cacheType -> hints.reflection().registerType(TypeReference.of(cacheType),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS)));
|
||||
.registerType(TypeReference.of(Caffeine.class),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.registerType(TypeReference.of("com.github.benmanes.caffeine.cache.BoundedLocalCache"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.registerType(TypeReference.of("com.github.benmanes.caffeine.cache.LocalCacheFactory"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.registerType(TypeReference.of("com.github.benmanes.caffeine.cache.Node"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
|
||||
getCaffeineSubtypes().forEach(cacheType -> hints.reflection()
|
||||
.registerType(TypeReference.of(cacheType), hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS)));
|
||||
}
|
||||
|
||||
private Set<String> getCaffeineSubtypes() {
|
||||
@@ -205,8 +205,12 @@ class CaffeineHints implements RuntimeHintsRegistrar {
|
||||
catch (ClassNotFoundException e) {
|
||||
LOG.warn("Could not get class for name: " + CAFFEINE_BOUNDED_LOCAL_CACHE_CLASS_NAME);
|
||||
}
|
||||
return provider.findCandidateComponents(CAFFEINE_CACHE_BASE_PACKAGE).stream().filter(Objects::nonNull)
|
||||
.map(BeanDefinition::getBeanClassName).filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
return provider.findCandidateComponents(CAFFEINE_CACHE_BASE_PACKAGE)
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(BeanDefinition::getBeanClassName)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,18 +66,19 @@ public class CachingServiceInstanceListSupplier extends DelegatingServiceInstanc
|
||||
return Mono.empty();
|
||||
}
|
||||
return Flux.just(list).materialize().collectList();
|
||||
}, delegate.getServiceId()).onCacheMissResume(delegate.get().take(1))
|
||||
.andWriteWith((key, signals) -> Flux.fromIterable(signals).dematerialize().doOnNext(instances -> {
|
||||
Cache cache = cacheManager.getCache(SERVICE_INSTANCE_CACHE_NAME);
|
||||
if (cache == null) {
|
||||
if (log.isErrorEnabled()) {
|
||||
log.error("Unable to find cache for writing: " + SERVICE_INSTANCE_CACHE_NAME);
|
||||
}
|
||||
}, delegate.getServiceId())
|
||||
.onCacheMissResume(delegate.get().take(1))
|
||||
.andWriteWith((key, signals) -> Flux.fromIterable(signals).dematerialize().doOnNext(instances -> {
|
||||
Cache cache = cacheManager.getCache(SERVICE_INSTANCE_CACHE_NAME);
|
||||
if (cache == null) {
|
||||
if (log.isErrorEnabled()) {
|
||||
log.error("Unable to find cache for writing: " + SERVICE_INSTANCE_CACHE_NAME);
|
||||
}
|
||||
else {
|
||||
cache.put(key, instances);
|
||||
}
|
||||
}).then());
|
||||
}
|
||||
else {
|
||||
cache.put(key, instances);
|
||||
}
|
||||
}).then());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -62,26 +62,27 @@ public class DiscoveryClientServiceInstanceListSupplier implements ServiceInstan
|
||||
this.serviceId = environment.getProperty(PROPERTY_NAME);
|
||||
resolveTimeout(environment);
|
||||
this.serviceInstances = Flux.defer(() -> Mono.fromCallable(() -> delegate.getInstances(serviceId)))
|
||||
.timeout(timeout, Flux.defer(() -> {
|
||||
logTimeout();
|
||||
return Flux.just(new ArrayList<>());
|
||||
}), Schedulers.boundedElastic()).onErrorResume(error -> {
|
||||
logException(error);
|
||||
return Flux.just(new ArrayList<>());
|
||||
});
|
||||
.timeout(timeout, Flux.defer(() -> {
|
||||
logTimeout();
|
||||
return Flux.just(new ArrayList<>());
|
||||
}), Schedulers.boundedElastic())
|
||||
.onErrorResume(error -> {
|
||||
logException(error);
|
||||
return Flux.just(new ArrayList<>());
|
||||
});
|
||||
}
|
||||
|
||||
public DiscoveryClientServiceInstanceListSupplier(ReactiveDiscoveryClient delegate, Environment environment) {
|
||||
this.serviceId = environment.getProperty(PROPERTY_NAME);
|
||||
resolveTimeout(environment);
|
||||
this.serviceInstances = Flux
|
||||
.defer(() -> delegate.getInstances(serviceId).collectList().flux().timeout(timeout, Flux.defer(() -> {
|
||||
logTimeout();
|
||||
return Flux.just(new ArrayList<>());
|
||||
})).onErrorResume(error -> {
|
||||
logException(error);
|
||||
return Flux.just(new ArrayList<>());
|
||||
}));
|
||||
.defer(() -> delegate.getInstances(serviceId).collectList().flux().timeout(timeout, Flux.defer(() -> {
|
||||
logTimeout();
|
||||
return Flux.just(new ArrayList<>());
|
||||
})).onErrorResume(error -> {
|
||||
logException(error);
|
||||
return Flux.just(new ArrayList<>());
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,12 +68,14 @@ public class HealthCheckServiceInstanceListSupplier extends DelegatingServiceIns
|
||||
defaultHealthCheckPath = healthCheck.getPath().getOrDefault("default", "/actuator/health");
|
||||
this.aliveFunction = aliveFunction;
|
||||
Repeat<Object> aliveInstancesReplayRepeat = Repeat
|
||||
.onlyIf(repeatContext -> this.healthCheck.getRefetchInstances())
|
||||
.fixedBackoff(healthCheck.getRefetchInstancesInterval());
|
||||
Flux<List<ServiceInstance>> aliveInstancesFlux = Flux.defer(delegate).repeatWhen(aliveInstancesReplayRepeat)
|
||||
.switchMap(serviceInstances -> healthCheckFlux(serviceInstances).map(alive -> List.copyOf(alive)));
|
||||
aliveInstancesReplay = aliveInstancesFlux.delaySubscription(healthCheck.getInitialDelay()).replay(1)
|
||||
.refCount(1);
|
||||
.onlyIf(repeatContext -> this.healthCheck.getRefetchInstances())
|
||||
.fixedBackoff(healthCheck.getRefetchInstancesInterval());
|
||||
Flux<List<ServiceInstance>> aliveInstancesFlux = Flux.defer(delegate)
|
||||
.repeatWhen(aliveInstancesReplayRepeat)
|
||||
.switchMap(serviceInstances -> healthCheckFlux(serviceInstances).map(alive -> List.copyOf(alive)));
|
||||
aliveInstancesReplay = aliveInstancesFlux.delaySubscription(healthCheck.getInitialDelay())
|
||||
.replay(1)
|
||||
.refCount(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +89,7 @@ public class HealthCheckServiceInstanceListSupplier extends DelegatingServiceIns
|
||||
|
||||
protected Flux<List<ServiceInstance>> healthCheckFlux(List<ServiceInstance> instances) {
|
||||
Repeat<Object> healthCheckFluxRepeat = Repeat.onlyIf(repeatContext -> healthCheck.getRepeatHealthCheck())
|
||||
.fixedBackoff(healthCheck.getInterval());
|
||||
.fixedBackoff(healthCheck.getInterval());
|
||||
return Flux.defer(() -> {
|
||||
List<Mono<ServiceInstance>> checks = new ArrayList<>(instances.size());
|
||||
for (ServiceInstance instance : instances) {
|
||||
|
||||
@@ -59,9 +59,10 @@ public class RandomLoadBalancer implements ReactorServiceInstanceLoadBalancer {
|
||||
@Override
|
||||
public Mono<Response<ServiceInstance>> choose(Request request) {
|
||||
ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider
|
||||
.getIfAvailable(NoopServiceInstanceListSupplier::new);
|
||||
return supplier.get(request).next()
|
||||
.map(serviceInstances -> processInstanceResponse(supplier, serviceInstances));
|
||||
.getIfAvailable(NoopServiceInstanceListSupplier::new);
|
||||
return supplier.get(request)
|
||||
.next()
|
||||
.map(serviceInstances -> processInstanceResponse(supplier, serviceInstances));
|
||||
}
|
||||
|
||||
private Response<ServiceInstance> processInstanceResponse(ServiceInstanceListSupplier supplier,
|
||||
|
||||
@@ -78,9 +78,10 @@ public class RoundRobinLoadBalancer implements ReactorServiceInstanceLoadBalance
|
||||
// src/main/java/netflix/ocelli/loadbalancer/RoundRobinLoadBalancer.java
|
||||
public Mono<Response<ServiceInstance>> choose(Request request) {
|
||||
ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider
|
||||
.getIfAvailable(NoopServiceInstanceListSupplier::new);
|
||||
return supplier.get(request).next()
|
||||
.map(serviceInstances -> processInstanceResponse(supplier, serviceInstances));
|
||||
.getIfAvailable(NoopServiceInstanceListSupplier::new);
|
||||
return supplier.get(request)
|
||||
.next()
|
||||
.map(serviceInstances -> processInstanceResponse(supplier, serviceInstances));
|
||||
}
|
||||
|
||||
private Response<ServiceInstance> processInstanceResponse(ServiceInstanceListSupplier supplier,
|
||||
|
||||
@@ -52,7 +52,7 @@ public class SameInstancePreferenceServiceInstanceListSupplier extends Delegatin
|
||||
ReactiveLoadBalancer.Factory<ServiceInstance> loadBalancerClientFactory) {
|
||||
super(delegate);
|
||||
callGetWithRequestOnDelegates = loadBalancerClientFactory.getProperties(getServiceId())
|
||||
.isCallGetWithRequestOnDelegates();
|
||||
.isCallGetWithRequestOnDelegates();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -120,7 +120,7 @@ public final class ServiceInstanceListSupplierBuilder {
|
||||
public ServiceInstanceListSupplierBuilder withWeighted() {
|
||||
DelegateCreator creator = (context, delegate) -> {
|
||||
ReactiveLoadBalancer.Factory<ServiceInstance> loadBalancerClientFactory = context
|
||||
.getBean(LoadBalancerClientFactory.class);
|
||||
.getBean(LoadBalancerClientFactory.class);
|
||||
return new WeightedServiceInstanceListSupplier(delegate, loadBalancerClientFactory);
|
||||
};
|
||||
this.creators.add(creator);
|
||||
@@ -137,7 +137,7 @@ public final class ServiceInstanceListSupplierBuilder {
|
||||
public ServiceInstanceListSupplierBuilder withWeighted(WeightFunction weightFunction) {
|
||||
DelegateCreator creator = (context, delegate) -> {
|
||||
ReactiveLoadBalancer.Factory<ServiceInstance> loadBalancerClientFactory = context
|
||||
.getBean(LoadBalancerClientFactory.class);
|
||||
.getBean(LoadBalancerClientFactory.class);
|
||||
return new WeightedServiceInstanceListSupplier(delegate, weightFunction, loadBalancerClientFactory);
|
||||
};
|
||||
this.creators.add(creator);
|
||||
@@ -152,7 +152,7 @@ public final class ServiceInstanceListSupplierBuilder {
|
||||
public ServiceInstanceListSupplierBuilder withHealthChecks() {
|
||||
DelegateCreator creator = (context, delegate) -> {
|
||||
ReactiveLoadBalancer.Factory<ServiceInstance> loadBalancerClientFactory = context
|
||||
.getBean(LoadBalancerClientFactory.class);
|
||||
.getBean(LoadBalancerClientFactory.class);
|
||||
WebClient.Builder webClient = context.getBean(WebClient.Builder.class);
|
||||
return healthCheckServiceInstanceListSupplier(webClient.build(), delegate, loadBalancerClientFactory);
|
||||
};
|
||||
@@ -305,7 +305,7 @@ public final class ServiceInstanceListSupplierBuilder {
|
||||
public ServiceInstanceListSupplierBuilder withCaching() {
|
||||
DelegateCreator creator = (context, delegate) -> {
|
||||
ObjectProvider<LoadBalancerCacheManager> cacheManagerProvider = context
|
||||
.getBeanProvider(LoadBalancerCacheManager.class);
|
||||
.getBeanProvider(LoadBalancerCacheManager.class);
|
||||
if (cacheManagerProvider.getIfAvailable() != null) {
|
||||
return new CachingServiceInstanceListSupplier(delegate, cacheManagerProvider.getIfAvailable());
|
||||
}
|
||||
@@ -379,10 +379,10 @@ public final class ServiceInstanceListSupplierBuilder {
|
||||
ReactiveLoadBalancer.Factory<ServiceInstance> loadBalancerClientFactory) {
|
||||
return new HealthCheckServiceInstanceListSupplier(delegate, loadBalancerClientFactory,
|
||||
(serviceInstance, healthCheckPath) -> webClient.get()
|
||||
.uri(UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath)).build()
|
||||
.toUri())
|
||||
.exchange().flatMap(clientResponse -> clientResponse.releaseBody()
|
||||
.thenReturn(HttpStatus.OK.equals(clientResponse.statusCode()))));
|
||||
.uri(UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath)).build().toUri())
|
||||
.exchange()
|
||||
.flatMap(clientResponse -> clientResponse.releaseBody()
|
||||
.thenReturn(HttpStatus.OK.equals(clientResponse.statusCode()))));
|
||||
}
|
||||
|
||||
private ServiceInstanceListSupplier blockingHealthCheckServiceInstanceListSupplier(RestTemplate restTemplate,
|
||||
@@ -390,11 +390,12 @@ public final class ServiceInstanceListSupplierBuilder {
|
||||
ReactiveLoadBalancer.Factory<ServiceInstance> loadBalancerClientFactory) {
|
||||
return new HealthCheckServiceInstanceListSupplier(delegate, loadBalancerClientFactory,
|
||||
(serviceInstance, healthCheckPath) -> Mono.defer(() -> {
|
||||
URI uri = UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath)).build()
|
||||
.toUri();
|
||||
URI uri = UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath))
|
||||
.build()
|
||||
.toUri();
|
||||
try {
|
||||
return Mono
|
||||
.just(HttpStatus.OK.equals(restTemplate.getForEntity(uri, Void.class).getStatusCode()));
|
||||
.just(HttpStatus.OK.equals(restTemplate.getForEntity(uri, Void.class).getStatusCode()));
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
return Mono.just(false);
|
||||
@@ -406,11 +407,12 @@ public final class ServiceInstanceListSupplierBuilder {
|
||||
ServiceInstanceListSupplier delegate, LoadBalancerClientFactory loadBalancerClientFactory) {
|
||||
return new HealthCheckServiceInstanceListSupplier(delegate, loadBalancerClientFactory,
|
||||
(serviceInstance, healthCheckPath) -> Mono.defer(() -> {
|
||||
URI uri = UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath)).build()
|
||||
.toUri();
|
||||
URI uri = UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath))
|
||||
.build()
|
||||
.toUri();
|
||||
try {
|
||||
return Mono.just(HttpStatus.OK
|
||||
.equals(restClient.get().uri(uri).retrieve().toBodilessEntity().getStatusCode()));
|
||||
.equals(restClient.get().uri(uri).retrieve().toBodilessEntity().getStatusCode()));
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
return Mono.just(false);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class WeightedServiceInstanceListSupplier extends DelegatingServiceInstan
|
||||
super(delegate);
|
||||
this.weightFunction = weightFunction;
|
||||
callGetWithRequestOnDelegates = loadBalancerClientFactory.getProperties(getServiceId())
|
||||
.isCallGetWithRequestOnDelegates();
|
||||
.isCallGetWithRequestOnDelegates();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,7 +45,7 @@ public class XForwardedHeadersTransformer implements LoadBalancerClientRequestTr
|
||||
return request;
|
||||
}
|
||||
LoadBalancerProperties.XForwarded xForwarded = clientFactory.getProperties(instance.getServiceId())
|
||||
.getXForwarded();
|
||||
.getXForwarded();
|
||||
if (xForwarded.isEnabled()) {
|
||||
HttpHeaders headers = request.headers();
|
||||
String xForwardedHost = request.url().getHost();
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ZonePreferenceServiceInstanceListSupplier extends DelegatingService
|
||||
super(delegate);
|
||||
this.zoneConfig = zoneConfig;
|
||||
callGetWithRequestOnDelegates = loadBalancerClientFactory.getProperties(getServiceId())
|
||||
.isCallGetWithRequestOnDelegates();
|
||||
.isCallGetWithRequestOnDelegates();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -77,7 +77,7 @@ final class LoadBalancerTags {
|
||||
CompletionContext<Object, ServiceInstance, Object> completionContext) {
|
||||
if (completionContext.getLoadBalancerRequest().getContext() instanceof RequestDataContext) {
|
||||
RequestData requestData = ((RequestDataContext) completionContext.getLoadBalancerRequest().getContext())
|
||||
.getClientRequest();
|
||||
.getClientRequest();
|
||||
if (requestData != null) {
|
||||
return Tags.of(valueOrUnknown("method", requestData.getHttpMethod()),
|
||||
valueOrUnknown("uri", getPath(requestData)), valueOrUnknown("serviceId", getHost(requestData)));
|
||||
@@ -97,7 +97,7 @@ final class LoadBalancerTags {
|
||||
Tags tags = Tags.of(buildServiceInstanceTags(serviceInstance)).and(exception(completionContext.getThrowable()));
|
||||
if (completionContext.getLoadBalancerRequest().getContext() instanceof RequestDataContext) {
|
||||
RequestData requestData = ((RequestDataContext) completionContext.getLoadBalancerRequest().getContext())
|
||||
.getClientRequest();
|
||||
.getClientRequest();
|
||||
if (requestData != null) {
|
||||
return tags.and(Tags.of(valueOrUnknown("method", requestData.getHttpMethod()),
|
||||
valueOrUnknown("uri", getPath(requestData))));
|
||||
|
||||
@@ -76,7 +76,8 @@ public class MicrometerStatsLoadBalancerLifecycle implements LoadBalancerLifecyc
|
||||
AtomicLong activeRequestsCounter = activeRequestsPerInstance.computeIfAbsent(serviceInstance, instance -> {
|
||||
AtomicLong createdCounter = new AtomicLong();
|
||||
Gauge.builder("loadbalancer.requests.active", () -> createdCounter)
|
||||
.tags(buildServiceInstanceTags(serviceInstance)).register(meterRegistry);
|
||||
.tags(buildServiceInstanceTags(serviceInstance))
|
||||
.register(meterRegistry);
|
||||
return createdCounter;
|
||||
});
|
||||
activeRequestsCounter.incrementAndGet();
|
||||
@@ -86,8 +87,10 @@ public class MicrometerStatsLoadBalancerLifecycle implements LoadBalancerLifecyc
|
||||
public void onComplete(CompletionContext<Object, ServiceInstance, Object> completionContext) {
|
||||
long requestFinishedTimestamp = System.nanoTime();
|
||||
if (CompletionContext.Status.DISCARD.equals(completionContext.status())) {
|
||||
Counter.builder("loadbalancer.requests.discard").tags(buildDiscardedRequestTags(completionContext))
|
||||
.register(meterRegistry).increment();
|
||||
Counter.builder("loadbalancer.requests.discard")
|
||||
.tags(buildDiscardedRequestTags(completionContext))
|
||||
.register(meterRegistry)
|
||||
.increment();
|
||||
return;
|
||||
}
|
||||
ServiceInstance serviceInstance = completionContext.getLoadBalancerResponse().getServer();
|
||||
@@ -98,18 +101,20 @@ public class MicrometerStatsLoadBalancerLifecycle implements LoadBalancerLifecyc
|
||||
Object loadBalancerRequestContext = completionContext.getLoadBalancerRequest().getContext();
|
||||
if (requestHasBeenTimed(loadBalancerRequestContext)) {
|
||||
if (CompletionContext.Status.FAILED.equals(completionContext.status())) {
|
||||
Timer.builder("loadbalancer.requests.failed").tags(buildFailedRequestTags(completionContext))
|
||||
.register(meterRegistry)
|
||||
.record(requestFinishedTimestamp
|
||||
- ((TimedRequestContext) loadBalancerRequestContext).getRequestStartTime(),
|
||||
TimeUnit.NANOSECONDS);
|
||||
return;
|
||||
}
|
||||
Timer.builder("loadbalancer.requests.success").tags(buildSuccessRequestTags(completionContext))
|
||||
Timer.builder("loadbalancer.requests.failed")
|
||||
.tags(buildFailedRequestTags(completionContext))
|
||||
.register(meterRegistry)
|
||||
.record(requestFinishedTimestamp
|
||||
- ((TimedRequestContext) loadBalancerRequestContext).getRequestStartTime(),
|
||||
TimeUnit.NANOSECONDS);
|
||||
return;
|
||||
}
|
||||
Timer.builder("loadbalancer.requests.success")
|
||||
.tags(buildSuccessRequestTags(completionContext))
|
||||
.register(meterRegistry)
|
||||
.record(requestFinishedTimestamp
|
||||
- ((TimedRequestContext) loadBalancerRequestContext).getRequestStartTime(),
|
||||
TimeUnit.NANOSECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,9 +102,9 @@ public class LoadBalancerClientFactory extends NamedContextFactory<LoadBalancerC
|
||||
Map<String, Object> applicationContextInitializers) {
|
||||
Map<String, ApplicationContextInitializer<GenericApplicationContext>> convertedInitializers = new HashMap<>();
|
||||
applicationContextInitializers.keySet()
|
||||
.forEach(contextId -> convertedInitializers.put(contextId,
|
||||
(ApplicationContextInitializer<GenericApplicationContext>) applicationContextInitializers
|
||||
.get(contextId)));
|
||||
.forEach(contextId -> convertedInitializers.put(contextId,
|
||||
(ApplicationContextInitializer<GenericApplicationContext>) applicationContextInitializers
|
||||
.get(contextId)));
|
||||
return new LoadBalancerClientFactory(properties, convertedInitializers);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,20 +58,20 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
class LoadBalancerClientConfigurationTests {
|
||||
|
||||
ApplicationContextRunner reactiveDiscoveryClientRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(ReactiveCompositeDiscoveryClientAutoConfiguration.class,
|
||||
LoadBalancerCacheAutoConfiguration.class, LoadBalancerAutoConfiguration.class,
|
||||
LoadBalancerClientConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(ReactiveCompositeDiscoveryClientAutoConfiguration.class,
|
||||
LoadBalancerCacheAutoConfiguration.class, LoadBalancerAutoConfiguration.class,
|
||||
LoadBalancerClientConfiguration.class));
|
||||
|
||||
ApplicationContextRunner blockingDiscoveryClientRunner = new ApplicationContextRunner()
|
||||
.withClassLoader(new FilteredClassLoader(RetryTemplate.class))
|
||||
.withConfiguration(AutoConfigurations.of(CompositeDiscoveryClientAutoConfiguration.class,
|
||||
LoadBalancerCacheAutoConfiguration.class, LoadBalancerAutoConfiguration.class,
|
||||
LoadBalancerClientConfiguration.class));
|
||||
.withClassLoader(new FilteredClassLoader(RetryTemplate.class))
|
||||
.withConfiguration(AutoConfigurations.of(CompositeDiscoveryClientAutoConfiguration.class,
|
||||
LoadBalancerCacheAutoConfiguration.class, LoadBalancerAutoConfiguration.class,
|
||||
LoadBalancerClientConfiguration.class));
|
||||
|
||||
ApplicationContextRunner blockingDiscoveryClientRunnerWithRetry = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(CompositeDiscoveryClientAutoConfiguration.class,
|
||||
LoadBalancerCacheAutoConfiguration.class, LoadBalancerAutoConfiguration.class,
|
||||
LoadBalancerClientConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(CompositeDiscoveryClientAutoConfiguration.class,
|
||||
LoadBalancerCacheAutoConfiguration.class, LoadBalancerAutoConfiguration.class,
|
||||
LoadBalancerClientConfiguration.class));
|
||||
|
||||
@Test
|
||||
void shouldInstantiateDefaultServiceInstanceListSupplierWhenConfigurationsPropertyNotSet() {
|
||||
@@ -79,77 +79,75 @@ class LoadBalancerClientConfigurationTests {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInstantiateDefaultServiceInstanceListSupplier() {
|
||||
reactiveDiscoveryClientRunner.withPropertyValues("spring.cloud.loadbalancer.configurations=default")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInstantiateZonePreferenceServiceInstanceListSupplier() {
|
||||
reactiveDiscoveryClientRunner.withPropertyValues("spring.cloud.loadbalancer.configurations=zone-preference")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(ZonePreferenceServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier)
|
||||
.getDelegate();
|
||||
then(delegate).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate)
|
||||
.getDelegate();
|
||||
then(secondDelegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(ZonePreferenceServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier).getDelegate();
|
||||
then(delegate).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate)
|
||||
.getDelegate();
|
||||
then(secondDelegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInstantiateHealthCheckServiceInstanceListSupplier() {
|
||||
reactiveDiscoveryClientRunner.withUserConfiguration(TestConfig.class)
|
||||
.withPropertyValues("spring.cloud.loadbalancer.configurations=health-check").run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(HealthCheckServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier)
|
||||
.getDelegate();
|
||||
then(delegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
.withPropertyValues("spring.cloud.loadbalancer.configurations=health-check")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(HealthCheckServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier).getDelegate();
|
||||
then(delegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInstantiateWeightedServiceInstanceListSupplier() {
|
||||
reactiveDiscoveryClientRunner.withUserConfiguration(TestConfig.class)
|
||||
.withPropertyValues("spring.cloud.loadbalancer.configurations=weighted").run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(WeightedServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier)
|
||||
.getDelegate();
|
||||
then(delegate).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate)
|
||||
.getDelegate();
|
||||
then(secondDelegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
.withPropertyValues("spring.cloud.loadbalancer.configurations=weighted")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(WeightedServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier).getDelegate();
|
||||
then(delegate).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate)
|
||||
.getDelegate();
|
||||
then(secondDelegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInstantiateRequestBasedStickySessionServiceInstanceListSupplierTests() {
|
||||
reactiveDiscoveryClientRunner.withUserConfiguration(TestConfig.class)
|
||||
.withPropertyValues("spring.cloud.loadbalancer.configurations=request-based-sticky-session")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(RequestBasedStickySessionServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier)
|
||||
.getDelegate();
|
||||
then(delegate).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate)
|
||||
.getDelegate();
|
||||
then(secondDelegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
.withPropertyValues("spring.cloud.loadbalancer.configurations=request-based-sticky-session")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(RequestBasedStickySessionServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier).getDelegate();
|
||||
then(delegate).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate)
|
||||
.getDelegate();
|
||||
then(secondDelegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,19 +156,19 @@ class LoadBalancerClientConfigurationTests {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInstantiateDefaultBlockingServiceInstanceListSupplier() {
|
||||
blockingDiscoveryClientRunner.withPropertyValues("spring.cloud.loadbalancer.configurations=default")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,21 +177,21 @@ class LoadBalancerClientConfigurationTests {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(RetryAwareServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
.isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) ((DelegatingServiceInstanceListSupplier) supplier)
|
||||
.getDelegate()).getDelegate()).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
.getDelegate()).getDelegate()).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotWrapWithRetryAwareSupplierWhenRetryTemplateOnClasspath() {
|
||||
blockingDiscoveryClientRunner.withPropertyValues("spring.cloud.loadbalancer.retry.avoidPreviousInstance=false")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -201,26 +199,26 @@ class LoadBalancerClientConfigurationTests {
|
||||
@MethodSource("blockingConfigurations")
|
||||
void shouldInstantiateBlockingHealthCheckServiceInstanceListSupplier(Class<?> configurationClass) {
|
||||
blockingDiscoveryClientRunner.withUserConfiguration(configurationClass)
|
||||
.withPropertyValues("spring.cloud.loadbalancer.configurations=health-check").run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(HealthCheckServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
.withPropertyValues("spring.cloud.loadbalancer.configurations=health-check")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(HealthCheckServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInstantiateBlockingWeightedServiceInstanceListSupplier() {
|
||||
blockingDiscoveryClientRunner.withPropertyValues("spring.cloud.loadbalancer.configurations=weighted")
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(WeightedServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier)
|
||||
.getDelegate();
|
||||
then(delegate).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) delegate).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
.run(context -> {
|
||||
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
|
||||
then(supplier).isInstanceOf(WeightedServiceInstanceListSupplier.class);
|
||||
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier).getDelegate();
|
||||
then(delegate).isInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
then(((DelegatingServiceInstanceListSupplier) delegate).getDelegate())
|
||||
.isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
|
||||
});
|
||||
}
|
||||
|
||||
private static Stream<Arguments> blockingConfigurations() {
|
||||
|
||||
@@ -80,9 +80,9 @@ public class LoadBalancerChildContextInitializerTests {
|
||||
void shouldStartLBChildContextsFromAotContributions(CapturedOutput output) {
|
||||
WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(
|
||||
AnnotationConfigServletWebApplicationContext::new)
|
||||
.withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class,
|
||||
LoadBalancerAutoConfiguration.class))
|
||||
.withConfiguration(UserConfigurations.of(TestLoadBalancerConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class,
|
||||
LoadBalancerAutoConfiguration.class))
|
||||
.withConfiguration(UserConfigurations.of(TestLoadBalancerConfiguration.class));
|
||||
contextRunner.withPropertyValues("spring.cloud.loadbalancer.eager-load.clients[0]=test1").prepare(context -> {
|
||||
TestGenerationContext generationContext = new TestGenerationContext(TestTarget.class);
|
||||
ClassName className = new ApplicationContextAotGenerator().processAheadOfTime(
|
||||
@@ -92,14 +92,14 @@ public class LoadBalancerChildContextInitializerTests {
|
||||
compiler.with(generationContext).compile(compiled -> {
|
||||
ServletWebServerApplicationContext freshApplicationContext = new ServletWebServerApplicationContext();
|
||||
ApplicationContextInitializer<GenericApplicationContext> initializer = compiled
|
||||
.getInstance(ApplicationContextInitializer.class, className.toString());
|
||||
.getInstance(ApplicationContextInitializer.class, className.toString());
|
||||
initializer.initialize(freshApplicationContext);
|
||||
assertThat(output).contains("Refreshing LoadBalancerClientFactory-test1",
|
||||
"Refreshing LoadBalancerClientFactory-test-2", "Refreshing LoadBalancerClientFactory-test_3");
|
||||
assertThat(output).doesNotContain("Instantiating bean from Test 2 custom config",
|
||||
"Instantiating bean from default custom config");
|
||||
TestPropertyValues.of(AotDetector.AOT_ENABLED + "=true")
|
||||
.applyToSystemProperties(freshApplicationContext::refresh);
|
||||
.applyToSystemProperties(freshApplicationContext::refresh);
|
||||
WebClient webClient = freshApplicationContext.getBean(WebClient.class);
|
||||
webClient.get().uri(URI.create("http://test-2/")).retrieve().bodyToMono(String.class).subscribe();
|
||||
assertThat(output).contains("Instantiating bean from Test 2 custom config",
|
||||
|
||||
@@ -158,7 +158,8 @@ class BlockingLoadBalancerClientTests {
|
||||
(LoadBalancerRequest<Object>) instance -> {
|
||||
assertThat(instance.getHost()).isEqualTo("test.example");
|
||||
return "result";
|
||||
})).doesNotThrowAnyException();
|
||||
}))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,20 +173,20 @@ class BlockingLoadBalancerClientTests {
|
||||
});
|
||||
|
||||
Collection<Request<Object>> lifecycleLogRequests = ((TestLoadBalancerLifecycle) factory
|
||||
.getInstances("myservice", LoadBalancerLifecycle.class).get("loadBalancerLifecycle")).getStartLog()
|
||||
.values();
|
||||
.getInstances("myservice", LoadBalancerLifecycle.class)
|
||||
.get("loadBalancerLifecycle")).getStartLog().values();
|
||||
Collection<Request<Object>> lifecycleLogStartedRequests = ((TestLoadBalancerLifecycle) factory
|
||||
.getInstances("myservice", LoadBalancerLifecycle.class).get("loadBalancerLifecycle"))
|
||||
.getStartRequestLog().values();
|
||||
.getInstances("myservice", LoadBalancerLifecycle.class)
|
||||
.get("loadBalancerLifecycle")).getStartRequestLog().values();
|
||||
Collection<CompletionContext<Object, ServiceInstance, Object>> anotherLifecycleLogRequests = ((AnotherLoadBalancerLifecycle) factory
|
||||
.getInstances("myservice", LoadBalancerLifecycle.class).get("anotherLoadBalancerLifecycle"))
|
||||
.getCompleteLog().values();
|
||||
.getInstances("myservice", LoadBalancerLifecycle.class)
|
||||
.get("anotherLoadBalancerLifecycle")).getCompleteLog().values();
|
||||
assertThat(actualResult).isEqualTo(result);
|
||||
assertThat(lifecycleLogRequests).extracting(request -> ((DefaultRequestContext) request.getContext()).getHint())
|
||||
.contains(callbackTestHint);
|
||||
.contains(callbackTestHint);
|
||||
assertThat(lifecycleLogStartedRequests)
|
||||
.extracting(request -> ((DefaultRequestContext) request.getContext()).getHint())
|
||||
.contains(callbackTestHint);
|
||||
.extracting(request -> ((DefaultRequestContext) request.getContext()).getHint())
|
||||
.contains(callbackTestHint);
|
||||
assertThat(anotherLifecycleLogRequests).extracting(CompletionContext::getClientResponse).contains(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class DefaultLoadBalancerCacheManagerTests {
|
||||
assertThat(cacheManager.getCacheNames()).hasSize(1);
|
||||
assertThat(cacheManager.getCache(SERVICE_INSTANCE_CACHE_NAME)).isInstanceOf(DefaultLoadBalancerCache.class);
|
||||
assertThat(((DefaultLoadBalancerCache) cacheManager.getCache(SERVICE_INSTANCE_CACHE_NAME)).getEvictMs())
|
||||
.isEqualTo(300000);
|
||||
.isEqualTo(300000);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,7 +53,7 @@ class DefaultLoadBalancerCacheManagerTests {
|
||||
LoadBalancerCacheProperties properties = new LoadBalancerCacheProperties();
|
||||
|
||||
assertThatCode(() -> new DefaultLoadBalancerCacheManager(properties, "test", "test"))
|
||||
.doesNotThrowAnyException();
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -48,7 +48,7 @@ class DefaultLoadBalancerCacheTests {
|
||||
DefaultLoadBalancerCache cache = new DefaultLoadBalancerCache("test", false);
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> cache.put("testKey", null))
|
||||
.withMessageContaining("Cache 'test' is configured to not allow null values but null was provided");
|
||||
.withMessageContaining("Cache 'test' is configured to not allow null values but null was provided");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -36,8 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class BlockingLoadBalancerClientAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(LoadBalancerAutoConfiguration.class,
|
||||
BlockingLoadBalancerClientAutoConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(LoadBalancerAutoConfiguration.class,
|
||||
BlockingLoadBalancerClientAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void beansCreatedNormally() {
|
||||
@@ -50,7 +50,7 @@ class BlockingLoadBalancerClientAutoConfigurationTests {
|
||||
@Test
|
||||
public void worksWithoutSpringWeb() {
|
||||
applicationContextRunner.withClassLoader(new FilteredClassLoader(RestTemplate.class, RestClient.class))
|
||||
.run(context -> assertThat(context).doesNotHaveBean(BlockingLoadBalancerClient.class));
|
||||
.run(context -> assertThat(context).doesNotHaveBean(BlockingLoadBalancerClient.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -49,20 +49,20 @@ class LoadBalancerCacheAutoConfigurationTests {
|
||||
assertThat(((CacheManager) context.getBean("caffeineLoadBalancerCacheManager")).getCacheNames()).hasSize(1);
|
||||
assertThat(context.getBean("caffeineLoadBalancerCacheManager")).isInstanceOf(CaffeineCacheManager.class);
|
||||
assertThat(((CacheManager) context.getBean("caffeineLoadBalancerCacheManager")).getCacheNames())
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void caffeineLoadBalancerCacheShouldNotOverrideCacheTypeSetting() {
|
||||
ApplicationContextRunner contextRunner = baseApplicationRunner().withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.cache.type=none");
|
||||
.withPropertyValues("spring.cache.type=none");
|
||||
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context.getBeansOfType(CacheManager.class)).hasSize(2);
|
||||
assertThat(context.getBean("caffeineLoadBalancerCacheManager")).isInstanceOf(CaffeineCacheManager.class);
|
||||
assertThat(context.getBeansOfType(CacheManager.class).get("cacheManager"))
|
||||
.isInstanceOf(NoOpCacheManager.class);
|
||||
.isInstanceOf(NoOpCacheManager.class);
|
||||
|
||||
});
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class LoadBalancerCacheAutoConfigurationTests {
|
||||
assertThat(((CacheManager) context.getBean("cacheManager")).getCacheNames()).isEmpty();
|
||||
assertThat(((CacheManager) context.getBean("caffeineLoadBalancerCacheManager")).getCacheNames()).hasSize(1);
|
||||
assertThat(((CacheManager) context.getBean("caffeineLoadBalancerCacheManager")).getCacheNames())
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
});
|
||||
|
||||
}
|
||||
@@ -85,8 +85,8 @@ class LoadBalancerCacheAutoConfigurationTests {
|
||||
@Test
|
||||
void shouldNotInstantiateCaffeineLoadBalancerCacheIfDisabled() {
|
||||
ApplicationContextRunner contextRunner = baseApplicationRunner()
|
||||
.withPropertyValues("spring.cloud.loadbalancer.cache.enabled=false")
|
||||
.withUserConfiguration(TestConfiguration.class);
|
||||
.withPropertyValues("spring.cloud.loadbalancer.cache.enabled=false")
|
||||
.withUserConfiguration(TestConfiguration.class);
|
||||
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context.getBeansOfType(CacheManager.class)).hasSize(1);
|
||||
@@ -101,13 +101,13 @@ class LoadBalancerCacheAutoConfigurationTests {
|
||||
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context.getBean(LoadBalancerCacheAutoConfiguration.LoadBalancerCaffeineWarnLogger.class))
|
||||
.isNotNull();
|
||||
.isNotNull();
|
||||
assertThat(context.getBeansOfType(CacheManager.class)).hasSize(1);
|
||||
assertThat(((CacheManager) context.getBean("defaultLoadBalancerCacheManager")).getCacheNames()).hasSize(1);
|
||||
assertThat(context.getBean("defaultLoadBalancerCacheManager"))
|
||||
.isInstanceOf(DefaultLoadBalancerCacheManager.class);
|
||||
.isInstanceOf(DefaultLoadBalancerCacheManager.class);
|
||||
assertThat(((CacheManager) context.getBean("defaultLoadBalancerCacheManager")).getCacheNames())
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,27 +117,27 @@ class LoadBalancerCacheAutoConfigurationTests {
|
||||
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context.getBean(LoadBalancerCacheAutoConfiguration.LoadBalancerCaffeineWarnLogger.class))
|
||||
.isNotNull();
|
||||
.isNotNull();
|
||||
assertThat(context.getBeansOfType(CacheManager.class)).hasSize(1);
|
||||
assertThat(((CacheManager) context.getBean("defaultLoadBalancerCacheManager")).getCacheNames()).hasSize(1);
|
||||
assertThat(context.getBean("defaultLoadBalancerCacheManager"))
|
||||
.isInstanceOf(DefaultLoadBalancerCacheManager.class);
|
||||
.isInstanceOf(DefaultLoadBalancerCacheManager.class);
|
||||
assertThat(((CacheManager) context.getBean("defaultLoadBalancerCacheManager")).getCacheNames())
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultLoadBalancerCacheShouldNotOverrideCacheTypeSetting() {
|
||||
ApplicationContextRunner contextRunner = noCaffeineRunner().withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.cache.type=none");
|
||||
.withPropertyValues("spring.cache.type=none");
|
||||
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context.getBeansOfType(CacheManager.class)).hasSize(2);
|
||||
assertThat(context.getBean("defaultLoadBalancerCacheManager"))
|
||||
.isInstanceOf(DefaultLoadBalancerCacheManager.class);
|
||||
.isInstanceOf(DefaultLoadBalancerCacheManager.class);
|
||||
assertThat(context.getBeansOfType(CacheManager.class).get("cacheManager"))
|
||||
.isInstanceOf(NoOpCacheManager.class);
|
||||
.isInstanceOf(NoOpCacheManager.class);
|
||||
|
||||
});
|
||||
}
|
||||
@@ -152,7 +152,7 @@ class LoadBalancerCacheAutoConfigurationTests {
|
||||
assertThat(((CacheManager) context.getBean("cacheManager")).getCacheNames()).isEmpty();
|
||||
assertThat(((CacheManager) context.getBean("defaultLoadBalancerCacheManager")).getCacheNames()).hasSize(1);
|
||||
assertThat(((CacheManager) context.getBean("defaultLoadBalancerCacheManager")).getCacheNames())
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
.contains("CachingServiceInstanceListSupplierCache");
|
||||
});
|
||||
|
||||
}
|
||||
@@ -160,8 +160,8 @@ class LoadBalancerCacheAutoConfigurationTests {
|
||||
@Test
|
||||
void shouldNotInstantiateDefaultLoadBalancerCacheIfDisabled() {
|
||||
ApplicationContextRunner contextRunner = noCaffeineRunner()
|
||||
.withPropertyValues("spring.cloud.loadbalancer.cache.enabled=false")
|
||||
.withUserConfiguration(TestConfiguration.class);
|
||||
.withPropertyValues("spring.cloud.loadbalancer.cache.enabled=false")
|
||||
.withUserConfiguration(TestConfiguration.class);
|
||||
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context.getBeansOfType(CacheManager.class)).hasSize(1);
|
||||
@@ -173,11 +173,12 @@ class LoadBalancerCacheAutoConfigurationTests {
|
||||
@Test
|
||||
void shouldNotInstantiateDefaultLoadBalancerCacheIfLoadBalancingDisabled() {
|
||||
noCaffeineRunner().withPropertyValues("spring.cloud.loadbalancer.enabled=false")
|
||||
.withUserConfiguration(TestConfiguration.class).run(context -> {
|
||||
assertThat(context.getBeansOfType(CacheManager.class)).hasSize(1);
|
||||
assertThat(context.getBean("cacheManager")).isInstanceOf(ConcurrentMapCacheManager.class);
|
||||
assertThat(((CacheManager) context.getBean("cacheManager")).getCacheNames()).isEmpty();
|
||||
});
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.run(context -> {
|
||||
assertThat(context.getBeansOfType(CacheManager.class)).hasSize(1);
|
||||
assertThat(context.getBean("cacheManager")).isInstanceOf(ConcurrentMapCacheManager.class);
|
||||
assertThat(((CacheManager) context.getBean("cacheManager")).getCacheNames()).isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
private ApplicationContextRunner baseApplicationRunner() {
|
||||
|
||||
@@ -132,7 +132,7 @@ class CachingServiceInstanceListSupplierTests {
|
||||
firstDelegate, loadBalancerProperties, webClientBuilder.build());
|
||||
delegate.afterPropertiesSet();
|
||||
ObjectProvider<LoadBalancerCacheManager> cacheManagerProvider = context
|
||||
.getBeanProvider(LoadBalancerCacheManager.class);
|
||||
.getBeanProvider(LoadBalancerCacheManager.class);
|
||||
return new CachingServiceInstanceListSupplier(delegate, cacheManagerProvider.getIfAvailable());
|
||||
}
|
||||
|
||||
|
||||
@@ -69,38 +69,44 @@ class DiscoveryClientServiceInstanceListSupplierTests {
|
||||
@Test
|
||||
void shouldReturnRetrievedInstances() {
|
||||
when(reactiveDiscoveryClient.getInstances(SERVICE_ID))
|
||||
.thenReturn(Flux.just(instance("1host", false), instance("2host-secure", true)));
|
||||
.thenReturn(Flux.just(instance("1host", false), instance("2host-secure", true)));
|
||||
|
||||
StepVerifier.withVirtualTime(() -> {
|
||||
supplier = new DiscoveryClientServiceInstanceListSupplier(reactiveDiscoveryClient, environment);
|
||||
return supplier.get();
|
||||
}).expectSubscription().expectNext(Lists.list(instance("1host", false), instance("2host-secure", true)))
|
||||
.thenCancel().verify(VERIFICATION_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNext(Lists.list(instance("1host", false), instance("2host-secure", true)))
|
||||
.thenCancel()
|
||||
.verify(VERIFICATION_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUpdateReturnRetrievedInstances() {
|
||||
when(reactiveDiscoveryClient.getInstances(SERVICE_ID))
|
||||
.thenReturn(Flux.just(instance("1host", false), instance("2host-secure", true)));
|
||||
.thenReturn(Flux.just(instance("1host", false), instance("2host-secure", true)));
|
||||
supplier = new DiscoveryClientServiceInstanceListSupplier(reactiveDiscoveryClient, environment);
|
||||
|
||||
StepVerifier.withVirtualTime(() -> supplier.get()).expectSubscription()
|
||||
.expectNext(Lists.list(instance("1host", false), instance("2host-secure", true))).thenCancel()
|
||||
.verify(VERIFICATION_TIMEOUT);
|
||||
StepVerifier.withVirtualTime(() -> supplier.get())
|
||||
.expectSubscription()
|
||||
.expectNext(Lists.list(instance("1host", false), instance("2host-secure", true)))
|
||||
.thenCancel()
|
||||
.verify(VERIFICATION_TIMEOUT);
|
||||
|
||||
when(reactiveDiscoveryClient.getInstances(SERVICE_ID)).thenReturn(
|
||||
Flux.just(instance("1host", false), instance("2host-secure", true), instance("3host", false)));
|
||||
when(reactiveDiscoveryClient.getInstances(SERVICE_ID))
|
||||
.thenReturn(Flux.just(instance("1host", false), instance("2host-secure", true), instance("3host", false)));
|
||||
|
||||
StepVerifier.withVirtualTime(() -> supplier.get()).expectSubscription()
|
||||
.expectNext(
|
||||
Lists.list(instance("1host", false), instance("2host-secure", true), instance("3host", false)))
|
||||
.thenCancel().verify(VERIFICATION_TIMEOUT);
|
||||
StepVerifier.withVirtualTime(() -> supplier.get())
|
||||
.expectSubscription()
|
||||
.expectNext(Lists.list(instance("1host", false), instance("2host-secure", true), instance("3host", false)))
|
||||
.thenCancel()
|
||||
.verify(VERIFICATION_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnEmptyInstancesListOnException() {
|
||||
when(reactiveDiscoveryClient.getInstances(SERVICE_ID))
|
||||
.thenReturn(Flux.error(new RuntimeException("Exception")));
|
||||
.thenReturn(Flux.error(new RuntimeException("Exception")));
|
||||
|
||||
StepVerifier.withVirtualTime(() -> {
|
||||
supplier = new DiscoveryClientServiceInstanceListSupplier(reactiveDiscoveryClient, environment);
|
||||
@@ -113,36 +119,43 @@ class DiscoveryClientServiceInstanceListSupplierTests {
|
||||
environment.setProperty(SERVICE_DISCOVERY_TIMEOUT, "100ms");
|
||||
when(reactiveDiscoveryClient.getInstances(SERVICE_ID)).thenReturn(Flux.never());
|
||||
StepVerifier.create(new DiscoveryClientServiceInstanceListSupplier(reactiveDiscoveryClient, environment).get())
|
||||
.expectSubscription().expectNext(Collections.emptyList()).thenCancel().verify(VERIFICATION_TIMEOUT);
|
||||
.expectSubscription()
|
||||
.expectNext(Collections.emptyList())
|
||||
.thenCancel()
|
||||
.verify(VERIFICATION_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnRetrievedInstancesBlockingClient() {
|
||||
StepVerifier.withVirtualTime(() -> {
|
||||
when(discoveryClient.getInstances(SERVICE_ID))
|
||||
.thenReturn(Lists.list(instance("1host", false), instance("2host-secure", true)));
|
||||
.thenReturn(Lists.list(instance("1host", false), instance("2host-secure", true)));
|
||||
|
||||
supplier = new DiscoveryClientServiceInstanceListSupplier(discoveryClient, environment);
|
||||
return supplier.get();
|
||||
}).expectSubscription().expectNext(Lists.list(instance("1host", false), instance("2host-secure", true)))
|
||||
.thenCancel().verify(VERIFICATION_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNext(Lists.list(instance("1host", false), instance("2host-secure", true)))
|
||||
.thenCancel()
|
||||
.verify(VERIFICATION_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUpdateReturnRetrievedInstancesBlockingClient() {
|
||||
StepVerifier.withVirtualTime(() -> {
|
||||
when(discoveryClient.getInstances(SERVICE_ID))
|
||||
.thenReturn(Lists.list(instance("1host", false), instance("2host-secure", true)));
|
||||
.thenReturn(Lists.list(instance("1host", false), instance("2host-secure", true)));
|
||||
supplier = new DiscoveryClientServiceInstanceListSupplier(discoveryClient, environment);
|
||||
supplier.get();
|
||||
|
||||
when(discoveryClient.getInstances(SERVICE_ID)).thenReturn(
|
||||
Lists.list(instance("1host", false), instance("2host-secure", true), instance("3host", false)));
|
||||
return supplier.get();
|
||||
}).expectSubscription()
|
||||
.expectNext(
|
||||
Lists.list(instance("1host", false), instance("2host-secure", true), instance("3host", false)))
|
||||
.thenCancel().verify(VERIFICATION_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNext(Lists.list(instance("1host", false), instance("2host-secure", true), instance("3host", false)))
|
||||
.thenCancel()
|
||||
.verify(VERIFICATION_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,7 +175,10 @@ class DiscoveryClientServiceInstanceListSupplierTests {
|
||||
when(discoveryClient.getInstances(SERVICE_ID)).thenAnswer(new AnswersWithDelay(200, new Returns(
|
||||
Lists.list(instance("1host", false), instance("2host-secure", true), instance("3host", false)))));
|
||||
StepVerifier.create(new DiscoveryClientServiceInstanceListSupplier(discoveryClient, environment).get())
|
||||
.expectSubscription().expectNext(Collections.emptyList()).thenCancel().verify(VERIFICATION_TIMEOUT);
|
||||
.expectSubscription()
|
||||
.expectNext(Collections.emptyList())
|
||||
.thenCancel()
|
||||
.verify(VERIFICATION_TIMEOUT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -213,9 +213,13 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1)).expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,9 +248,14 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1)).expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval()).thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -277,9 +286,13 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval()).thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -308,9 +321,13 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1)).expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -339,8 +356,13 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay()).expectNext(Lists.list())
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval()).thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list())
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -364,9 +386,13 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
listSupplier.afterPropertiesSet();
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1)).expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -395,10 +421,16 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay()).expectNext(Lists.list())
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval()).expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval()).expectNext(Lists.list(serviceInstance1))
|
||||
.thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list())
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -424,11 +456,17 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval()).expectNext(Lists.list())
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval()).expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval()).expectNext(Lists.list(serviceInstance1))
|
||||
.thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.expectNext(Lists.list())
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -443,8 +481,8 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
ServiceInstanceListSupplier delegate = mock(ServiceInstanceListSupplier.class);
|
||||
Mockito.when(delegate.getServiceId()).thenReturn(SERVICE_ID);
|
||||
Flux<List<ServiceInstance>> instances = Flux.just(Lists.list(serviceInstance1))
|
||||
.concatWith(Flux.just(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.delayElements(properties.getHealthCheck().getInterval().dividedBy(2)));
|
||||
.concatWith(Flux.just(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.delayElements(properties.getHealthCheck().getInterval().dividedBy(2)));
|
||||
Mockito.when(delegate.get()).thenReturn(instances);
|
||||
|
||||
listSupplier = new HealthCheckServiceInstanceListSupplier(delegate,
|
||||
@@ -456,12 +494,18 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenAwait(properties.getHealthCheck().getInterval().dividedBy(2))
|
||||
.expectNext(Lists.list(serviceInstance1)).expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval()).expectNext(Lists.list(serviceInstance1))
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2)).thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenAwait(properties.getHealthCheck().getInterval().dividedBy(2))
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -478,8 +522,8 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
ServiceInstanceListSupplier delegate = mock(ServiceInstanceListSupplier.class);
|
||||
Mockito.when(delegate.getServiceId()).thenReturn(SERVICE_ID);
|
||||
Flux<List<ServiceInstance>> instances = Flux.just(Lists.list(serviceInstance1))
|
||||
.concatWith(Flux.just(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.delayElements(properties.getHealthCheck().getInterval().dividedBy(2)));
|
||||
.concatWith(Flux.just(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.delayElements(properties.getHealthCheck().getInterval().dividedBy(2)));
|
||||
Mockito.when(delegate.get()).thenReturn(instances);
|
||||
|
||||
listSupplier = new HealthCheckServiceInstanceListSupplier(delegate,
|
||||
@@ -491,12 +535,16 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenAwait(properties.getHealthCheck().getInterval().dividedBy(2))
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2)).thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenAwait(properties.getHealthCheck().getInterval().dividedBy(2))
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.expectNoEvent(properties.getHealthCheck().getInterval())
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -514,7 +562,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
ServiceInstanceListSupplier delegate = mock(ServiceInstanceListSupplier.class);
|
||||
when(delegate.getServiceId()).thenReturn(SERVICE_ID);
|
||||
when(delegate.get()).thenReturn(Flux.just(Collections.singletonList(serviceInstance1)))
|
||||
.thenReturn(Flux.just(Collections.singletonList(serviceInstance2)));
|
||||
.thenReturn(Flux.just(Collections.singletonList(serviceInstance2)));
|
||||
listSupplier = new HealthCheckServiceInstanceListSupplier(delegate,
|
||||
buildLoadBalancerClientFactory(SERVICE_ID, properties), webClientHealthCheckFunction()) {
|
||||
@Override
|
||||
@@ -523,10 +571,14 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
}
|
||||
};
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenAwait(properties.getHealthCheck().getRefetchInstancesInterval())
|
||||
.expectNext(Lists.list(serviceInstance2)).thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenAwait(properties.getHealthCheck().getRefetchInstancesInterval())
|
||||
.expectNext(Lists.list(serviceInstance2))
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -544,7 +596,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
ServiceInstanceListSupplier delegate = mock(ServiceInstanceListSupplier.class);
|
||||
when(delegate.getServiceId()).thenReturn(SERVICE_ID);
|
||||
when(delegate.get()).thenReturn(Flux.just(Collections.singletonList(serviceInstance1)))
|
||||
.thenReturn(Flux.just(Collections.singletonList(serviceInstance2)));
|
||||
.thenReturn(Flux.just(Collections.singletonList(serviceInstance2)));
|
||||
BiFunction<ServiceInstance, String, Mono<Boolean>> healthCheckFunc = webClientHealthCheckFunction();
|
||||
listSupplier = new HealthCheckServiceInstanceListSupplier(delegate,
|
||||
buildLoadBalancerClientFactory(SERVICE_ID, properties), healthCheckFunc) {
|
||||
@@ -554,10 +606,14 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
}
|
||||
};
|
||||
return listSupplier.get();
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenAwait(properties.getHealthCheck().getRefetchInstancesInterval())
|
||||
.expectNext(Lists.list(serviceInstance2)).thenCancel().verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenAwait(properties.getHealthCheck().getRefetchInstancesInterval())
|
||||
.expectNext(Lists.list(serviceInstance2))
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -589,9 +645,13 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
listSupplier.afterPropertiesSet();
|
||||
|
||||
return listSupplier.get().take(1).concatWith(listSupplier.get().take(1));
|
||||
}).expectSubscription().expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1)).expectNext(Lists.list(serviceInstance1)).thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
})
|
||||
.expectSubscription()
|
||||
.expectNoEvent(properties.getHealthCheck().getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
|
||||
Assertions.assertThat(emitCounter).hasValue(1);
|
||||
}
|
||||
@@ -602,22 +662,28 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
final AtomicInteger instancesCanceled = new AtomicInteger();
|
||||
final AtomicBoolean subscribed = new AtomicBoolean();
|
||||
ServiceInstanceListSupplier delegate = mock(ServiceInstanceListSupplier.class);
|
||||
Mockito.when(delegate.get()).thenReturn(Flux.<List<ServiceInstance>>never()
|
||||
.doOnSubscribe(subscription -> subscribed.set(true)).doOnCancel(instancesCanceled::incrementAndGet));
|
||||
Mockito.when(delegate.get())
|
||||
.thenReturn(Flux.<List<ServiceInstance>>never()
|
||||
.doOnSubscribe(subscription -> subscribed.set(true))
|
||||
.doOnCancel(instancesCanceled::incrementAndGet));
|
||||
|
||||
listSupplier = new HealthCheckServiceInstanceListSupplier(delegate,
|
||||
buildLoadBalancerClientFactory(SERVICE_ID, properties), webClientHealthCheckFunction());
|
||||
|
||||
listSupplier.afterPropertiesSet();
|
||||
|
||||
Awaitility.await("delegate subscription").pollDelay(Duration.ofMillis(50)).atMost(VERIFY_TIMEOUT)
|
||||
.untilTrue(subscribed);
|
||||
Awaitility.await("delegate subscription")
|
||||
.pollDelay(Duration.ofMillis(50))
|
||||
.atMost(VERIFY_TIMEOUT)
|
||||
.untilTrue(subscribed);
|
||||
|
||||
Assertions.assertThat(instancesCanceled).hasValue(0);
|
||||
|
||||
listSupplier.destroy();
|
||||
Awaitility.await("delegate cancellation").pollDelay(Duration.ofMillis(100)).atMost(VERIFY_TIMEOUT)
|
||||
.untilAsserted(() -> Assertions.assertThat(instancesCanceled).hasValue(1));
|
||||
Awaitility.await("delegate cancellation")
|
||||
.pollDelay(Duration.ofMillis(100))
|
||||
.atMost(VERIFY_TIMEOUT)
|
||||
.untilAsserted(() -> Assertions.assertThat(instancesCanceled).hasValue(1));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
|
||||
@@ -121,7 +121,7 @@ class LazyWeightedServiceInstanceListTest {
|
||||
list.get(list.size() - 1);
|
||||
|
||||
Map<String, Integer> counter = Arrays.stream(list.expanded)
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertThat(counter).containsEntry(serviceInstances.get(i).getInstanceId(), weights[i]);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class LoadBalancerTests {
|
||||
void staticConfigurationWorks() {
|
||||
String serviceId = "test1";
|
||||
RoundRobinLoadBalancer loadBalancer = new RoundRobinLoadBalancer(ServiceInstanceListSuppliers
|
||||
.toProvider(serviceId, instance(serviceId, "1host", false), instance(serviceId, "2host-secure", true)),
|
||||
.toProvider(serviceId, instance(serviceId, "1host", false), instance(serviceId, "2host-secure", true)),
|
||||
serviceId, -1);
|
||||
assertLoadBalancer(loadBalancer, Arrays.asList("1host", "2host-secure"));
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class RetryAwareServiceInstanceListSupplierTests {
|
||||
ServiceInstanceListSupplier supplier = new RetryAwareServiceInstanceListSupplier(delegate);
|
||||
|
||||
List<ServiceInstance> returnedInstances = supplier.get(new DefaultRequest<>(new RetryableRequestContext(null)))
|
||||
.blockFirst();
|
||||
.blockFirst();
|
||||
|
||||
assertThat(returnedInstances).isEmpty();
|
||||
}
|
||||
@@ -66,7 +66,8 @@ class RetryAwareServiceInstanceListSupplierTests {
|
||||
ServiceInstanceListSupplier supplier = new RetryAwareServiceInstanceListSupplier(delegate);
|
||||
|
||||
List<ServiceInstance> returnedInstances = supplier
|
||||
.get(new DefaultRequest<>(new RetryableRequestContext(firstInstance))).blockFirst();
|
||||
.get(new DefaultRequest<>(new RetryableRequestContext(firstInstance)))
|
||||
.blockFirst();
|
||||
|
||||
assertThat(returnedInstances).containsExactly(secondInstance);
|
||||
}
|
||||
@@ -78,7 +79,8 @@ class RetryAwareServiceInstanceListSupplierTests {
|
||||
ServiceInstanceListSupplier supplier = new RetryAwareServiceInstanceListSupplier(delegate);
|
||||
|
||||
List<ServiceInstance> returnedInstances = supplier
|
||||
.get(new DefaultRequest<>(new RetryableRequestContext(firstInstance))).blockFirst();
|
||||
.get(new DefaultRequest<>(new RetryableRequestContext(firstInstance)))
|
||||
.blockFirst();
|
||||
|
||||
assertThat(returnedInstances).containsExactly(firstInstance);
|
||||
}
|
||||
|
||||
@@ -36,8 +36,11 @@ public class ServiceInstanceListSupplierBuilderTests {
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
new ApplicationContextRunner().withUserConfiguration(CacheTestConfig.class).run(context -> {
|
||||
ServiceInstanceListSupplier supplier = ServiceInstanceListSupplier.builder().withDiscoveryClient()
|
||||
.withHealthChecks().withWeighted().build(context);
|
||||
ServiceInstanceListSupplier supplier = ServiceInstanceListSupplier.builder()
|
||||
.withDiscoveryClient()
|
||||
.withHealthChecks()
|
||||
.withWeighted()
|
||||
.build(context);
|
||||
assertThat(supplier).isInstanceOf(WeightedServiceInstanceListSupplier.class);
|
||||
DelegatingServiceInstanceListSupplier delegating = (DelegatingServiceInstanceListSupplier) supplier;
|
||||
assertThat(delegating.getDelegate()).isInstanceOf(HealthCheckServiceInstanceListSupplier.class);
|
||||
@@ -63,8 +66,11 @@ public class ServiceInstanceListSupplierBuilderTests {
|
||||
@Test
|
||||
public void testDelegateReturnedIfLoadBalancerCacheManagerNotAvailable() {
|
||||
new ApplicationContextRunner().withUserConfiguration(BaseTestConfig.class).run(context -> {
|
||||
ServiceInstanceListSupplier supplier = ServiceInstanceListSupplier.builder().withDiscoveryClient()
|
||||
.withHealthChecks().withCaching().build(context);
|
||||
ServiceInstanceListSupplier supplier = ServiceInstanceListSupplier.builder()
|
||||
.withDiscoveryClient()
|
||||
.withHealthChecks()
|
||||
.withCaching()
|
||||
.build(context);
|
||||
assertThat(supplier).isNotInstanceOf(CachingServiceInstanceListSupplier.class);
|
||||
assertThat(supplier).isInstanceOf(HealthCheckServiceInstanceListSupplier.class);
|
||||
DelegatingServiceInstanceListSupplier delegating = (DelegatingServiceInstanceListSupplier) supplier;
|
||||
|
||||
@@ -45,9 +45,10 @@ final class ServiceInstanceListSuppliersTestUtils {
|
||||
|
||||
static BiFunction<ServiceInstance, String, Mono<Boolean>> healthCheckFunction(WebClient webClient) {
|
||||
return (serviceInstance, healthCheckPath) -> webClient.get()
|
||||
.uri(UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath)).build().toUri())
|
||||
.exchange().flatMap(clientResponse -> clientResponse.releaseBody()
|
||||
.thenReturn(HttpStatus.OK.equals(clientResponse.statusCode())));
|
||||
.uri(UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath)).build().toUri())
|
||||
.exchange()
|
||||
.flatMap(clientResponse -> clientResponse.releaseBody()
|
||||
.thenReturn(HttpStatus.OK.equals(clientResponse.statusCode())));
|
||||
}
|
||||
|
||||
static BiFunction<ServiceInstance, String, Mono<Boolean>> healthCheckFunction(RestTemplate restTemplate) {
|
||||
|
||||
@@ -94,8 +94,8 @@ class SubsetServiceInstanceListSupplierTest {
|
||||
@Test
|
||||
void shouldReturnSublistWithGivenSubsetSize() {
|
||||
List<ServiceInstance> instances = IntStream.range(0, 101)
|
||||
.mapToObj(i -> new DefaultServiceInstance(Integer.toString(i), "test", "host" + i, 8080, false, null))
|
||||
.collect(Collectors.toList());
|
||||
.mapToObj(i -> new DefaultServiceInstance(Integer.toString(i), "test", "host" + i, 8080, false, null))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
when(delegate.getServiceId()).thenReturn("test");
|
||||
when(delegate.get()).thenReturn(Flux.just(instances));
|
||||
@@ -109,8 +109,8 @@ class SubsetServiceInstanceListSupplierTest {
|
||||
@Test
|
||||
void shouldReturnRawWhenLessThanSubsetSize() {
|
||||
List<ServiceInstance> instances = IntStream.range(0, 101)
|
||||
.mapToObj(i -> new DefaultServiceInstance(Integer.toString(i), "test", "host" + i, 8080, false, null))
|
||||
.collect(Collectors.toList());
|
||||
.mapToObj(i -> new DefaultServiceInstance(Integer.toString(i), "test", "host" + i, 8080, false, null))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
when(delegate.getServiceId()).thenReturn("test");
|
||||
when(delegate.get()).thenReturn(Flux.just(instances));
|
||||
@@ -124,8 +124,8 @@ class SubsetServiceInstanceListSupplierTest {
|
||||
@Test
|
||||
void shouldReturnSameSublistForSameInstanceId() {
|
||||
List<ServiceInstance> instances = IntStream.range(0, 101)
|
||||
.mapToObj(i -> new DefaultServiceInstance(Integer.toString(i), "test", "host" + i, 8080, false, null))
|
||||
.collect(Collectors.toList());
|
||||
.mapToObj(i -> new DefaultServiceInstance(Integer.toString(i), "test", "host" + i, 8080, false, null))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
when(delegate.getServiceId()).thenReturn("test");
|
||||
when(delegate.get()).thenReturn(Flux.just(instances));
|
||||
@@ -144,8 +144,8 @@ class SubsetServiceInstanceListSupplierTest {
|
||||
@Test
|
||||
void shouldReturnDifferentSublistForDifferentInstanceId() {
|
||||
List<ServiceInstance> instances = IntStream.range(0, 101)
|
||||
.mapToObj(i -> new DefaultServiceInstance(Integer.toString(i), "test", "host" + i, 8080, false, null))
|
||||
.collect(Collectors.toList());
|
||||
.mapToObj(i -> new DefaultServiceInstance(Integer.toString(i), "test", "host" + i, 8080, false, null))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
when(delegate.getServiceId()).thenReturn("test");
|
||||
when(delegate.get()).thenReturn(Flux.just(instances));
|
||||
|
||||
@@ -73,7 +73,7 @@ class WeightedServiceInstanceListSupplierTests {
|
||||
|
||||
List<ServiceInstance> serviceInstances = Objects.requireNonNull(supplier.get().blockFirst());
|
||||
Map<String, Integer> counter = serviceInstances.stream()
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
assertThat(counter).containsEntry("test-1", 1);
|
||||
assertThat(counter).containsEntry("test-2", 2);
|
||||
assertThat(counter).containsEntry("test-3", 3);
|
||||
@@ -90,7 +90,7 @@ class WeightedServiceInstanceListSupplierTests {
|
||||
|
||||
List<ServiceInstance> serviceInstances = Objects.requireNonNull(supplier.get().blockFirst());
|
||||
Map<String, Integer> counter = serviceInstances.stream()
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
assertThat(counter).containsEntry("test-1", 1);
|
||||
assertThat(counter).containsEntry("test-2", 2);
|
||||
assertThat(counter).containsEntry("test-3", 3);
|
||||
@@ -107,7 +107,7 @@ class WeightedServiceInstanceListSupplierTests {
|
||||
|
||||
List<ServiceInstance> serviceInstances = Objects.requireNonNull(supplier.get().blockFirst());
|
||||
Map<String, Integer> counter = serviceInstances.stream()
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
assertThat(counter).containsEntry("test-1", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-2", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-3", 3);
|
||||
@@ -124,7 +124,7 @@ class WeightedServiceInstanceListSupplierTests {
|
||||
|
||||
List<ServiceInstance> serviceInstances = Objects.requireNonNull(supplier.get().blockFirst());
|
||||
Map<String, Integer> counter = serviceInstances.stream()
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
assertThat(counter).containsEntry("test-1", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-2", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-3", DEFAULT_WEIGHT);
|
||||
@@ -141,7 +141,7 @@ class WeightedServiceInstanceListSupplierTests {
|
||||
|
||||
List<ServiceInstance> serviceInstances = Objects.requireNonNull(supplier.get().blockFirst());
|
||||
Map<String, Integer> counter = serviceInstances.stream()
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
assertThat(counter).containsEntry("test-1", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-2", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-3", DEFAULT_WEIGHT);
|
||||
@@ -159,7 +159,7 @@ class WeightedServiceInstanceListSupplierTests {
|
||||
|
||||
List<ServiceInstance> serviceInstances = Objects.requireNonNull(supplier.get().blockFirst());
|
||||
Map<String, Integer> counter = serviceInstances.stream()
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
assertThat(counter).containsEntry("test-1", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-2", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-3", DEFAULT_WEIGHT);
|
||||
@@ -178,7 +178,7 @@ class WeightedServiceInstanceListSupplierTests {
|
||||
|
||||
List<ServiceInstance> serviceInstances = Objects.requireNonNull(supplier.get().blockFirst());
|
||||
Map<String, Integer> counter = serviceInstances.stream()
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
assertThat(counter).containsEntry("test-1", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-2", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-3", DEFAULT_WEIGHT);
|
||||
@@ -201,7 +201,7 @@ class WeightedServiceInstanceListSupplierTests {
|
||||
|
||||
List<ServiceInstance> serviceInstances = Objects.requireNonNull(supplier.get(request).blockFirst());
|
||||
Map<String, Integer> counter = serviceInstances.stream()
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
.collect(Collectors.groupingBy(ServiceInstance::getInstanceId, summingInt(e -> 1)));
|
||||
assertThat(counter).containsEntry("test-1", DEFAULT_WEIGHT);
|
||||
assertThat(counter).containsEntry("test-2", DEFAULT_WEIGHT);
|
||||
assertThat(counter).doesNotContainEntry("test-3", 3);
|
||||
|
||||
@@ -57,8 +57,10 @@ public class OAuth2LoadBalancerClientAutoConfigurationTests {
|
||||
@Test
|
||||
@Disabled
|
||||
public void userInfoNotLoadBalanced() {
|
||||
this.context = new SpringApplicationBuilder(ClientConfiguration.class).properties("spring.config.name=test",
|
||||
"server.port=0", "security.oauth2.resource.userInfoUri:https://example.com").run();
|
||||
this.context = new SpringApplicationBuilder(ClientConfiguration.class)
|
||||
.properties("spring.config.name=test", "server.port=0",
|
||||
"security.oauth2.resource.userInfoUri:https://example.com")
|
||||
.run();
|
||||
|
||||
assertThat(this.context.containsBean("loadBalancedUserInfoRestTemplateCustomizer")).isFalse();
|
||||
assertThat(this.context.containsBean("retryLoadBalancedUserInfoRestTemplateCustomizer")).isFalse();
|
||||
@@ -67,9 +69,11 @@ public class OAuth2LoadBalancerClientAutoConfigurationTests {
|
||||
@Test
|
||||
@Disabled
|
||||
public void userInfoLoadBalancedNoRetry() {
|
||||
this.context = new SpringApplicationBuilder(ClientConfiguration.class).properties("spring.config.name=test",
|
||||
"server.port=0", "security.oauth2.resource.userInfoUri:https://nosuchservice",
|
||||
"spring.cloud.oauth2.load-balanced.enabled=true").run();
|
||||
this.context = new SpringApplicationBuilder(ClientConfiguration.class)
|
||||
.properties("spring.config.name=test", "server.port=0",
|
||||
"security.oauth2.resource.userInfoUri:https://nosuchservice",
|
||||
"spring.cloud.oauth2.load-balanced.enabled=true")
|
||||
.run();
|
||||
|
||||
assertThat(this.context.containsBean("loadBalancedUserInfoRestTemplateCustomizer")).isTrue();
|
||||
assertThat(this.context.containsBean("retryLoadBalancedUserInfoRestTemplateCustomizer")).isFalse();
|
||||
|
||||
@@ -67,8 +67,8 @@ class MicrometerStatsLoadBalancerLifecycleTests {
|
||||
statsLifecycle.onStartRequest(lbRequest, lbResponse);
|
||||
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(1);
|
||||
|
||||
statsLifecycle.onComplete(
|
||||
new CompletionContext<>(CompletionContext.Status.SUCCESS, lbRequest, lbResponse, responseData));
|
||||
statsLifecycle
|
||||
.onComplete(new CompletionContext<>(CompletionContext.Status.SUCCESS, lbRequest, lbResponse, responseData));
|
||||
|
||||
assertThat(meterRegistry.getMeters()).hasSize(2);
|
||||
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(0);
|
||||
@@ -126,8 +126,8 @@ class MicrometerStatsLoadBalancerLifecycleTests {
|
||||
statsLifecycle.onStartRequest(lbRequest, lbResponse);
|
||||
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(1);
|
||||
|
||||
statsLifecycle.onComplete(
|
||||
new CompletionContext<>(CompletionContext.Status.SUCCESS, lbRequest, lbResponse, responseData));
|
||||
statsLifecycle
|
||||
.onComplete(new CompletionContext<>(CompletionContext.Status.SUCCESS, lbRequest, lbResponse, responseData));
|
||||
|
||||
assertThat(meterRegistry.getMeters()).hasSize(1);
|
||||
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(0);
|
||||
@@ -141,7 +141,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
|
||||
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(1);
|
||||
|
||||
statsLifecycle
|
||||
.onComplete(new CompletionContext<>(CompletionContext.Status.SUCCESS, lbRequest, lbResponse, null));
|
||||
.onComplete(new CompletionContext<>(CompletionContext.Status.SUCCESS, lbRequest, lbResponse, null));
|
||||
|
||||
assertThat(meterRegistry.getMeters()).hasSize(2);
|
||||
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(0);
|
||||
@@ -162,8 +162,8 @@ class MicrometerStatsLoadBalancerLifecycleTests {
|
||||
statsLifecycle.onStartRequest(lbRequest, lbResponse);
|
||||
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(1);
|
||||
|
||||
statsLifecycle.onComplete(
|
||||
new CompletionContext<>(CompletionContext.Status.SUCCESS, lbRequest, lbResponse, responseData));
|
||||
statsLifecycle
|
||||
.onComplete(new CompletionContext<>(CompletionContext.Status.SUCCESS, lbRequest, lbResponse, responseData));
|
||||
|
||||
assertThat(meterRegistry.getMeters()).hasSize(2);
|
||||
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(0);
|
||||
|
||||
@@ -60,9 +60,9 @@ class LoadBalancerEnvironmentPropertyUtilsTests {
|
||||
environment.setProperty("spring.cloud.loadbalancer.test", "false");
|
||||
|
||||
assertThat(LoadBalancerEnvironmentPropertyUtils.equalToForClientOrDefault(environment, "test", "true"))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(LoadBalancerEnvironmentPropertyUtils.equalToOrMissingForClientOrDefault(environment, "test", "true"))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,16 +70,16 @@ class LoadBalancerEnvironmentPropertyUtilsTests {
|
||||
environment.setProperty("spring.cloud.loadbalancer.test", "true");
|
||||
|
||||
assertThat(LoadBalancerEnvironmentPropertyUtils.equalToForClientOrDefault(environment, "test", "true"))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(LoadBalancerEnvironmentPropertyUtils.equalToOrMissingForClientOrDefault(environment, "test", "true"))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnTrueWhenMissingForClientAndDefault() {
|
||||
assertThat(LoadBalancerEnvironmentPropertyUtils.trueOrMissingForClientOrDefault(environment, "test")).isTrue();
|
||||
assertThat(LoadBalancerEnvironmentPropertyUtils.equalToOrMissingForClientOrDefault(environment, "test", "true"))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user