Java Code Examples for org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration

The following examples show how to use org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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));
}
 
Example 2
@Test
public void testDefaults() {
	EnvironmentTestUtils.addEnvironment(this.context);
	context.register(RedisAutoConfiguration.class, RedisLockServiceAutoConfiguration.class);
	context.refresh();
	
	assertThat(context.containsBean("redisLockService"), is(true));		
}
 
Example 3
@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));
}
 
Example 4
@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));
}
 
Example 5
@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"));
}
 
Example 6
Source Project: spring-cloud-cluster   Source File: RedisIT.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}