Merge pull request #32205 from vpavic
* gh-32205: Polish "Add property to configure Spring Session Redis repository type" Add property to configure Spring Session Redis repository type Closes gh-32205
This commit is contained in:
commit
4e8f03526e
|
|
@ -22,8 +22,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
|
@ -32,6 +34,7 @@ import org.springframework.session.SessionRepository;
|
||||||
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
|
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
|
||||||
import org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction;
|
import org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction;
|
||||||
import org.springframework.session.data.redis.config.ConfigureRedisAction;
|
import org.springframework.session.data.redis.config.ConfigureRedisAction;
|
||||||
|
import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration;
|
||||||
import org.springframework.session.data.redis.config.annotation.web.http.RedisIndexedHttpSessionConfiguration;
|
import org.springframework.session.data.redis.config.annotation.web.http.RedisIndexedHttpSessionConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -50,6 +53,42 @@ import org.springframework.session.data.redis.config.annotation.web.http.RedisIn
|
||||||
@EnableConfigurationProperties(RedisSessionProperties.class)
|
@EnableConfigurationProperties(RedisSessionProperties.class)
|
||||||
class RedisSessionConfiguration {
|
class RedisSessionConfiguration {
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnProperty(prefix = "spring.session.redis", name = "repository-type", havingValue = "default",
|
||||||
|
matchIfMissing = true)
|
||||||
|
static class DefaultRedisSessionConfiguration {
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
static class SpringBootRedisHttpSessionConfiguration extends RedisHttpSessionConfiguration {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
void customize(SessionProperties sessionProperties, RedisSessionProperties redisSessionProperties,
|
||||||
|
ServerProperties serverProperties) {
|
||||||
|
String cleanupCron = redisSessionProperties.getCleanupCron();
|
||||||
|
if (cleanupCron != null) {
|
||||||
|
throw new InvalidConfigurationPropertyValueException("spring.session.redis.cleanup-cron",
|
||||||
|
cleanupCron,
|
||||||
|
"Cron-based cleanup is only supported when spring.session.redis.repository-type is set to "
|
||||||
|
+ "indexed.");
|
||||||
|
}
|
||||||
|
Duration timeout = sessionProperties
|
||||||
|
.determineTimeout(() -> serverProperties.getServlet().getSession().getTimeout());
|
||||||
|
if (timeout != null) {
|
||||||
|
setMaxInactiveIntervalInSeconds((int) timeout.getSeconds());
|
||||||
|
}
|
||||||
|
setRedisNamespace(redisSessionProperties.getNamespace());
|
||||||
|
setFlushMode(redisSessionProperties.getFlushMode());
|
||||||
|
setSaveMode(redisSessionProperties.getSaveMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnProperty(prefix = "spring.session.redis", name = "repository-type", havingValue = "indexed")
|
||||||
|
static class IndexedRedisSessionConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
ConfigureRedisAction configureRedisAction(RedisSessionProperties redisSessionProperties) {
|
ConfigureRedisAction configureRedisAction(RedisSessionProperties redisSessionProperties) {
|
||||||
|
|
@ -60,10 +99,12 @@ class RedisSessionConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
public static class SpringBootRedisHttpSessionConfiguration extends RedisIndexedHttpSessionConfiguration {
|
static class SpringBootRedisIndexedHttpSessionConfiguration extends RedisIndexedHttpSessionConfiguration {
|
||||||
|
|
||||||
|
private static final String DEFAULT_CLEANUP_CRON = "0 * * * * *";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void customize(SessionProperties sessionProperties, RedisSessionProperties redisSessionProperties,
|
void customize(SessionProperties sessionProperties, RedisSessionProperties redisSessionProperties,
|
||||||
ServerProperties serverProperties) {
|
ServerProperties serverProperties) {
|
||||||
Duration timeout = sessionProperties
|
Duration timeout = sessionProperties
|
||||||
.determineTimeout(() -> serverProperties.getServlet().getSession().getTimeout());
|
.determineTimeout(() -> serverProperties.getServlet().getSession().getTimeout());
|
||||||
|
|
@ -73,7 +114,10 @@ class RedisSessionConfiguration {
|
||||||
setRedisNamespace(redisSessionProperties.getNamespace());
|
setRedisNamespace(redisSessionProperties.getNamespace());
|
||||||
setFlushMode(redisSessionProperties.getFlushMode());
|
setFlushMode(redisSessionProperties.getFlushMode());
|
||||||
setSaveMode(redisSessionProperties.getSaveMode());
|
setSaveMode(redisSessionProperties.getSaveMode());
|
||||||
setCleanupCron(redisSessionProperties.getCleanupCron());
|
String cleanupCron = redisSessionProperties.getCleanupCron();
|
||||||
|
setCleanupCron((cleanupCron != null) ? cleanupCron : DEFAULT_CLEANUP_CRON);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -29,8 +29,6 @@ import org.springframework.session.SaveMode;
|
||||||
@ConfigurationProperties(prefix = "spring.session.redis")
|
@ConfigurationProperties(prefix = "spring.session.redis")
|
||||||
public class RedisSessionProperties {
|
public class RedisSessionProperties {
|
||||||
|
|
||||||
private static final String DEFAULT_CLEANUP_CRON = "0 * * * * *";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Namespace for keys used to store sessions.
|
* Namespace for keys used to store sessions.
|
||||||
*/
|
*/
|
||||||
|
|
@ -55,9 +53,15 @@ public class RedisSessionProperties {
|
||||||
private ConfigureAction configureAction = ConfigureAction.NOTIFY_KEYSPACE_EVENTS;
|
private ConfigureAction configureAction = ConfigureAction.NOTIFY_KEYSPACE_EVENTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cron expression for expired session cleanup job.
|
* Cron expression for expired session cleanup job. Only supported when
|
||||||
|
* repository-type is set to indexed.
|
||||||
*/
|
*/
|
||||||
private String cleanupCron = DEFAULT_CLEANUP_CRON;
|
private String cleanupCron;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of Redis session repository to configure.
|
||||||
|
*/
|
||||||
|
private RepositoryType repositoryType = RepositoryType.DEFAULT;
|
||||||
|
|
||||||
public String getNamespace() {
|
public String getNamespace() {
|
||||||
return this.namespace;
|
return this.namespace;
|
||||||
|
|
@ -99,6 +103,14 @@ public class RedisSessionProperties {
|
||||||
this.configureAction = configureAction;
|
this.configureAction = configureAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RepositoryType getRepositoryType() {
|
||||||
|
return this.repositoryType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepositoryType(RepositoryType repositoryType) {
|
||||||
|
this.repositoryType = repositoryType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategies for configuring and validating Redis.
|
* Strategies for configuring and validating Redis.
|
||||||
*/
|
*/
|
||||||
|
|
@ -117,4 +129,21 @@ public class RedisSessionProperties {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of Redis session repository to auto-configure.
|
||||||
|
*/
|
||||||
|
public enum RepositoryType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-configure a RedisSessionRepository.
|
||||||
|
*/
|
||||||
|
DEFAULT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-configure a RedisIndexedSessionRepository.
|
||||||
|
*/
|
||||||
|
INDEXED
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2749,6 +2749,10 @@
|
||||||
"name": "spring.session.jdbc.save-mode",
|
"name": "spring.session.jdbc.save-mode",
|
||||||
"defaultValue": "on-set-attribute"
|
"defaultValue": "on-set-attribute"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "spring.session.redis.cleanup-cron",
|
||||||
|
"defaultValue": "0 * * * * *"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "spring.session.redis.configure-action",
|
"name": "spring.session.redis.configure-action",
|
||||||
"defaultValue": "notify-keyspace-events"
|
"defaultValue": "notify-keyspace-events"
|
||||||
|
|
@ -2757,6 +2761,10 @@
|
||||||
"name": "spring.session.redis.flush-mode",
|
"name": "spring.session.redis.flush-mode",
|
||||||
"defaultValue": "on-save"
|
"defaultValue": "on-save"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "spring.session.redis.repository-type",
|
||||||
|
"defaultValue": "default"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "spring.session.redis.save-mode",
|
"name": "spring.session.redis.save-mode",
|
||||||
"defaultValue": "on-set-attribute"
|
"defaultValue": "on-set-attribute"
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,9 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.session.RedisSessionConfiguration.SpringBootRedisHttpSessionConfiguration;
|
import org.springframework.boot.autoconfigure.session.RedisSessionConfiguration.IndexedRedisSessionConfiguration.SpringBootRedisIndexedHttpSessionConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
|
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
|
||||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||||
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
|
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
|
||||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||||
|
|
@ -38,6 +39,7 @@ import org.springframework.session.FlushMode;
|
||||||
import org.springframework.session.SaveMode;
|
import org.springframework.session.SaveMode;
|
||||||
import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
|
import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
|
||||||
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
|
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
|
||||||
|
import org.springframework.session.data.redis.RedisSessionRepository;
|
||||||
import org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction;
|
import org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction;
|
||||||
import org.springframework.session.data.redis.config.ConfigureRedisAction;
|
import org.springframework.session.data.redis.config.ConfigureRedisAction;
|
||||||
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
|
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
|
||||||
|
|
@ -70,8 +72,19 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
|
||||||
.withPropertyValues("spring.data.redis.host=" + redis.getHost(),
|
.withPropertyValues("spring.data.redis.host=" + redis.getHost(),
|
||||||
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
||||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE,
|
.run(validateSpringSessionUsesDefaultRedis("spring:session:", FlushMode.ON_SAVE,
|
||||||
SaveMode.ON_SET_ATTRIBUTE, "0 * * * * *"));
|
SaveMode.ON_SET_ATTRIBUTE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void invalidConfigurationPropertyValueWhenDefaultConfigIsUsedWithCustomCronCleanup() {
|
||||||
|
this.contextRunner.withPropertyValues("spring.data.redis.host=" + redis.getHost(),
|
||||||
|
"spring.data.redis.port=" + redis.getFirstMappedPort(), "spring.session.redis.cleanup-cron=0 0 * * * *")
|
||||||
|
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)).run((context) -> {
|
||||||
|
assertThat(context).hasFailed();
|
||||||
|
assertThat(context.getStartupFailure())
|
||||||
|
.hasRootCauseExactlyInstanceOf(InvalidConfigurationPropertyValueException.class);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -79,8 +92,8 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
.withPropertyValues("spring.data.redis.host=" + redis.getHost(),
|
.withPropertyValues("spring.data.redis.host=" + redis.getHost(),
|
||||||
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
||||||
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE,
|
.run(validateSpringSessionUsesDefaultRedis("spring:session:", FlushMode.ON_SAVE,
|
||||||
SaveMode.ON_SET_ATTRIBUTE, "0 * * * * *"));
|
SaveMode.ON_SET_ATTRIBUTE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -89,64 +102,98 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
|
||||||
.withPropertyValues("spring.data.redis.host=" + redis.getHost(),
|
.withPropertyValues("spring.data.redis.host=" + redis.getHost(),
|
||||||
"spring.data.redis.port=" + redis.getFirstMappedPort(), "spring.session.timeout=1m")
|
"spring.data.redis.port=" + redis.getFirstMappedPort(), "spring.session.timeout=1m")
|
||||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)).run((context) -> {
|
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)).run((context) -> {
|
||||||
RedisIndexedSessionRepository repository = validateSessionRepository(context,
|
RedisSessionRepository repository = validateSessionRepository(context,
|
||||||
RedisIndexedSessionRepository.class);
|
RedisSessionRepository.class);
|
||||||
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", 60);
|
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
|
||||||
|
Duration.ofMinutes(1));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void redisSessionStoreWithCustomizations() {
|
void defaultRedisSessionStoreWithCustomizations() {
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
.withPropertyValues("spring.session.redis.namespace=foo", "spring.session.redis.flush-mode=immediate",
|
.withPropertyValues("spring.session.redis.namespace=foo", "spring.session.redis.flush-mode=immediate",
|
||||||
"spring.session.redis.save-mode=on-get-attribute",
|
"spring.session.redis.save-mode=on-get-attribute", "spring.data.redis.host=" + redis.getHost(),
|
||||||
"spring.session.redis.cleanup-cron=0 0 12 * * *", "spring.data.redis.host=" + redis.getHost(),
|
|
||||||
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
||||||
.run(validateSpringSessionUsesRedis("foo:event:0:created:", FlushMode.IMMEDIATE,
|
.run(validateSpringSessionUsesDefaultRedis("foo:", FlushMode.IMMEDIATE, SaveMode.ON_GET_ATTRIBUTE));
|
||||||
SaveMode.ON_GET_ATTRIBUTE, "0 0 12 * * *"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void redisSessionWithConfigureActionNone() {
|
void indexedRedisSessionDefaultConfig() {
|
||||||
|
this.contextRunner.withPropertyValues("spring.session.redis.repository-type=indexed",
|
||||||
|
"spring.data.redis.host=" + redis.getHost(), "spring.data.redis.port=" + redis.getFirstMappedPort())
|
||||||
|
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
|
.run(validateSpringSessionUsesIndexedRedis("spring:session:", FlushMode.ON_SAVE,
|
||||||
|
SaveMode.ON_SET_ATTRIBUTE, "0 * * * * *"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void indexedRedisSessionStoreWithCustomizations() {
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
.withPropertyValues("spring.session.redis.configure-action=none",
|
.withPropertyValues("spring.session.redis.repository-type=indexed",
|
||||||
"spring.data.redis.host=" + redis.getHost(),
|
"spring.session.redis.namespace=foo", "spring.session.redis.flush-mode=immediate",
|
||||||
|
"spring.session.redis.save-mode=on-get-attribute",
|
||||||
|
"spring.session.redis.cleanup-cron=0 0 12 * * *", "spring.data.redis.host=" + redis.getHost(),
|
||||||
|
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
||||||
|
.run(validateSpringSessionUsesIndexedRedis("foo:", FlushMode.IMMEDIATE, SaveMode.ON_GET_ATTRIBUTE,
|
||||||
|
"0 0 12 * * *"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void indexedRedisSessionWithConfigureActionNone() {
|
||||||
|
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
|
.withPropertyValues("spring.session.redis.repository-type=indexed",
|
||||||
|
"spring.session.redis.configure-action=none", "spring.data.redis.host=" + redis.getHost(),
|
||||||
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
||||||
.run(validateStrategy(ConfigureRedisAction.NO_OP.getClass()));
|
.run(validateStrategy(ConfigureRedisAction.NO_OP.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void redisSessionWithDefaultConfigureActionNone() {
|
void indexedRedisSessionWithDefaultConfigureActionNone() {
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
.withPropertyValues("spring.data.redis.host=" + redis.getHost(),
|
.withPropertyValues("spring.session.redis.repository-type=indexed",
|
||||||
|
"spring.data.redis.host=" + redis.getHost(),
|
||||||
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
||||||
.run(validateStrategy(ConfigureNotifyKeyspaceEventsAction.class,
|
.run(validateStrategy(ConfigureNotifyKeyspaceEventsAction.class,
|
||||||
entry("notify-keyspace-events", "gxE")));
|
entry("notify-keyspace-events", "gxE")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void redisSessionWithCustomConfigureRedisActionBean() {
|
void indexedRedisSessionWithCustomConfigureRedisActionBean() {
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
.withUserConfiguration(MaxEntriesRedisAction.class)
|
.withUserConfiguration(MaxEntriesRedisAction.class)
|
||||||
.withPropertyValues("spring.data.redis.host=" + redis.getHost(),
|
.withPropertyValues("spring.session.redis.repository-type=indexed",
|
||||||
|
"spring.data.redis.host=" + redis.getHost(),
|
||||||
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
"spring.data.redis.port=" + redis.getFirstMappedPort())
|
||||||
.run(validateStrategy(MaxEntriesRedisAction.class, entry("set-max-intset-entries", "1024")));
|
.run(validateStrategy(MaxEntriesRedisAction.class, entry("set-max-intset-entries", "1024")));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContextConsumer<AssertableWebApplicationContext> validateSpringSessionUsesRedis(
|
private ContextConsumer<AssertableWebApplicationContext> validateSpringSessionUsesDefaultRedis(String keyNamespace,
|
||||||
String sessionCreatedChannelPrefix, FlushMode flushMode, SaveMode saveMode, String cleanupCron) {
|
FlushMode flushMode, SaveMode saveMode) {
|
||||||
|
return (context) -> {
|
||||||
|
RedisSessionRepository repository = validateSessionRepository(context, RedisSessionRepository.class);
|
||||||
|
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
|
||||||
|
new ServerProperties().getServlet().getSession().getTimeout());
|
||||||
|
assertThat(repository).hasFieldOrPropertyWithValue("keyNamespace", keyNamespace);
|
||||||
|
assertThat(repository).hasFieldOrPropertyWithValue("flushMode", flushMode);
|
||||||
|
assertThat(repository).hasFieldOrPropertyWithValue("saveMode", saveMode);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private ContextConsumer<AssertableWebApplicationContext> validateSpringSessionUsesIndexedRedis(String keyNamespace,
|
||||||
|
FlushMode flushMode, SaveMode saveMode, String cleanupCron) {
|
||||||
return (context) -> {
|
return (context) -> {
|
||||||
RedisIndexedSessionRepository repository = validateSessionRepository(context,
|
RedisIndexedSessionRepository repository = validateSessionRepository(context,
|
||||||
RedisIndexedSessionRepository.class);
|
RedisIndexedSessionRepository.class);
|
||||||
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
|
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
|
||||||
(int) new ServerProperties().getServlet().getSession().getTimeout().getSeconds());
|
(int) new ServerProperties().getServlet().getSession().getTimeout().getSeconds());
|
||||||
assertThat(repository.getSessionCreatedChannelPrefix()).isEqualTo(sessionCreatedChannelPrefix);
|
assertThat(repository).hasFieldOrPropertyWithValue("namespace", keyNamespace);
|
||||||
assertThat(repository).hasFieldOrPropertyWithValue("flushMode", flushMode);
|
assertThat(repository).hasFieldOrPropertyWithValue("flushMode", flushMode);
|
||||||
SpringBootRedisHttpSessionConfiguration configuration = context
|
|
||||||
.getBean(SpringBootRedisHttpSessionConfiguration.class);
|
|
||||||
assertThat(configuration).hasFieldOrPropertyWithValue("cleanupCron", cleanupCron);
|
|
||||||
assertThat(repository).hasFieldOrPropertyWithValue("saveMode", saveMode);
|
assertThat(repository).hasFieldOrPropertyWithValue("saveMode", saveMode);
|
||||||
|
SpringBootRedisIndexedHttpSessionConfiguration configuration = context
|
||||||
|
.getBean(SpringBootRedisIndexedHttpSessionConfiguration.class);
|
||||||
|
assertThat(configuration).hasFieldOrPropertyWithValue("cleanupCron", cleanupCron);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
management.endpoints.web.exposure.include=*
|
management.endpoints.web.exposure.include=*
|
||||||
spring.security.user.name=user
|
spring.security.user.name=user
|
||||||
spring.security.user.password=password
|
spring.security.user.password=password
|
||||||
|
spring.session.redis.repository-type=indexed
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue