DATAREDIS-935 - Allow configuration of a single initial cache in RedisCacheManagerBuilder.
Also, add introspection methods to expose the configured cache names/configurations. Original pull request: #387.
This commit is contained in:
committed by
Mark Paluch
parent
32cc2a60e7
commit
630ff46b45
@@ -25,6 +25,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.transaction.TransactionAwareCacheDecorator;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager.RedisCacheManagerBuilder;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
@@ -110,4 +111,43 @@ public class RedisCacheManagerUnitTests {
|
||||
|
||||
assertThat(cacheManager.getCache("configured")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-935
|
||||
public void cacheManagerBuilderReturnsConfiguredCaches() {
|
||||
|
||||
RedisCacheManagerBuilder cmb = RedisCacheManager.builder(cacheWriter)
|
||||
.initialCacheNames(Collections.singleton("configured")).disableCreateOnMissingCache();
|
||||
|
||||
assertThat(cmb.getConfiguredCaches()).containsExactly("configured");
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||
.isThrownBy(() -> cmb.getConfiguredCaches().add("another"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-935
|
||||
public void cacheManagerBuilderDoesNotAllowSneakingInConfiguration() {
|
||||
|
||||
RedisCacheManagerBuilder cmb = RedisCacheManager.builder(cacheWriter)
|
||||
.initialCacheNames(Collections.singleton("configured")).disableCreateOnMissingCache();
|
||||
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||
.isThrownBy(() -> cmb.getConfiguredCaches().add("another"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-935
|
||||
public void cacheManagerBuilderReturnsConfigurationForKnownCache() {
|
||||
|
||||
RedisCacheManagerBuilder cmb = RedisCacheManager.builder(cacheWriter)
|
||||
.initialCacheNames(Collections.singleton("configured")).disableCreateOnMissingCache();
|
||||
|
||||
assertThat(cmb.getCacheConfigurationFor("configured")).isPresent();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-935
|
||||
public void cacheManagerBuilderReturnsEmptyOptionalForUnknownCache() {
|
||||
|
||||
RedisCacheManagerBuilder cmb = RedisCacheManager.builder(cacheWriter)
|
||||
.initialCacheNames(Collections.singleton("configured")).disableCreateOnMissingCache();
|
||||
|
||||
assertThat(cmb.getCacheConfigurationFor("unknown")).isNotPresent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user