@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 redisHealthIndicator() { this.context.register(RedisAutoConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertThat(beans).hasSize(1); assertThat(beans.values().iterator().next().getClass()) .isEqualTo(RedisHealthIndicator.class); }
@Test public void notRedisHealthIndicator() { this.context.register(RedisAutoConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.redis.enabled:false", "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertThat(beans).hasSize(1); assertThat(beans.values().iterator().next().getClass()) .isEqualTo(ApplicationHealthIndicator.class); }
@Test public void combinedHealthIndicator() { this.context.register(MongoAutoConfiguration.class, RedisAutoConfiguration.class, MongoDataAutoConfiguration.class, SolrAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertThat(beans).hasSize(4); }
@Test public void indicatorExists() { this.context = new AnnotationConfigApplicationContext( PropertyPlaceholderAutoConfiguration.class, RedisAutoConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); assertThat(this.context.getBeanNamesForType(RedisConnectionFactory.class)) .hasSize(1); RedisHealthIndicator healthIndicator = this.context .getBean(RedisHealthIndicator.class); assertThat(healthIndicator).isNotNull(); }
@Test public void redisSessionStore() { load(Collections.<Class<?>>singletonList(RedisAutoConfiguration.class), "spring.session.store-type=redis"); validateSpringSessionUsesRedis(); this.output.expect(not(containsString("Spring Session store type is mandatory: set 'spring.session.store-type=redis' in your configuration"))); }
@Test public void redisSessionStoreWithCustomizations() { load(Collections.<Class<?>>singletonList(RedisAutoConfiguration.class), "spring.session.store-type=redis", "spring.session.redis.namespace=foo", "spring.session.redis.flush-mode=immediate"); RedisOperationsSessionRepository repository = validateSessionRepository( RedisOperationsSessionRepository.class); assertThat(repository.getSessionCreatedChannelPrefix()) .isEqualTo("spring:session:foo:event:created:"); assertThat(new DirectFieldAccessor(repository).getPropertyValue("redisFlushMode")) .isEqualTo(RedisFlushMode.IMMEDIATE); }
@Before public void setup() { context = new AnnotationConfigApplicationContext(); context.setId("testDataFlowConfig"); context.register(DataFlowServerConfigurationTests.TestConfiguration.class, RedisAutoConfiguration.class, SecurityAutoConfiguration.class, DataFlowServerAutoConfiguration.class, DataFlowControllerAutoConfiguration.class, DataSourceAutoConfiguration.class, DataFlowServerConfiguration.class, PropertyPlaceholderAutoConfiguration.class, WebClientAutoConfiguration.class, HibernateJpaAutoConfiguration.class, WebConfiguration.class); environment = new StandardEnvironment(); propertySources = environment.getPropertySources(); }
@Test public void redisHealthIndicator() { this.context.register(RedisAutoConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(1, beans.size()); assertEquals(RedisHealthIndicator.class, beans.values().iterator().next().getClass()); }
@Test public void notRedisHealthIndicator() { this.context.register(RedisAutoConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.redis.enabled:false", "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(1, beans.size()); assertEquals(ApplicationHealthIndicator.class, beans.values().iterator().next().getClass()); }
@Test public void combinedHealthIndicator() { this.context.register(MongoAutoConfiguration.class, RedisAutoConfiguration.class, MongoDataAutoConfiguration.class, SolrAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(4, beans.size()); }
@Test public void indicatorExists() { this.context = new AnnotationConfigApplicationContext( PropertyPlaceholderAutoConfiguration.class, RedisAutoConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); assertEquals(1, this.context.getBeanNamesForType(RedisConnectionFactory.class).length); RedisHealthIndicator healthIndicator = this.context .getBean(RedisHealthIndicator.class); assertNotNull(healthIndicator); }
@Test public void flat() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context.register(Config.class, ServerPropertiesAutoConfiguration.class, RedisAutoConfiguration.class, SessionAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); ServerProperties server = this.context.getBean(ServerProperties.class); assertNotNull(server); }
@Test public void hierarchy() throws Exception { AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(); parent.register(RedisAutoConfiguration.class, SessionAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); parent.refresh(); this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context.setParent(parent); this.context.register(Config.class, ServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); ServerProperties server = this.context.getBean(ServerProperties.class); assertNotNull(server); }
@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(); }
@Test public void redisSessionStoreIsTheDefault() { load(Collections.<Class<?>>singletonList(RedisAutoConfiguration.class)); validateSpringSessionUsesRedis(); this.output.expect(containsString("Spring Session store type is mandatory: set 'spring.session.store-type=redis' in your configuration")); }