类org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration源码实例Demo

下面列出了怎么用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"));
}
 
源代码6 项目: spring-cloud-cluster   文件: RedisIT.java
@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();
}
 
 类方法
 同包方法