WebSession creation does not block
Closes gh-24027
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.IdGenerator;
|
||||
@@ -111,9 +112,14 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
|
||||
@Override
|
||||
public Mono<WebSession> createWebSession() {
|
||||
|
||||
// Opportunity to clean expired sessions
|
||||
Instant now = this.clock.instant();
|
||||
this.expiredSessionChecker.checkIfNecessary(now);
|
||||
return Mono.fromSupplier(() -> new InMemoryWebSession(now));
|
||||
|
||||
return Mono.fromSupplier(() -> new InMemoryWebSession(now))
|
||||
.subscribeOn(Schedulers.boundedElastic())
|
||||
.cast(WebSession.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,10 @@ import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.web.server.WebSession;
|
||||
@@ -56,6 +59,14 @@ public class InMemoryWebSessionStoreTests {
|
||||
assertThat(session.isStarted()).isTrue();
|
||||
}
|
||||
|
||||
@Disabled // TODO: remove if/when Blockhound is enabled
|
||||
@Test // gh-24027
|
||||
public void createSessionDoesNotBlock() {
|
||||
Mono.defer(() -> this.store.createWebSession())
|
||||
.subscribeOn(Schedulers.parallel())
|
||||
.block();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrieveExpiredSession() {
|
||||
WebSession session = this.store.createWebSession().block();
|
||||
|
||||
Reference in New Issue
Block a user