Skip to content

Commit

Permalink
Merge pull request spring-projects#316 from tsachev/spring-projectsgh…
Browse files Browse the repository at this point in the history
…-315

Don't send expirations del events when expiration time does not change.
  • Loading branch information
rwinch committed Dec 3, 2015
2 parents e766ad7 + d85624c commit 18a07ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ public void onDelete(ExpiringSession session) {

public void onExpirationUpdated(Long originalExpirationTimeInMilli, ExpiringSession session) {
String keyToExpire = "expires:" + session.getId();
long toExpire = roundUpToNextMinute(expiresInMillis(session));

if(originalExpirationTimeInMilli != null) {
long originalRoundedUp = roundUpToNextMinute(originalExpirationTimeInMilli);
String expireKey = getExpirationKey(originalRoundedUp);
redis.boundSetOps(expireKey).remove(keyToExpire);
if(toExpire != originalRoundedUp) {
String expireKey = getExpirationKey(originalRoundedUp);
redis.boundSetOps(expireKey).remove(keyToExpire);
}
}

long toExpire = roundUpToNextMinute(expiresInMillis(session));

String expireKey = getExpirationKey(toExpire);
BoundSetOperations<Object, Object> expireOperations = redis.boundSetOps(expireKey);
expireOperations.add(keyToExpire);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setup() {
RedisOperationsSessionRepository repository = new RedisOperationsSessionRepository(sessionRedisOperations);
policy = new RedisSessionExpirationPolicy(sessionRedisOperations, repository);
session = new MapSession();
session.setLastAccessedTime(1429116694665L);
session.setLastAccessedTime(1429116694675L);
session.setId("12345");

when(sessionRedisOperations.boundSetOps(anyString())).thenReturn(setOperations);
Expand All @@ -81,6 +81,19 @@ public void onExpirationUpdatedRemovesOriginalExpirationTimeRoundedUp() throws E
verify(setOperations).remove("expires:"+ session.getId());
}

@Test
public void onExpirationUpdatedDoNotSendDeleteWhenExpirationTimeDoesNotChange() throws Exception {
long originalExpirationTimeInMs = RedisSessionExpirationPolicy.expiresInMillis(session) - 10;
long originalRoundedToNextMinInMs = RedisSessionExpirationPolicy.roundUpToNextMinute(originalExpirationTimeInMs);
String originalExpireKey = policy.getExpirationKey(originalRoundedToNextMinInMs);

policy.onExpirationUpdated(originalExpirationTimeInMs, session);

// verify the original is not removed
verify(sessionRedisOperations).boundSetOps(originalExpireKey);
verify(setOperations, never()).remove("expires:"+ session.getId());
}

@Test
public void onExpirationUpdatedAddsExpirationTimeRoundedUp() throws Exception {
long expirationTimeInMs = RedisSessionExpirationPolicy.expiresInMillis(session);
Expand Down

0 comments on commit 18a07ab

Please sign in to comment.