From 4a1f132e073599abf243e5b0dbf03069f693dbf3 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Wed, 29 Jun 2016 11:55:43 -0500 Subject: [PATCH] Add JdbcOperationsSessionRepository overflow test Add test for ensuring JdbcOperationsSessionRepository.cleanupExpiredSessions does not have an overflow when setting the max inactive interval to large values. Issue gh-564 --- .../JdbcOperationsSessionRepositoryTests.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spring-session/src/test/java/org/springframework/session/jdbc/JdbcOperationsSessionRepositoryTests.java b/spring-session/src/test/java/org/springframework/session/jdbc/JdbcOperationsSessionRepositoryTests.java index 6039e90..8ec47f0 100644 --- a/spring-session/src/test/java/org/springframework/session/jdbc/JdbcOperationsSessionRepositoryTests.java +++ b/spring-session/src/test/java/org/springframework/session/jdbc/JdbcOperationsSessionRepositoryTests.java @@ -22,6 +22,7 @@ import java.util.Map; import javax.sql.DataSource; +import org.assertj.core.data.Offset; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -351,6 +352,22 @@ public class JdbcOperationsSessionRepositoryTests { verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), anyLong()); } + // gh-564 + @Test + public void cleanupExpiredSessionsNoOverflow() { + long now = System.currentTimeMillis(); + long toDelete = now - (new Long(Integer.MAX_VALUE) * 1000L); + this.repository.setDefaultMaxInactiveInterval(Integer.MAX_VALUE); + + this.repository.cleanUpExpiredSessions(); + + ArgumentCaptor time = ArgumentCaptor.forClass(Long.class); + assertPropagationRequiresNew(); + verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), + time.capture()); + assertThat(time.getValue()).isCloseTo(toDelete, Offset.offset(5L)); + } + private void assertPropagationRequiresNew() { ArgumentCaptor argument = ArgumentCaptor.forClass(TransactionDefinition.class);