Skip to content

Commit ed655da

Browse files
committed
Make reactive session settings configurable through setters
Resolves #11
1 parent 2afebe8 commit ed655da

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,18 @@ public void setMaxInactiveIntervalInSeconds(Integer maxInactiveIntervalInSeconds
145145
this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds;
146146
}
147147

148+
public Integer getMaxInactiveIntervalInSeconds() {
149+
return maxInactiveIntervalInSeconds;
150+
}
151+
148152
public void setCollectionName(String collectionName) {
149153
this.collectionName = collectionName;
150154
}
151155

156+
public String getCollectionName() {
157+
return collectionName;
158+
}
159+
152160
public MongoOperations getBlockingMongoOperations() {
153161
return this.blockingMongoOperations;
154162
}

src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,19 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
9393
public void setEmbeddedValueResolver(StringValueResolver embeddedValueResolver) {
9494
this.embeddedValueResolver = embeddedValueResolver;
9595
}
96+
public Integer getMaxInactiveIntervalInSeconds() {
97+
return maxInactiveIntervalInSeconds;
98+
}
99+
100+
public void setMaxInactiveIntervalInSeconds(Integer maxInactiveIntervalInSeconds) {
101+
this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds;
102+
}
103+
104+
public String getCollectionName() {
105+
return collectionName;
106+
}
107+
108+
public void setCollectionName(String collectionName) {
109+
this.collectionName = collectionName;
110+
}
96111
}

src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919
import static org.mockito.BDDMockito.*;
20+
import static org.mockito.BDDMockito.times;
21+
import static org.mockito.BDDMockito.verify;
2022
import static org.mockito.Mockito.any;
2123
import static org.mockito.Mockito.mock;
2224

@@ -155,6 +157,18 @@ public void reactiveAndBlockingMongoOperationsShouldEnsureIndexing() {
155157
verify(indexOperations, times(1)).ensureIndex(any());
156158
}
157159

160+
@Test
161+
public void overrideCollectionAndInactiveIntervalThroughConfigurationOptions() {
162+
163+
this.context = new AnnotationConfigApplicationContext();
164+
this.context.register(CustomizedReactiveConfiguration.class);
165+
this.context.refresh();
166+
167+
ReactiveMongoOperationsSessionRepository repository = this.context.getBean(ReactiveMongoOperationsSessionRepository.class);
168+
assertThat(repository.getCollectionName()).isEqualTo("custom-collection");
169+
assertThat(repository.getMaxInactiveIntervalInSeconds()).isEqualTo(123);
170+
}
171+
158172
/**
159173
* Reflectively extract the {@link AbstractMongoSessionConverter} from the {@link ReactiveMongoOperationsSessionRepository}.
160174
* This is to avoid expanding the surface area of the API.
@@ -240,4 +254,19 @@ MongoOperations mongoOperations(IndexOperations indexOperations) {
240254
return mongoOperations;
241255
}
242256
}
257+
258+
@EnableSpringWebSession
259+
static class CustomizedReactiveConfiguration extends ReactiveMongoWebSessionConfiguration {
260+
261+
@Bean
262+
ReactiveMongoOperations reactiveMongoOperations() {
263+
return mock(ReactiveMongoOperations.class);
264+
}
265+
266+
public CustomizedReactiveConfiguration() {
267+
268+
this.setCollectionName("custom-collection");
269+
this.setMaxInactiveIntervalInSeconds(123);
270+
}
271+
}
243272
}

0 commit comments

Comments
 (0)