diff --git a/spring-session-data-geode/src/integration-test/java/org/springframework/session/data/gemfire/AbstractGemFireIntegrationTests.java b/spring-session-data-geode/src/integration-test/java/org/springframework/session/data/gemfire/AbstractGemFireIntegrationTests.java index 1365b21..47c2440 100644 --- a/spring-session-data-geode/src/integration-test/java/org/springframework/session/data/gemfire/AbstractGemFireIntegrationTests.java +++ b/spring-session-data-geode/src/integration-test/java/org/springframework/session/data/gemfire/AbstractGemFireIntegrationTests.java @@ -42,8 +42,10 @@ import org.apache.geode.cache.Region; import org.apache.geode.cache.query.Index; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.lang.Nullable; import org.springframework.session.Session; import org.springframework.session.SessionRepository; import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration; @@ -52,22 +54,24 @@ import org.springframework.session.events.AbstractSessionEvent; import org.springframework.util.StringUtils; /** - * {@link AbstractGemFireIntegrationTests} is an abstract base class encapsulating common functionality - * for writing Spring Session for Apache Geode & Pivotal GemFire integration tests. + * Abstract base class encapsulating functionality common to all Spring Session for Apache Geode & Pivotal GemFire + * integration tests. * * @author John Blum * @see java.io.File * @see java.net.URL * @see java.time.Instant - * @see org.apache.geode.cache.DataPolicy + * @see org.junit.Test * @see org.apache.geode.cache.ExpirationAttributes * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region * @see org.apache.geode.cache.query.Index - * @see org.junit.Test + * @see org.springframework.context.ApplicationContext + * @see org.springframework.context.ApplicationListener * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.session.Session * @see org.springframework.session.SessionRepository + * @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration * @see org.springframework.session.events.AbstractSessionEvent * @since 1.1.0 */ @@ -81,13 +85,17 @@ public abstract class AbstractGemFireIntegrationTests extends ForkingClientServe protected static final File WORKING_DIRECTORY = new File(System.getProperty("user.dir")); + protected static final String DEFAULT_GEMFIRE_LOG_LEVEL = "error"; protected static final String DEFAULT_PROCESS_CONTROL_FILENAME = "process.ctl"; protected static final String GEMFIRE_LOG_FILE_NAME = System.getProperty("spring.session.data.gemfire.log.file", "gemfire-server.log"); protected static final String GEMFIRE_LOG_LEVEL = - System.getProperty("spring.session.data.gemfire.log.level", "error"); + System.getProperty("spring.session.data.gemfire.log.level", DEFAULT_GEMFIRE_LOG_LEVEL); + + @Autowired(required = false) + private ApplicationContext applicationContext; @Autowired(required = false) protected GemFireCache gemfireCache; @@ -267,6 +275,26 @@ public abstract class AbstractGemFireIntegrationTests extends ForkingClientServe return processControl; } + @Nullable @SuppressWarnings("unchecked") + protected T getApplicationContext() { + return (T) this.applicationContext; + } + + @Nullable @SuppressWarnings("unchecked") + protected T getGemFireCache() { + return (T) this.gemfireCache; + } + + @Nullable + protected Region getSessionRegion() { + return this.sessions; + } + + @Nullable + protected SessionRepository getSessionRepository() { + return this.sessionRepository; + } + protected void assertValidSession(Session session) { assertThat(session).isNotNull(); @@ -306,10 +334,6 @@ public abstract class AbstractGemFireIntegrationTests extends ForkingClientServe return DEFAULT_ENABLE_QUERY_DEBUGGING; } - protected SessionRepository getSessionRepository() { - return this.sessionRepository; - } - @SuppressWarnings("unused") protected List listRegions(GemFireCache gemfireCache) { @@ -354,6 +378,17 @@ public abstract class AbstractGemFireIntegrationTests extends ForkingClientServe return session; } + protected T forcedTouch(T session) { + + Instant lastAccessedTime = session.getLastAccessedTime(); + + session.setLastAccessedTime(lastAccessedTime.plusMillis(1)); + + assertThat(session.getLastAccessedTime()).isAfter(lastAccessedTime); + + return session; + } + @SuppressWarnings("unchecked") protected T get(String sessionId) { return (T) getSessionRepository().findById(sessionId);