Harmonize naming of reactive components

Closes gh-897
This commit is contained in:
Vedran Pavic
2017-10-24 07:36:25 +02:00
parent 6cfa975b29
commit 00ede81665
14 changed files with 62 additions and 62 deletions

View File

@@ -19,11 +19,11 @@ package sample;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisReactorSession;
import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession;
@Import(EmbeddedRedisConfig.class)
// tag::class[]
@EnableRedisReactorSession
@EnableRedisWebSession
public class HelloWebfluxSessionConfig {
@Bean

View File

@@ -25,7 +25,7 @@ import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.session.events.SessionExpiredEvent;
/**
* A {@link ReactorSessionRepository} backed by a {@link Map} and that uses a
* A {@link ReactiveSessionRepository} backed by a {@link Map} and that uses a
* {@link MapSession}. The injected {@link java.util.Map} can be backed by a distributed
* NoSQL store like Hazelcast, for instance. Note that the supplied map itself is
* responsible for purging the expired sessions.
@@ -38,7 +38,7 @@ import org.springframework.session.events.SessionExpiredEvent;
* @author Rob Winch
* @since 2.0
*/
public class MapReactorSessionRepository implements ReactorSessionRepository<MapSession> {
public class MapReactiveSessionRepository implements ReactiveSessionRepository<MapSession> {
/**
* If non-null, this value is used to override
@@ -54,7 +54,7 @@ public class MapReactorSessionRepository implements ReactorSessionRepository<Map
*
* @param sessions the {@link Map} to use. Cannot be null.
*/
public MapReactorSessionRepository(Map<String, Session> sessions) {
public MapReactiveSessionRepository(Map<String, Session> sessions) {
if (sessions == null) {
throw new IllegalArgumentException("sessions cannot be null");
}

View File

@@ -25,11 +25,11 @@ import reactor.core.publisher.Mono;
* @author Rob Winch
* @since 2.0
*/
public interface ReactorSessionRepository<S extends Session> {
public interface ReactiveSessionRepository<S extends Session> {
/**
* Creates a new {@link Session} that is capable of being persisted by this
* {@link ReactorSessionRepository}.
* {@link ReactiveSessionRepository}.
*
* <p>
* This allows optimizations and customizations in how the {@link Session} is
@@ -38,13 +38,13 @@ public interface ReactorSessionRepository<S extends Session> {
* </p>
*
* @return a new {@link Session} that is capable of being persisted by this
* {@link ReactorSessionRepository}
* {@link ReactiveSessionRepository}
*/
Mono<S> createSession();
/**
* Ensures the {@link Session} created by
* {@link ReactorSessionRepository#createSession()} is saved.
* {@link ReactiveSessionRepository#createSession()} is saved.
*
* <p>
* Some implementations may choose to save as the {@link Session} is updated by

View File

@@ -24,7 +24,7 @@ import org.springframework.context.annotation.Import;
/**
* Add this annotation to a {@code @Configuration} class to configure a {@code WebSessionManager} for a WebFlux
* application. This annotation assumes a {@code ReactorSessionRepository} is defined somewhere in the application
* application. This annotation assumes a {@code ReactiveSessionRepository} is defined somewhere in the application
* context. If not, it will fail with a clear error messages. For example:
*
* <pre>
@@ -34,8 +34,8 @@ import org.springframework.context.annotation.Import;
* public class SpringWebFluxConfig {
*
* {@literal @Bean}
* public ReactorSessionRepository sessionRepository() {
* return new MapReactorSessionRepository();
* public ReactiveSessionRepository sessionRepository() {
* return new MapReactiveSessionRepository();
* }
*
* }

View File

@@ -18,7 +18,7 @@ package org.springframework.session.config.annotation.web.server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.ReactorSessionRepository;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.web.server.session.SpringSessionWebSessionStore;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
@@ -27,7 +27,7 @@ import org.springframework.web.server.session.WebSessionIdResolver;
import org.springframework.web.server.session.WebSessionManager;
/**
* Wire up a {@link WebSessionManager} using a Reactive {@link ReactorSessionRepository} from the application context.
* Wire up a {@link WebSessionManager} using a Reactive {@link ReactiveSessionRepository} from the application context.
*
* @author Greg Turnquist
* @author Rob Winch
@@ -45,13 +45,13 @@ public class SpringWebSessionConfiguration {
private WebSessionIdResolver webSessionIdResolver;
/**
* Configure a {@link WebSessionManager} using a provided {@link ReactorSessionRepository}.
* Configure a {@link WebSessionManager} using a provided {@link ReactiveSessionRepository}.
*
* @param repository - a bean that implements {@link ReactorSessionRepository}.
* @param repository - a bean that implements {@link ReactiveSessionRepository}.
* @return a configured {@link WebSessionManager} registered with a preconfigured name.
*/
@Bean(WebHttpHandlerBuilder.WEB_SESSION_MANAGER_BEAN_NAME)
public WebSessionManager webSessionManager(ReactorSessionRepository<? extends Session> repository) {
public WebSessionManager webSessionManager(ReactiveSessionRepository<? extends Session> repository) {
SpringSessionWebSessionStore<? extends Session> sessionStore = new SpringSessionWebSessionStore<>(repository);
DefaultWebSessionManager manager = new DefaultWebSessionManager();
manager.setSessionStore(sessionStore);

View File

@@ -33,7 +33,7 @@ import java.util.concurrent.atomic.AtomicReference;
import reactor.core.publisher.Mono;
import org.springframework.lang.Nullable;
import org.springframework.session.ReactorSessionRepository;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.Session;
import org.springframework.util.Assert;
import org.springframework.web.server.WebSession;
@@ -42,7 +42,7 @@ import org.springframework.web.server.session.WebSessionStore;
/**
* The {@link WebSessionStore} implementation that provides the {@link WebSession}
* implementation backed by a {@link Session} returned by the
* {@link ReactorSessionRepository}.
* {@link ReactiveSessionRepository}.
*
* @param <S> the {@link Session} type
* @author Rob Winch
@@ -50,13 +50,13 @@ import org.springframework.web.server.session.WebSessionStore;
*/
public class SpringSessionWebSessionStore<S extends Session> implements WebSessionStore {
private final ReactorSessionRepository<S> sessions;
private final ReactiveSessionRepository<S> sessions;
private Clock clock = Clock.system(ZoneOffset.UTC);
public SpringSessionWebSessionStore(ReactorSessionRepository<S> reactorSessionRepository) {
Assert.notNull(reactorSessionRepository, "reactorSessionRepository cannot be null");
this.sessions = reactorSessionRepository;
public SpringSessionWebSessionStore(ReactiveSessionRepository<S> reactiveSessionRepository) {
Assert.notNull(reactiveSessionRepository, "reactiveSessionRepository cannot be null");
this.sessions = reactiveSessionRepository;
}
/**

View File

@@ -29,20 +29,20 @@ import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link MapReactorSessionRepository}.
* Tests for {@link MapReactiveSessionRepository}.
*
* @author Rob Winch
* @since 2.0
*/
public class MapReactorSessionRepositoryTests {
public class MapReactiveSessionRepositoryTests {
private MapReactorSessionRepository repository;
private MapReactiveSessionRepository repository;
private MapSession session;
@Before
public void setup() {
this.repository = new MapReactorSessionRepository(new HashMap<>());
this.repository = new MapReactiveSessionRepository(new HashMap<>());
this.session = new MapSession("session-id");
}
@@ -50,7 +50,7 @@ public class MapReactorSessionRepositoryTests {
public void constructorMapThenFound() {
Map<String, Session> sessions = new HashMap<>();
sessions.put(this.session.getId(), this.session);
this.repository = new MapReactorSessionRepository(sessions);
this.repository = new MapReactiveSessionRepository(sessions);
Session findByIdSession = this.repository.findById(this.session.getId()).block();
assertThat(findByIdSession).isNotNull();
@@ -60,7 +60,7 @@ public class MapReactorSessionRepositoryTests {
@Test(expected = IllegalArgumentException.class)
public void constructorMapWhenNullThenThrowsIllegalArgumentException() {
Map<String, Session> sessions = null;
new MapReactorSessionRepository(sessions);
new MapReactiveSessionRepository(sessions);
}
@Test
@@ -86,7 +86,7 @@ public class MapReactorSessionRepositoryTests {
Map<String, Session> sessions = new ConcurrentHashMap<>();
sessions.put("session-id", this.session);
this.repository = new MapReactorSessionRepository(sessions);
this.repository = new MapReactiveSessionRepository(sessions);
assertThat(this.repository.findById(this.session.getId()).block()).isNull();
assertThat(sessions).isEmpty();

View File

@@ -64,11 +64,11 @@ public class SpringWebSessionConfigurationTests {
assertThat(webSessionManagerFoundByName).isNotNull();
assertThat(webSessionManagerFoundByType).isEqualTo(webSessionManagerFoundByName);
assertThat(this.context.getBean(ReactorSessionRepository.class)).isNotNull();
assertThat(this.context.getBean(ReactiveSessionRepository.class)).isNotNull();
}
@Test
public void missingReactorSessionRepositoryBreaksAppContext() {
public void missingReactiveSessionRepositoryBreaksAppContext() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(BadConfig.class);
@@ -76,7 +76,7 @@ public class SpringWebSessionConfigurationTests {
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
.isThrownBy(this.context::refresh)
.withMessageContaining("Error creating bean with name 'webSessionManager'")
.withMessageContaining("No qualifying bean of type '" + ReactorSessionRepository.class.getCanonicalName());
.withMessageContaining("No qualifying bean of type '" + ReactiveSessionRepository.class.getCanonicalName());
}
@Test
@@ -108,16 +108,16 @@ public class SpringWebSessionConfigurationTests {
static class GoodConfig {
/**
* Use Reactor-friendly, {@link java.util.Map}-backed {@link ReactorSessionRepository} for test purposes.
* Use Reactor-friendly, {@link java.util.Map}-backed {@link ReactiveSessionRepository} for test purposes.
*/
@Bean
ReactorSessionRepository<?> reactorSessionRepository() {
return new MapReactorSessionRepository(new HashMap<>());
ReactiveSessionRepository<?> reactiveSessionRepository() {
return new MapReactiveSessionRepository(new HashMap<>());
}
}
/**
* A configuration where no {@link ReactorSessionRepository} is defined. It's BAD!
* A configuration where no {@link ReactiveSessionRepository} is defined. It's BAD!
*/
@EnableSpringWebSession
static class BadConfig {
@@ -128,8 +128,8 @@ public class SpringWebSessionConfigurationTests {
static class OverrideSessionIdResolver {
@Bean
ReactorSessionRepository<?> reactorSessionRepository() {
return new MapReactorSessionRepository(new HashMap<>());
ReactiveSessionRepository<?> reactiveSessionRepository() {
return new MapReactiveSessionRepository(new HashMap<>());
}
@Bean

View File

@@ -28,7 +28,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import reactor.core.publisher.Mono;
import org.springframework.session.ReactorSessionRepository;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.Session;
import org.springframework.web.server.WebSession;
@@ -47,7 +47,7 @@ import static org.mockito.Mockito.verify;
public class SpringSessionWebSessionStoreTests<S extends Session> {
@Mock
private ReactorSessionRepository<S> sessionRepository;
private ReactiveSessionRepository<S> sessionRepository;
@Mock
private S createSession;

View File

@@ -22,7 +22,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.Session;
import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisReactorSession;
import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@@ -177,7 +177,7 @@ public class ReactiveRedisOperationsSessionRepositoryITests extends AbstractRedi
}
@Configuration
@EnableRedisReactorSession
@EnableRedisWebSession
static class Config extends BaseConfig {
}

View File

@@ -28,19 +28,19 @@ import reactor.core.publisher.Mono;
import org.springframework.data.redis.core.ReactiveRedisOperations;
import org.springframework.session.MapSession;
import org.springframework.session.ReactorSessionRepository;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.Session;
import org.springframework.util.Assert;
/**
* A {@link ReactorSessionRepository} that is implemented using Spring Data's
* A {@link ReactiveSessionRepository} that is implemented using Spring Data's
* {@link ReactiveRedisOperations}.
*
* @author Vedran Pavic
* @since 2.0
*/
public class ReactiveRedisOperationsSessionRepository implements
ReactorSessionRepository<ReactiveRedisOperationsSessionRepository.RedisSession> {
ReactiveSessionRepository<ReactiveRedisOperationsSessionRepository.RedisSession> {
/**
* The default prefix for each key and channel in Redis used by Spring Session.

View File

@@ -23,7 +23,7 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.springframework.session.ReactorSessionRepository;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.config.annotation.web.server.EnableSpringWebSession;
import org.springframework.session.data.redis.RedisFlushMode;
@@ -35,8 +35,8 @@ import org.springframework.session.data.redis.RedisFlushMode;
* annotation, a single {@link ReactiveRedisConnectionFactory} must be provided. For
* example: <pre class="code">
* &#064;Configuration
* &#064;EnableRedisReactorSession
* public class RedisReactorSessionConfig {
* &#064;EnableRedisWebSession
* public class RedisWebSessionConfig {
*
* &#064;Bean
* public LettuceConnectionFactory redisConnectionFactory() {
@@ -46,7 +46,7 @@ import org.springframework.session.data.redis.RedisFlushMode;
* }
* </pre>
*
* More advanced configurations can extend {@link RedisReactorSessionConfiguration}
* More advanced configurations can extend {@link RedisWebSessionConfiguration}
* instead.
*
* @author Vedran Pavic
@@ -56,9 +56,9 @@ import org.springframework.session.data.redis.RedisFlushMode;
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target({ java.lang.annotation.ElementType.TYPE })
@Documented
@Import(RedisReactorSessionConfiguration.class)
@Import(RedisWebSessionConfiguration.class)
@Configuration
public @interface EnableRedisReactorSession {
public @interface EnableRedisWebSession {
int maxInactiveIntervalInSeconds() default 1800;
@@ -83,7 +83,7 @@ public @interface EnableRedisReactorSession {
/**
* <p>
* Sets the flush mode for the Redis sessions. The default is ON_SAVE which only
* updates the backing Redis when {@link ReactorSessionRepository#save(Session)} is
* updates the backing Redis when {@link ReactiveSessionRepository#save(Session)} is
* invoked. In a web environment this happens just before the HTTP response is
* committed.
* </p>

View File

@@ -44,11 +44,11 @@ import org.springframework.web.server.session.WebSessionManager;
* Bean.
*
* @author Vedran Pavic
* @see EnableRedisReactorSession
* @see EnableRedisWebSession
* @since 2.0.0
*/
@Configuration
public class RedisReactorSessionConfiguration extends SpringWebSessionConfiguration
public class RedisWebSessionConfiguration extends SpringWebSessionConfiguration
implements EmbeddedValueResolverAware, ImportAware {
private static final RedisSerializer<String> keySerializer = new StringRedisSerializer();
@@ -101,7 +101,7 @@ public class RedisReactorSessionConfiguration extends SpringWebSessionConfigurat
public void setImportMetadata(AnnotationMetadata importMetadata) {
Map<String, Object> enableAttrMap = importMetadata
.getAnnotationAttributes(EnableRedisReactorSession.class.getName());
.getAnnotationAttributes(EnableRedisWebSession.class.getName());
AnnotationAttributes enableAttrs = AnnotationAttributes.fromMap(enableAttrMap);
if (enableAttrs != null) {

View File

@@ -32,11 +32,11 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link RedisReactorSessionConfiguration}.
* Tests for {@link RedisWebSessionConfiguration}.
*
* @author Vedran Pavic
*/
public class RedisReactorSessionConfigurationTests {
public class RedisWebSessionConfigurationTests {
private static final String REDIS_NAMESPACE = "testNamespace";
@@ -115,25 +115,25 @@ public class RedisReactorSessionConfigurationTests {
}
@Configuration
@EnableRedisReactorSession
@EnableRedisWebSession
static class DefaultConfiguration {
}
@Configuration
@EnableRedisReactorSession(redisNamespace = REDIS_NAMESPACE)
@EnableRedisWebSession(redisNamespace = REDIS_NAMESPACE)
static class CustomNamespaceConfiguration {
}
@Configuration
@EnableRedisReactorSession(maxInactiveIntervalInSeconds = MAX_INACTIVE_INTERVAL_IN_SECONDS)
@EnableRedisWebSession(maxInactiveIntervalInSeconds = MAX_INACTIVE_INTERVAL_IN_SECONDS)
static class CustomMaxInactiveIntervalConfiguration {
}
@Configuration
@EnableRedisReactorSession(redisFlushMode = RedisFlushMode.IMMEDIATE)
@EnableRedisWebSession(redisFlushMode = RedisFlushMode.IMMEDIATE)
static class CustomFlushModeConfiguration {
}