Add basic cache metrics support for Infinispan
Closes gh-3066
This commit is contained in:
@@ -17,14 +17,24 @@
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.configuration.MutableConfiguration;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.hazelcast.cache.HazelcastCachingProvider;
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.XmlConfigBuilder;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.spring.cache.HazelcastCacheManager;
|
||||
import org.infinispan.manager.DefaultCacheManager;
|
||||
import org.infinispan.manager.EmbeddedCacheManager;
|
||||
import org.infinispan.spring.provider.SpringEmbeddedCacheManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.actuate.autoconfigure.CacheStatisticsAutoConfiguration;
|
||||
|
||||
import org.springframework.boot.actuate.cache.CacheStatistics;
|
||||
import org.springframework.boot.actuate.cache.CacheStatisticsProvider;
|
||||
import org.springframework.cache.Cache;
|
||||
@@ -42,14 +52,6 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.hazelcast.cache.HazelcastCachingProvider;
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.XmlConfigBuilder;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.spring.cache.HazelcastCacheManager;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@@ -76,7 +78,7 @@ public class CacheStatisticsAutoConfigurationTests {
|
||||
public void basicJCacheCacheStatistics() {
|
||||
load(JCacheCacheConfig.class);
|
||||
CacheStatisticsProvider provider = this.context.getBean(
|
||||
"jCacheStatisticsProvider", CacheStatisticsProvider.class);
|
||||
"jCacheCacheStatisticsProvider", CacheStatisticsProvider.class);
|
||||
doTestCoreStatistics(provider, false);
|
||||
}
|
||||
|
||||
@@ -96,6 +98,14 @@ public class CacheStatisticsAutoConfigurationTests {
|
||||
doTestCoreStatistics(provider, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicInfinispanCacheStatistics() {
|
||||
load(InfinispanConfig.class);
|
||||
CacheStatisticsProvider provider = this.context.getBean(
|
||||
"infinispanCacheStatisticsProvider", CacheStatisticsProvider.class);
|
||||
doTestCoreStatistics(provider, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicGuavaCacheStatistics() {
|
||||
load(GuavaConfig.class);
|
||||
@@ -246,6 +256,28 @@ public class CacheStatisticsAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class InfinispanConfig {
|
||||
|
||||
@Bean
|
||||
public SpringEmbeddedCacheManager cacheManager() throws IOException {
|
||||
return new SpringEmbeddedCacheManager(embeddedCacheManager());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EmbeddedCacheManager embeddedCacheManager() throws IOException {
|
||||
Resource resource = new ClassPathResource("cache/test-infinispan.xml");
|
||||
InputStream in = resource.getInputStream();
|
||||
try {
|
||||
return new DefaultCacheManager(in);
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class GuavaConfig {
|
||||
|
||||
|
||||
9
spring-boot-actuator/src/test/resources/cache/test-infinispan.xml
vendored
Normal file
9
spring-boot-actuator/src/test/resources/cache/test-infinispan.xml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<infinispan xmlns="urn:infinispan:config:7.2">
|
||||
|
||||
<cache-container default-cache="default">
|
||||
<local-cache name="books" statistics="true"/>
|
||||
<local-cache name="players" statistics="true"/>
|
||||
</cache-container>
|
||||
|
||||
</infinispan>
|
||||
Reference in New Issue
Block a user