Skip to content

Commit d53454c

Browse files
Add test for global cache metrics registration path
Verify that CaffeineCacheMetrics are registered for the global response-cache when both MeterRegistry and global filter are enabled.
1 parent cd815b1 commit d53454c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

spring-cloud-gateway-server-webflux/src/test/java/org/springframework/cloud/gateway/config/LocalResponseCacheMetricsAutoConfigurationTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ void cacheMetricsListenerBindsToMeterRegistry() {
114114
});
115115
}
116116

117+
@Test
118+
void globalCacheMetricsRegisteredViaCaffeineCache() {
119+
SimpleMeterRegistry registry = new SimpleMeterRegistry();
120+
new ApplicationContextRunner()
121+
.withConfiguration(AutoConfigurations.of(LocalResponseCacheAutoConfiguration.class,
122+
LocalResponseCacheMetricsAutoConfiguration.class))
123+
.withBean(MeterRegistry.class, () -> registry)
124+
.withPropertyValues(GatewayProperties.PREFIX + ".filter.local-response-cache.enabled=true",
125+
GatewayProperties.PREFIX + ".enabled=true",
126+
GatewayProperties.PREFIX + ".global-filter.local-response-cache.enabled=true")
127+
.run(context -> {
128+
assertThat(context).hasSingleBean(CacheMetricsListener.class);
129+
assertThat(registry.find("cache.size").tag("cache", "response-cache").gauge()).isNotNull();
130+
});
131+
}
132+
117133
@Configuration(proxyBeanMethods = false)
118134
static class MeterRegistryConfig {
119135

0 commit comments

Comments
 (0)