Skip to content

Commit

Permalink
Align Session auto-config with Redis namespace config support
Browse files Browse the repository at this point in the history
  • Loading branch information
vpavic authored and snicoll committed Nov 20, 2017
1 parent f654b9b commit b6d9ae7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RedisSessionProperties {
/**
* Namespace for keys used to store sessions.
*/
private String namespace = "";
private String namespace = "spring:session";

/**
* Sessions flush mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Vedran Pavic
*/
public class ReactiveSessionAutoConfigurationRedisTests
extends AbstractSessionAutoConfigurationTests {
Expand All @@ -56,7 +57,7 @@ public void defaultConfig() {
this.contextRunner.withPropertyValues("spring.session.store-type=redis")
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class,
RedisReactiveAutoConfiguration.class))
.run(validateSpringSessionUsesRedis(RedisFlushMode.ON_SAVE));
.run(validateSpringSessionUsesRedis("spring:session:", RedisFlushMode.ON_SAVE));
}

@Test
Expand All @@ -66,7 +67,7 @@ public void defaultConfigWithUniqueStoreImplementation() {
ReactiveMongoOperationsSessionRepository.class))
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class,
RedisReactiveAutoConfiguration.class))
.run(validateSpringSessionUsesRedis(RedisFlushMode.ON_SAVE));
.run(validateSpringSessionUsesRedis("spring:session:", RedisFlushMode.ON_SAVE));
}

@Test
Expand All @@ -77,16 +78,18 @@ public void redisSessionStoreWithCustomizations() {
.withPropertyValues("spring.session.store-type=redis",
"spring.session.redis.namespace=foo",
"spring.session.redis.flush-mode=immediate")
.run(validateSpringSessionUsesRedis(RedisFlushMode.IMMEDIATE));
.run(validateSpringSessionUsesRedis("foo:", RedisFlushMode.IMMEDIATE));
}

private ContextConsumer<AssertableReactiveWebApplicationContext> validateSpringSessionUsesRedis(
RedisFlushMode flushMode) {
String namespace, RedisFlushMode flushMode) {
return (context) -> {
System.out.println(new ConditionEvaluationReportMessage(
context.getBean(ConditionEvaluationReport.class)));
ReactiveRedisOperationsSessionRepository repository = validateSessionRepository(
context, ReactiveRedisOperationsSessionRepository.class);
assertThat(new DirectFieldAccessor(repository).getPropertyValue("namespace"))
.isEqualTo(namespace);
assertThat(new DirectFieldAccessor(repository)
.getPropertyValue("redisFlushMode")).isEqualTo(flushMode);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void redisSessionStoreWithCustomizations() {
"spring.session.redis.namespace=foo",
"spring.session.redis.flush-mode=immediate",
"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 * * *"));
}

Expand Down

0 comments on commit b6d9ae7

Please sign in to comment.