SessionRepository.getSession(String) -> findById(String)
Issue gh-809
This commit is contained in:
@@ -83,7 +83,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
|
||||
assertThat(this.redis.boundSetOps(usernameSessionKey).members())
|
||||
.contains(toSave.getId());
|
||||
|
||||
Session session = this.repository.getSession(toSave.getId());
|
||||
Session session = this.repository.findById(toSave.getId());
|
||||
|
||||
assertThat(session.getId()).isEqualTo(toSave.getId());
|
||||
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
||||
@@ -94,7 +94,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
|
||||
|
||||
this.repository.delete(toSave.getId());
|
||||
|
||||
assertThat(this.repository.getSession(toSave.getId())).isNull();
|
||||
assertThat(this.repository.findById(toSave.getId())).isNull();
|
||||
assertThat(this.registry.<SessionDestroyedEvent>getEvent(toSave.getId()))
|
||||
.isInstanceOf(SessionDestroyedEvent.class);
|
||||
assertThat(this.redis.boundSetOps(usernameSessionKey).members())
|
||||
@@ -111,14 +111,14 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
|
||||
toSave.setAttribute("a", "b");
|
||||
|
||||
this.repository.save(toSave);
|
||||
toSave = this.repository.getSession(toSave.getId());
|
||||
toSave = this.repository.findById(toSave.getId());
|
||||
|
||||
toSave.setAttribute("1", "2");
|
||||
|
||||
this.repository.save(toSave);
|
||||
toSave = this.repository.getSession(toSave.getId());
|
||||
toSave = this.repository.findById(toSave.getId());
|
||||
|
||||
Session session = this.repository.getSession(toSave.getId());
|
||||
Session session = this.repository.findById(toSave.getId());
|
||||
assertThat(session.getAttributeNames().size()).isEqualTo(2);
|
||||
assertThat(session.<String>getAttribute("a")).isEqualTo(Optional.of("b"));
|
||||
assertThat(session.<String>getAttribute("1")).isEqualTo(Optional.of("2"));
|
||||
@@ -202,7 +202,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
toSave = this.repository.getSession(toSave.getId());
|
||||
toSave = this.repository.findById(toSave.getId());
|
||||
|
||||
toSave.setAttribute("other", "value");
|
||||
this.repository.save(toSave);
|
||||
@@ -262,7 +262,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
RedisSession getSession = this.repository.getSession(toSave.getId());
|
||||
RedisSession getSession = this.repository.findById(toSave.getId());
|
||||
getSession.setAttribute(INDEX_NAME, null);
|
||||
this.repository.save(getSession);
|
||||
|
||||
@@ -281,7 +281,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
RedisSession getSession = this.repository.getSession(toSave.getId());
|
||||
RedisSession getSession = this.repository.findById(toSave.getId());
|
||||
|
||||
getSession.setAttribute(INDEX_NAME, principalNameChanged);
|
||||
this.repository.save(getSession);
|
||||
@@ -367,7 +367,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
toSave = this.repository.getSession(toSave.getId());
|
||||
toSave = this.repository.findById(toSave.getId());
|
||||
|
||||
toSave.setAttribute("other", "value");
|
||||
this.repository.save(toSave);
|
||||
@@ -423,7 +423,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
RedisSession getSession = this.repository.getSession(toSave.getId());
|
||||
RedisSession getSession = this.repository.findById(toSave.getId());
|
||||
getSession.setAttribute(INDEX_NAME, null);
|
||||
this.repository.save(getSession);
|
||||
|
||||
@@ -440,7 +440,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
RedisSession getSession = this.repository.getSession(toSave.getId());
|
||||
RedisSession getSession = this.repository.findById(toSave.getId());
|
||||
|
||||
getSession.setAttribute(SPRING_SECURITY_CONTEXT, this.changedContext);
|
||||
this.repository.save(getSession);
|
||||
|
||||
@@ -76,7 +76,7 @@ public class EnableRedisHttpSessionExpireSessionDestroyedTests<S extends Session
|
||||
if (!this.registry.receivedEvent()) {
|
||||
// Redis makes no guarantees on when an expired event will be fired
|
||||
// we can ensure it gets fired by trying to get the session
|
||||
this.repository.getSession(toSave.getId());
|
||||
this.repository.findById(toSave.getId());
|
||||
synchronized (this.lock) {
|
||||
if (!this.registry.receivedEvent()) {
|
||||
// wait at most a minute
|
||||
|
||||
@@ -40,7 +40,7 @@ public class RedisOperationsSessionRepositoryFlushImmediatelyITests<S extends Se
|
||||
public void savesOnCreate() throws InterruptedException {
|
||||
S created = this.sessionRepository.createSession();
|
||||
|
||||
S getSession = this.sessionRepository.getSession(created.getId());
|
||||
S getSession = this.sessionRepository.findById(created.getId());
|
||||
|
||||
assertThat(getSession).isNotNull();
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ import org.springframework.util.Assert;
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <b>NOTE:</b> The {@link #getSession(String)} method ensures that no expired sessions
|
||||
* <b>NOTE:</b> The {@link #findById(String)} method ensures that no expired sessions
|
||||
* will be returned. This means there is no need to check the expiration before using a
|
||||
* session
|
||||
* </p>
|
||||
@@ -401,7 +401,7 @@ public class RedisOperationsSessionRepository implements
|
||||
this.expirationPolicy.cleanExpiredSessions();
|
||||
}
|
||||
|
||||
public RedisSession getSession(String id) {
|
||||
public RedisSession findById(String id) {
|
||||
return getSession(id, false);
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ public class RedisOperationsSessionRepository implements
|
||||
Map<String, RedisSession> sessions = new HashMap<>(
|
||||
sessionIds.size());
|
||||
for (Object id : sessionIds) {
|
||||
RedisSession session = getSession((String) id);
|
||||
RedisSession session = findById((String) id);
|
||||
if (session != null) {
|
||||
sessions.put(session.getId(), session);
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
// the actual data in the session expires 5 minutes after expiration so the data
|
||||
// can be accessed in expiration events
|
||||
// if the session is retrieved and expired it will not be returned since
|
||||
// getSession checks if it is expired
|
||||
// findById checks if it is expired
|
||||
long fiveMinutesAfterExpires = session.getMaxInactiveInterval().plusMinutes(5)
|
||||
.getSeconds();
|
||||
verify(this.boundHashOperations).expire(fiveMinutesAfterExpires,
|
||||
@@ -232,7 +232,7 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
// the actual data in the session expires 5 minutes after expiration so the data
|
||||
// can be accessed in expiration events
|
||||
// if the session is retrieved and expired it will not be returned since
|
||||
// getSession checks if it is expired
|
||||
// findById checks if it is expired
|
||||
verify(this.boundHashOperations).expire(
|
||||
session.getMaxInactiveInterval().plusMinutes(5).getSeconds(),
|
||||
TimeUnit.SECONDS);
|
||||
@@ -370,7 +370,7 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
.willReturn(this.boundHashOperations);
|
||||
given(this.boundHashOperations.entries()).willReturn(map());
|
||||
|
||||
assertThat(this.redisRepository.getSession(id)).isNull();
|
||||
assertThat(this.redisRepository.findById(id)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -391,7 +391,7 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
expected.getLastAccessedTime().toEpochMilli());
|
||||
given(this.boundHashOperations.entries()).willReturn(map);
|
||||
|
||||
RedisSession session = this.redisRepository.getSession(expected.getId());
|
||||
RedisSession session = this.redisRepository.findById(expected.getId());
|
||||
assertThat(session.getId()).isEqualTo(expected.getId());
|
||||
assertThat(session.getAttributeNames()).isEqualTo(expected.getAttributeNames());
|
||||
assertThat(session.<String>getAttribute(attrName))
|
||||
@@ -414,7 +414,7 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
Instant.now().minus(5, ChronoUnit.MINUTES).toEpochMilli());
|
||||
given(this.boundHashOperations.entries()).willReturn(map);
|
||||
|
||||
assertThat(this.redisRepository.getSession(expiredId)).isNull();
|
||||
assertThat(this.redisRepository.findById(expiredId)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user