@Test public void onExpirationUpdatedAddsExpirationTimeRoundedUp() throws Exception { long expirationTimeInMs = RedisSessionExpirationPolicy .expiresInMillis(this.session); long expirationRoundedUpInMs = RedisSessionExpirationPolicy .roundUpToNextMinute(expirationTimeInMs); String expectedExpireKey = this.policy.getExpirationKey(expirationRoundedUpInMs); this.policy.onExpirationUpdated(null, this.session); verify(this.sessionRedisOperations).boundSetOps(expectedExpireKey); verify(this.setOperations).add("expires:" + this.session.getId()); verify(this.setOperations).expire( this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); }
@Test public void onExpirationUpdatedDeleteOnZero() throws Exception { String sessionKey = this.policy.getSessionKey("expires:" + this.session.getId()); long originalExpirationTimeInMs = ONE_MINUTE_AGO; this.session.setMaxInactiveInterval(Duration.ZERO); this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session); // verify the original is removed verify(this.setOperations).remove("expires:" + this.session.getId()); verify(this.setOperations).add("expires:" + this.session.getId()); verify(this.sessionRedisOperations).delete(sessionKey); verify(this.setOperations).expire( this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); }
@Test public void saveJavadocSummary() { RedisSession session = this.redisRepository.createSession(); String sessionKey = "spring:session:sessions:" + session.getId(); String backgroundExpireKey = "spring:session:expirations:" + RedisSessionExpirationPolicy.roundUpToNextMinute( RedisSessionExpirationPolicy.expiresInMillis(session)); String destroyedTriggerKey = "spring:session:sessions:expires:" + session.getId(); given(this.redisOperations.boundHashOps(sessionKey)) .willReturn(this.boundHashOperations); given(this.redisOperations.boundSetOps(backgroundExpireKey)) .willReturn(this.boundSetOperations); given(this.redisOperations.boundValueOps(destroyedTriggerKey)) .willReturn(this.boundValueOperations); this.redisRepository.save(session); // 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 // findById checks if it is expired long fiveMinutesAfterExpires = session.getMaxInactiveInterval().plusMinutes(5) .getSeconds(); verify(this.boundHashOperations).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS); verify(this.boundSetOperations).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS); verify(this.boundSetOperations).add("expires:" + session.getId()); verify(this.boundValueOperations).expire(1800L, TimeUnit.SECONDS); verify(this.boundValueOperations).append(""); }
+ TimeUnit.MINUTES.toSeconds(5); expireOperations.expire(fiveMinutesAfterExpires, TimeUnit.SECONDS); if (sessionExpireInSeconds == 0) { this.redis.delete(sessionKey);