Remove Mockito Spy on SessionRepository in AbstractGemFireIntegrationTests.
Add Mockito Spy on GemFireOperationsSessionRepository reference maintained by the AbstractConcurrentSessionOperationsTestCase class.
This commit is contained in:
@@ -20,17 +20,23 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||||
import static org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSession;
|
import static org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSession;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import edu.umd.cs.mtc.MultithreadedTestCase;
|
import edu.umd.cs.mtc.MultithreadedTestCase;
|
||||||
import edu.umd.cs.mtc.TestFramework;
|
import edu.umd.cs.mtc.TestFramework;
|
||||||
|
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.session.Session;
|
import org.springframework.session.Session;
|
||||||
import org.springframework.session.SessionRepository;
|
import org.springframework.session.SessionRepository;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link AbstractConcurrentSessionOperationsIntegrationTests} class is an abstract base class encapsulating
|
* The {@link AbstractConcurrentSessionOperationsIntegrationTests} class is an abstract base class encapsulating
|
||||||
@@ -56,33 +62,49 @@ public abstract class AbstractConcurrentSessionOperationsIntegrationTests extend
|
|||||||
|
|
||||||
private final AbstractConcurrentSessionOperationsIntegrationTests testInstance;
|
private final AbstractConcurrentSessionOperationsIntegrationTests testInstance;
|
||||||
|
|
||||||
|
private final GemFireOperationsSessionRepository sessionRepository;
|
||||||
|
|
||||||
protected AbstractConcurrentSessionOperationsTestCase(
|
protected AbstractConcurrentSessionOperationsTestCase(
|
||||||
AbstractConcurrentSessionOperationsIntegrationTests testInstance) {
|
@NonNull AbstractConcurrentSessionOperationsIntegrationTests testInstance) {
|
||||||
|
|
||||||
assertThat(testInstance).as("Test class instance must not be null").isNotNull();
|
assertThat(testInstance).as("Test class instance must not be null").isNotNull();
|
||||||
|
|
||||||
this.testInstance = testInstance;
|
this.testInstance = testInstance;
|
||||||
|
|
||||||
|
SessionRepository<?> sessionRepository = this.testInstance.getSessionRepository();
|
||||||
|
|
||||||
|
this.sessionRepository = Optional.ofNullable(sessionRepository)
|
||||||
|
.filter(GemFireOperationsSessionRepository.class::isInstance)
|
||||||
|
.map(GemFireOperationsSessionRepository.class::cast)
|
||||||
|
.map(Mockito::spy)
|
||||||
|
.orElseThrow(() -> newIllegalArgumentException("Expected SessionRepository of type [%1$s]; but was [%2$s]",
|
||||||
|
ObjectUtils.nullSafeClassName(sessionRepository), GemFireOperationsSessionRepository.class.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull @SuppressWarnings("unused")
|
||||||
protected AbstractConcurrentSessionOperationsIntegrationTests getTestInstance() {
|
protected AbstractConcurrentSessionOperationsIntegrationTests getTestInstance() {
|
||||||
return this.testInstance;
|
return this.testInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@NonNull
|
||||||
protected <T extends SessionRepository<? extends Session>> T getSessionRepository() {
|
protected GemFireOperationsSessionRepository getSessionRepository() {
|
||||||
return (T) getTestInstance().getSessionRepository();
|
return this.sessionRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected Session findById(String id) {
|
protected Session findById(String id) {
|
||||||
return getTestInstance().get(id);
|
return getSessionRepository().findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
protected Session newSession() {
|
protected Session newSession() {
|
||||||
return getTestInstance().createSession();
|
return getSessionRepository().createSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T extends Session> T save(T session) {
|
@Nullable
|
||||||
return getTestInstance().save(session);
|
protected <T extends Session> T save(@Nullable T session) {
|
||||||
|
getSessionRepository().save(session);
|
||||||
|
return session;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import org.apache.geode.cache.DataPolicy;
|
import org.apache.geode.cache.DataPolicy;
|
||||||
import org.apache.geode.cache.ExpirationAction;
|
import org.apache.geode.cache.ExpirationAction;
|
||||||
@@ -62,12 +61,14 @@ import org.springframework.util.StringUtils;
|
|||||||
* @see org.apache.geode.cache.GemFireCache
|
* @see org.apache.geode.cache.GemFireCache
|
||||||
* @see org.apache.geode.cache.Region
|
* @see org.apache.geode.cache.Region
|
||||||
* @see org.apache.geode.cache.query.Index
|
* @see org.apache.geode.cache.query.Index
|
||||||
|
* @see org.junit.Test
|
||||||
* @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport
|
* @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport
|
||||||
* @see org.springframework.session.Session
|
* @see org.springframework.session.Session
|
||||||
* @see org.springframework.session.SessionRepository
|
* @see org.springframework.session.SessionRepository
|
||||||
* @see org.springframework.session.events.AbstractSessionEvent
|
* @see org.springframework.session.events.AbstractSessionEvent
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public abstract class AbstractGemFireIntegrationTests extends ForkingClientServerIntegrationTestsSupport {
|
public abstract class AbstractGemFireIntegrationTests extends ForkingClientServerIntegrationTestsSupport {
|
||||||
|
|
||||||
protected static final boolean DEFAULT_ENABLE_QUERY_DEBUGGING = false;
|
protected static final boolean DEFAULT_ENABLE_QUERY_DEBUGGING = false;
|
||||||
@@ -100,10 +101,6 @@ public abstract class AbstractGemFireIntegrationTests extends ForkingClientServe
|
|||||||
this.sessionRepository = this.gemfireSessionRepository != null
|
this.sessionRepository = this.gemfireSessionRepository != null
|
||||||
? this.gemfireSessionRepository
|
? this.gemfireSessionRepository
|
||||||
: this.sessionRepository;
|
: this.sessionRepository;
|
||||||
|
|
||||||
this.sessionRepository = Optional.ofNullable(this.sessionRepository)
|
|
||||||
.map(Mockito::spy)
|
|
||||||
.orElse(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String buildClassPathContainingJarFiles(String... jarFilenames) {
|
protected static String buildClassPathContainingJarFiles(String... jarFilenames) {
|
||||||
|
|||||||
Reference in New Issue
Block a user