DATAREDIS-283 - RedisCacheManager.loadCaches overrides already defined cache names in afterPropertiesSet().
We now retain the potentially already configured caches during the initialisation of the RedisCacheManager bean. Previously we discarded the already configured caches which was an undesired side-effect. Original pull request: #45.
This commit is contained in:
committed by
Christoph Strobl
parent
ec2a760dd6
commit
9cf484d25a
@@ -42,6 +42,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RedisCacheManagerUnitTests {
|
||||
@@ -171,4 +172,34 @@ public class RedisCacheManagerUnitTests {
|
||||
assertThat(cacheManager.getCache("redis"), notNullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-283
|
||||
*/
|
||||
@Test
|
||||
public void testRetainConfiguredCachesAfterBeanInitialization() {
|
||||
|
||||
cacheManager.setCacheNames(Arrays.asList("spring", "data"));
|
||||
cacheManager.afterPropertiesSet();
|
||||
|
||||
assertThat(cacheManager.getCache("spring"), notNullValue());
|
||||
assertThat(cacheManager.getCache("data"), notNullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-283
|
||||
*/
|
||||
@Test
|
||||
public void testRetainConfiguredCachesAfterBeanInitializationWithLoadingOfRemoteKeys() {
|
||||
|
||||
cacheManager.setCacheNames(Arrays.asList("spring", "data"));
|
||||
Set<byte[]> keys = new HashSet<byte[]>(Arrays.asList(redisTemplate.getKeySerializer()
|
||||
.serialize("remote-cache~keys")));
|
||||
when(redisConnectionMock.keys(any(byte[].class))).thenReturn(keys);
|
||||
cacheManager.setLoadRemoteCachesOnStartup(true);
|
||||
cacheManager.afterPropertiesSet();
|
||||
|
||||
assertThat(cacheManager.getCache("spring"), notNullValue());
|
||||
assertThat(cacheManager.getCache("data"), notNullValue());
|
||||
assertThat(cacheManager.getCacheNames(), IsCollectionContaining.hasItem("remote-cache"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user