Skip to content

Commit ad57d99

Browse files
committed
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 hazelcast/hazelcast#7606 Closes gh-5209
1 parent 5d1ee87 commit ad57d99

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27+
import javax.cache.Caching;
2728
import javax.cache.configuration.CompleteConfiguration;
2829
import javax.cache.configuration.MutableConfiguration;
2930
import javax.cache.expiry.CreatedExpiryPolicy;
@@ -468,12 +469,17 @@ public void hazelcastCacheWithMainHazelcastAutoConfigurationAndSeparateCacheConf
468469
@Test
469470
public void hazelcastAsJCacheWithCaches() {
470471
String cachingProviderFqn = HazelcastCachingProvider.class.getName();
471-
load(DefaultCacheConfiguration.class, "spring.cache.type=jcache",
472-
"spring.cache.jcache.provider=" + cachingProviderFqn,
473-
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar");
474-
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
475-
assertThat(cacheManager.getCacheNames(), containsInAnyOrder("foo", "bar"));
476-
assertThat(cacheManager.getCacheNames(), hasSize(2));
472+
try {
473+
load(DefaultCacheConfiguration.class, "spring.cache.type=jcache",
474+
"spring.cache.jcache.provider=" + cachingProviderFqn,
475+
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar");
476+
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
477+
assertThat(cacheManager.getCacheNames(), containsInAnyOrder("foo", "bar"));
478+
assertThat(cacheManager.getCacheNames(), hasSize(2));
479+
}
480+
finally {
481+
Caching.getCachingProvider(cachingProviderFqn).close();
482+
}
477483
}
478484

479485
@Test

0 commit comments

Comments
 (0)