From ad57d99fe5e7414d481ae6ce8cfa658f02cacdfb Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 25 Feb 2016 14:25:28 +0100 Subject: [PATCH] Cleanup HazelcastInstance in test If a JCache provider is started with hazelcast and the default settings, the underlying `HazelcastInstance` is disposed at the end of the process, not when the `CacheManager` is closed. This commit fixes the only test that use such setup. See also https://github.com/hazelcast/hazelcast/issues/7606 Closes gh-5209 --- .../cache/CacheAutoConfigurationTests.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index 03b308414b..7199d5ad9b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import javax.cache.Caching; import javax.cache.configuration.CompleteConfiguration; import javax.cache.configuration.MutableConfiguration; import javax.cache.expiry.CreatedExpiryPolicy; @@ -468,12 +469,17 @@ public class CacheAutoConfigurationTests { @Test public void hazelcastAsJCacheWithCaches() { String cachingProviderFqn = HazelcastCachingProvider.class.getName(); - load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", - "spring.cache.jcache.provider=" + cachingProviderFqn, - "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar"); - JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); - assertThat(cacheManager.getCacheNames(), containsInAnyOrder("foo", "bar")); - assertThat(cacheManager.getCacheNames(), hasSize(2)); + try { + load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", + "spring.cache.jcache.provider=" + cachingProviderFqn, + "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar"); + JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); + assertThat(cacheManager.getCacheNames(), containsInAnyOrder("foo", "bar")); + assertThat(cacheManager.getCacheNames(), hasSize(2)); + } + finally { + Caching.getCachingProvider(cachingProviderFqn).close(); + } } @Test