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:
Christoph Strobl
2019-02-26 14:05:34 +01:00
committed by Mark Paluch
parent 32cc2a60e7
commit 630ff46b45
2 changed files with 80 additions and 4 deletions

View File

@@ -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();
}
}