下面列出了怎么用org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testChangeTimeout() throws Exception {
EnvironmentTestUtils
.addEnvironment(
this.context,
"spring.cloud.cluster.redis.lock.expireAfter:1234");
context.register(RedisAutoConfiguration.class, RedisLockServiceAutoConfiguration.class);
context.refresh();
RedisLockService service = context.getBean(RedisLockService.class);
RedisLockRegistry redisLockRegistry = TestUtils.readField("redisLockRegistry", service);
String registryKey = TestUtils.readField("registryKey", redisLockRegistry);
Long expireAfter = TestUtils.readField("expireAfter", redisLockRegistry);
assertThat(registryKey, is(RedisLockService.DEFAULT_REGISTRY_KEY));
assertThat(expireAfter, is(1234l));
}
@Test
public void testDefaults() {
EnvironmentTestUtils.addEnvironment(this.context);
context.register(RedisAutoConfiguration.class, RedisLockServiceAutoConfiguration.class);
context.refresh();
assertThat(context.containsBean("redisLockService"), is(true));
}
@Test
public void testDisabled() throws Exception {
EnvironmentTestUtils
.addEnvironment(
this.context,
"spring.cloud.cluster.redis.lock.enabled:false");
context.register(RedisAutoConfiguration.class, RedisLockServiceAutoConfiguration.class);
context.refresh();
assertThat(context.containsBean("redisLockService"), is(false));
}
@Test
public void testGlobalLeaderDisabled() throws Exception {
EnvironmentTestUtils
.addEnvironment(
this.context,
"spring.cloud.cluster.lock.enabled:false",
"spring.cloud.cluster.redis.lock.enabled:true");
context.register(RedisAutoConfiguration.class, RedisLockServiceAutoConfiguration.class);
context.refresh();
assertThat(context.containsBean("redisLockService"), is(false));
}
@Test
public void testChangeRole() throws Exception {
EnvironmentTestUtils
.addEnvironment(
this.context,
"spring.cloud.cluster.lock.role:foo");
context.register(RedisAutoConfiguration.class, RedisLockServiceAutoConfiguration.class);
context.refresh();
RedisLockService service = context.getBean(RedisLockService.class);
RedisLockRegistry redisLockRegistry = TestUtils.readField("redisLockRegistry", service);
String registryKey = TestUtils.readField("registryKey", redisLockRegistry);
assertThat(registryKey, is("foo"));
}
@Before
public void setup() {
context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context);
context.register(RedisAutoConfiguration.class);
context.refresh();
connectionFactory = context.getBean(RedisConnectionFactory.class);
redisTemplate = new RedisTemplate<String, String>();
redisTemplate.setConnectionFactory(connectionFactory);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.afterPropertiesSet();
cleanLocks();
}