Align Session auto-config with Redis namespace config support

See gh-11084
pull/11055/head
Vedran Pavic 7 years ago committed by Stephane Nicoll
parent f654b9b302
commit b6d9ae7efa

@ -33,7 +33,7 @@ public class RedisSessionProperties {
/** /**
* Namespace for keys used to store sessions. * Namespace for keys used to store sessions.
*/ */
private String namespace = ""; private String namespace = "spring:session";
/** /**
* Sessions flush mode. * Sessions flush mode.

@ -41,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Vedran Pavic
*/ */
public class ReactiveSessionAutoConfigurationRedisTests public class ReactiveSessionAutoConfigurationRedisTests
extends AbstractSessionAutoConfigurationTests { extends AbstractSessionAutoConfigurationTests {
@ -56,7 +57,7 @@ public class ReactiveSessionAutoConfigurationRedisTests
this.contextRunner.withPropertyValues("spring.session.store-type=redis") this.contextRunner.withPropertyValues("spring.session.store-type=redis")
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class,
RedisReactiveAutoConfiguration.class)) RedisReactiveAutoConfiguration.class))
.run(validateSpringSessionUsesRedis(RedisFlushMode.ON_SAVE)); .run(validateSpringSessionUsesRedis("spring:session:", RedisFlushMode.ON_SAVE));
} }
@Test @Test
@ -66,7 +67,7 @@ public class ReactiveSessionAutoConfigurationRedisTests
ReactiveMongoOperationsSessionRepository.class)) ReactiveMongoOperationsSessionRepository.class))
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class,
RedisReactiveAutoConfiguration.class)) RedisReactiveAutoConfiguration.class))
.run(validateSpringSessionUsesRedis(RedisFlushMode.ON_SAVE)); .run(validateSpringSessionUsesRedis("spring:session:", RedisFlushMode.ON_SAVE));
} }
@Test @Test
@ -77,16 +78,18 @@ public class ReactiveSessionAutoConfigurationRedisTests
.withPropertyValues("spring.session.store-type=redis", .withPropertyValues("spring.session.store-type=redis",
"spring.session.redis.namespace=foo", "spring.session.redis.namespace=foo",
"spring.session.redis.flush-mode=immediate") "spring.session.redis.flush-mode=immediate")
.run(validateSpringSessionUsesRedis(RedisFlushMode.IMMEDIATE)); .run(validateSpringSessionUsesRedis("foo:", RedisFlushMode.IMMEDIATE));
} }
private ContextConsumer<AssertableReactiveWebApplicationContext> validateSpringSessionUsesRedis( private ContextConsumer<AssertableReactiveWebApplicationContext> validateSpringSessionUsesRedis(
RedisFlushMode flushMode) { String namespace, RedisFlushMode flushMode) {
return (context) -> { return (context) -> {
System.out.println(new ConditionEvaluationReportMessage( System.out.println(new ConditionEvaluationReportMessage(
context.getBean(ConditionEvaluationReport.class))); context.getBean(ConditionEvaluationReport.class)));
ReactiveRedisOperationsSessionRepository repository = validateSessionRepository( ReactiveRedisOperationsSessionRepository repository = validateSessionRepository(
context, ReactiveRedisOperationsSessionRepository.class); context, ReactiveRedisOperationsSessionRepository.class);
assertThat(new DirectFieldAccessor(repository).getPropertyValue("namespace"))
.isEqualTo(namespace);
assertThat(new DirectFieldAccessor(repository) assertThat(new DirectFieldAccessor(repository)
.getPropertyValue("redisFlushMode")).isEqualTo(flushMode); .getPropertyValue("redisFlushMode")).isEqualTo(flushMode);
}; };

@ -78,7 +78,7 @@ public class SessionAutoConfigurationRedisTests
"spring.session.redis.namespace=foo", "spring.session.redis.namespace=foo",
"spring.session.redis.flush-mode=immediate", "spring.session.redis.flush-mode=immediate",
"spring.session.redis.cleanup-cron=0 0 12 * * *") "spring.session.redis.cleanup-cron=0 0 12 * * *")
.run(validateSpringSessionUsesRedis("spring:session:foo:event:created:", .run(validateSpringSessionUsesRedis("foo:event:created:",
RedisFlushMode.IMMEDIATE, "0 0 12 * * *")); RedisFlushMode.IMMEDIATE, "0 0 12 * * *"));
} }

Loading…
Cancel
Save