Skip to content

Commit

Permalink
#1159 Enable to use property placeholder in cleanupCron property (Re…
Browse files Browse the repository at this point in the history
…dis and JDBC backend)
  • Loading branch information
saiya committed Aug 18, 2018
1 parent 121a449 commit 97503fb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
this.redisFlushMode = attributes.getEnum("redisFlushMode");
String cleanupCron = attributes.getString("cleanupCron");
if (StringUtils.hasText(cleanupCron)) {
this.cleanupCron = cleanupCron;
this.cleanupCron = this.embeddedValueResolver
.resolveStringValue(cleanupCron);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,23 @@ public void resolveValue() {
.getBean(RedisHttpSessionConfiguration.class);
assertThat(ReflectionTestUtils.getField(configuration, "redisNamespace"))
.isEqualTo("myRedisNamespace");
assertThat(ReflectionTestUtils.getField(configuration, "cleanupCron"))
.isEqualTo(CLEANUP_CRON_EXPRESSION);
}

@Test
public void resolveValueByPlaceholder() {
this.context.setEnvironment(new MockEnvironment()
.withProperty("session.redis.namespace", "customRedisNamespace"));
.withProperty("session.redis.namespace", "customRedisNamespace")
.withProperty("session.redis.cleanupCron", CLEANUP_CRON_EXPRESSION));
registerAndRefresh(RedisConfig.class, PropertySourceConfiguration.class,
CustomRedisHttpSessionConfiguration2.class);
RedisHttpSessionConfiguration configuration = this.context
.getBean(RedisHttpSessionConfiguration.class);
assertThat(ReflectionTestUtils.getField(configuration, "redisNamespace"))
.isEqualTo("customRedisNamespace");
assertThat(ReflectionTestUtils.getField(configuration, "cleanupCron"))
.isEqualTo(CLEANUP_CRON_EXPRESSION);
}

@Test
Expand Down Expand Up @@ -346,13 +351,13 @@ public RedisConnectionFactory secondaryRedisConnectionFactory() {
}

@Configuration
@EnableRedisHttpSession(redisNamespace = "myRedisNamespace")
@EnableRedisHttpSession(redisNamespace = "myRedisNamespace", cleanupCron = CLEANUP_CRON_EXPRESSION)
static class CustomRedisHttpSessionConfiguration {

}

@Configuration
@EnableRedisHttpSession(redisNamespace = "${session.redis.namespace}")
@EnableRedisHttpSession(redisNamespace = "${session.redis.namespace}", cleanupCron = "${session.redis.cleanupCron}")
static class CustomRedisHttpSessionConfiguration2 {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
}
String cleanupCron = attributes.getString("cleanupCron");
if (StringUtils.hasText(cleanupCron)) {
this.cleanupCron = cleanupCron;
this.cleanupCron = this.embeddedValueResolver
.resolveStringValue(cleanupCron);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,18 @@ public void customConversionServiceConfiguration() {
}

@Test
public void resolveTableNameByPropertyPlaceholder() {
public void resolveValuesByPropertyPlaceholder() {
this.context.setEnvironment(new MockEnvironment()
.withProperty("session.jdbc.tableName", "custom_session_table"));
.withProperty("session.jdbc.tableName", "custom_session_table")
.withProperty("session.jdbc.cleanupCron", CLEANUP_CRON_EXPRESSION));
registerAndRefresh(DataSourceConfiguration.class,
CustomJdbcHttpSessionConfiguration.class);
JdbcHttpSessionConfiguration configuration = this.context
.getBean(JdbcHttpSessionConfiguration.class);
assertThat(ReflectionTestUtils.getField(configuration, "tableName"))
.isEqualTo("custom_session_table");
assertThat(ReflectionTestUtils.getField(configuration, "cleanupCron"))
.isEqualTo(CLEANUP_CRON_EXPRESSION);
}

private void registerAndRefresh(Class<?>... annotatedClasses) {
Expand Down Expand Up @@ -469,7 +472,7 @@ public ConversionService springSessionConversionService() {

}

@EnableJdbcHttpSession(tableName = "${session.jdbc.tableName}")
@EnableJdbcHttpSession(tableName = "${session.jdbc.tableName}", cleanupCron = "${session.jdbc.cleanupCron}")
static class CustomJdbcHttpSessionConfiguration {

@Bean
Expand Down

0 comments on commit 97503fb

Please sign in to comment.