You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2020/06/11 23:56:36 UTC
[geode] branch develop updated: GEODE-8221: Refactor tests to run
in appropriate projects. (#5244)
This is an automated email from the ASF dual-hosted git repository.
jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new cb5990c GEODE-8221: Refactor tests to run in appropriate projects. (#5244)
cb5990c is described below
commit cb5990cd437244bc0ac8abdc6e12552e686e7c7a
Author: Jacob Barrett <jb...@pivotal.io>
AuthorDate: Thu Jun 11 16:55:54 2020 -0700
GEODE-8221: Refactor tests to run in appropriate projects. (#5244)
---
...SessionsBase.java => AbstractSessionsTest.java} | 143 ++++-----
...t.java => AbstractDeltaSessionManagerTest.java} | 187 ++++++------
.../ClientServerSessionCacheJUnitTest.java | 319 ---------------------
...ionsJUnitTest.java => Tomcat7SessionsTest.java} | 10 +-
...st.java => Tomcat7DeltaSessionManagerTest.java} | 6 +-
...st.java => Tomcat8DeltaSessionManagerTest.java} | 2 +-
...st.java => Tomcat9DeltaSessionManagerTest.java} | 2 +-
extensions/geode-modules/build.gradle | 4 +-
...ionsJUnitTest.java => Tomcat6SessionsTest.java} | 4 +-
.../catalina/AbstractSessionCacheTest.java} | 29 +-
.../catalina/ClientServerSessionCacheTest.java | 303 ++++++++++++++++++-
.../session/catalina/DeltaSessionFacadeTest.java} | 6 +-
.../session/catalina/DeltaSessionTest.java} | 74 ++---
.../catalina/PeerToPeerSessionCacheTest.java} | 26 +-
.../SessionExpirationCacheListenerTest.java} | 10 +-
.../DeltaSessionAttributeEventBatchTest.java} | 17 +-
.../DeltaSessionDestroyAttributeEventTest.java} | 9 +-
.../internal/DeltaSessionStatisticsTest.java} | 11 +-
.../DeltaSessionUpdateAttributeEventTest.java} | 10 +-
.../modules/util/CreateRegionFunctionTest.java} | 17 +-
...TouchPartitionedRegionEntriesFunctionTest.java} | 16 +-
.../TouchReplicatedRegionEntriesFunctionTest.java} | 20 +-
22 files changed, 603 insertions(+), 622 deletions(-)
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/TestSessionsBase.java b/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/AbstractSessionsTest.java
similarity index 72%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/TestSessionsBase.java
rename to extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/AbstractSessionsTest.java
index a46eec3..e30a15d 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/TestSessionsBase.java
+++ b/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/AbstractSessionsTest.java
@@ -45,7 +45,7 @@ import org.apache.geode.cache.Region;
import org.apache.geode.modules.session.catalina.DeltaSessionManager;
import org.apache.geode.modules.session.catalina.PeerToPeerCacheLifecycleListener;
-public abstract class TestSessionsBase {
+public abstract class AbstractSessionsTest {
protected static int port;
private static EmbeddedTomcat server;
private static StandardWrapper servlet;
@@ -53,13 +53,13 @@ public abstract class TestSessionsBase {
protected static DeltaSessionManager sessionManager;
// Set up the servers we need
- protected static void setupServer(DeltaSessionManager manager) throws Exception {
+ protected static void setupServer(final DeltaSessionManager manager) throws Exception {
FileUtils.copyDirectory(Paths.get("..", "resources", "integrationTest", "tomcat").toFile(),
new File("./tomcat"));
port = SocketUtils.findAvailableTcpPort();
server = new EmbeddedTomcat(port, "JVM-1");
- PeerToPeerCacheLifecycleListener p2pListener = new PeerToPeerCacheLifecycleListener();
+ final PeerToPeerCacheLifecycleListener p2pListener = new PeerToPeerCacheLifecycleListener();
p2pListener.setProperty(MCAST_PORT, "0");
p2pListener.setProperty(LOG_LEVEL, "config");
server.getEmbedded().addLifecycleListener(p2pListener);
@@ -91,19 +91,20 @@ public abstract class TestSessionsBase {
region.clear();
}
- private WebResponse setCallbackAndExecuteGet(Callback callback) throws IOException, SAXException {
+ private WebResponse setCallbackAndExecuteGet(final Callback callback)
+ throws IOException, SAXException {
servlet.getServletContext().setAttribute("callback", callback);
- WebConversation wc = new WebConversation();
- WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
return wc.getResponse(req);
}
- private WebRequest prepareRequest(String key, String value) {
- WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
+ private WebRequest prepareRequest(final String key, final String value) {
+ final WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
@@ -116,11 +117,11 @@ public abstract class TestSessionsBase {
*/
@Test
public void testSanity() throws Exception {
- WebConversation wc = new WebConversation();
- WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", "null");
- WebResponse response = wc.getResponse(req);
+ final WebResponse response = wc.getResponse(req);
assertEquals("JSESSIONID", response.getNewCookieNames()[0]);
}
@@ -133,12 +134,12 @@ public abstract class TestSessionsBase {
@Test
public void testCallback() throws Exception {
final String helloWorld = "Hello World";
- Callback c = (request, response) -> {
- PrintWriter out = response.getWriter();
+ final Callback c = (request, response) -> {
+ final PrintWriter out = response.getWriter();
out.write(helloWorld);
};
- WebResponse response = setCallbackAndExecuteGet(c);
+ final WebResponse response = setCallbackAndExecuteGet(c);
assertEquals(helloWorld, response.getText());
}
@@ -147,14 +148,14 @@ public abstract class TestSessionsBase {
*/
@Test
public void testIsNew() throws Exception {
- Callback c = (request, response) -> {
- HttpSession session = request.getSession();
+ final Callback c = (request, response) -> {
+ final HttpSession session = request.getSession();
response.getWriter().write(Boolean.toString(session.isNew()));
};
servlet.getServletContext().setAttribute("callback", c);
- WebConversation wc = new WebConversation();
- WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
@@ -172,13 +173,13 @@ public abstract class TestSessionsBase {
*/
@Test
public void testSessionPersists1() throws Exception {
- String key = "value_testSessionPersists1";
- String value = "Foo";
+ final String key = "value_testSessionPersists1";
+ final String value = "Foo";
- WebConversation wc = new WebConversation();
- WebRequest req = prepareRequest(key, value);
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = prepareRequest(key, value);
WebResponse response = wc.getResponse(req);
- String sessionId = response.getNewCookieValue("JSESSIONID");
+ final String sessionId = response.getNewCookieValue("JSESSIONID");
assertNotNull("No apparent session cookie", sessionId);
@@ -196,11 +197,11 @@ public abstract class TestSessionsBase {
*/
@Test
public void testInvalidate() throws Exception {
- String key = "value_testInvalidate";
- String value = "Foo";
+ final String key = "value_testInvalidate";
+ final String value = "Foo";
- WebConversation wc = new WebConversation();
- WebRequest req = prepareRequest(key, value);
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = prepareRequest(key, value);
wc.getResponse(req);
// Invalidate the session
@@ -212,7 +213,7 @@ public abstract class TestSessionsBase {
// The attribute should not be accessible now...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
- WebResponse response = wc.getResponse(req);
+ final WebResponse response = wc.getResponse(req);
assertEquals("", response.getText());
}
@@ -225,11 +226,11 @@ public abstract class TestSessionsBase {
// TestSessions only live for a second
sessionManager.setMaxInactiveInterval(1);
- String key = "value_testSessionExpiration1";
- String value = "Foo";
+ final String key = "value_testSessionExpiration1";
+ final String value = "Foo";
- WebConversation wc = new WebConversation();
- WebRequest req = prepareRequest(key, value);
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = prepareRequest(key, value);
wc.getResponse(req);
// Sleep a while
@@ -238,7 +239,7 @@ public abstract class TestSessionsBase {
// The attribute should not be accessible now...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
- WebResponse response = wc.getResponse(req);
+ final WebResponse response = wc.getResponse(req);
assertEquals("", response.getText());
}
@@ -263,11 +264,11 @@ public abstract class TestSessionsBase {
@Test
public void testSessionExpirationByContainer() throws Exception {
- String key = "value_testSessionExpiration1";
- String value = "Foo";
+ final String key = "value_testSessionExpiration1";
+ final String value = "Foo";
- WebConversation wc = new WebConversation();
- WebRequest req = prepareRequest(key, value);
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = prepareRequest(key, value);
wc.getResponse(req);
// Set the session timeout of this one session.
@@ -281,7 +282,7 @@ public abstract class TestSessionsBase {
// Do a request, which should cause the session to be expired
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
- WebResponse response = wc.getResponse(req);
+ final WebResponse response = wc.getResponse(req);
assertEquals("", response.getText());
}
@@ -291,13 +292,13 @@ public abstract class TestSessionsBase {
*/
@Test
public void testRemoveAttribute() throws Exception {
- String key = "value_testRemoveAttribute";
- String value = "Foo";
+ final String key = "value_testRemoveAttribute";
+ final String value = "Foo";
- WebConversation wc = new WebConversation();
- WebRequest req = prepareRequest(key, value);
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = prepareRequest(key, value);
WebResponse response = wc.getResponse(req);
- String sessionId = response.getNewCookieValue("JSESSIONID");
+ final String sessionId = response.getNewCookieValue("JSESSIONID");
// Implicitly remove the attribute
req.removeParameter("value");
@@ -317,13 +318,13 @@ public abstract class TestSessionsBase {
*/
@Test
public void testBasicRegion() throws Exception {
- String key = "value_testBasicRegion";
- String value = "Foo";
+ final String key = "value_testBasicRegion";
+ final String value = "Foo";
- WebConversation wc = new WebConversation();
- WebRequest req = prepareRequest(key, value);
- WebResponse response = wc.getResponse(req);
- String sessionId = response.getNewCookieValue("JSESSIONID");
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = prepareRequest(key, value);
+ final WebResponse response = wc.getResponse(req);
+ final String sessionId = response.getNewCookieValue("JSESSIONID");
assertEquals(value, region.get(sessionId).getAttribute(key));
}
@@ -333,13 +334,13 @@ public abstract class TestSessionsBase {
*/
@Test
public void testRegionInvalidate() throws Exception {
- String key = "value_testRegionInvalidate";
- String value = "Foo";
+ final String key = "value_testRegionInvalidate";
+ final String value = "Foo";
- WebConversation wc = new WebConversation();
- WebRequest req = prepareRequest(key, value);
- WebResponse response = wc.getResponse(req);
- String sessionId = response.getNewCookieValue("JSESSIONID");
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = prepareRequest(key, value);
+ final WebResponse response = wc.getResponse(req);
+ final String sessionId = response.getNewCookieValue("JSESSIONID");
// Invalidate the session
req.removeParameter("param");
@@ -357,15 +358,15 @@ public abstract class TestSessionsBase {
@Test
public void testMultipleAttributeUpdates() throws Exception {
final String key = "value_testMultipleAttributeUpdates";
- Callback c = (request, response) -> {
- HttpSession session = request.getSession();
+ final Callback c = (request, response) -> {
+ final HttpSession session = request.getSession();
for (int i = 0; i < 1000; i++) {
session.setAttribute(key, Integer.toString(i));
}
};
- WebResponse response = setCallbackAndExecuteGet(c);
- String sessionId = response.getNewCookieValue("JSESSIONID");
+ final WebResponse response = setCallbackAndExecuteGet(c);
+ final String sessionId = response.getNewCookieValue("JSESSIONID");
assertEquals("999", region.get(sessionId).getAttribute(key));
}
@@ -374,13 +375,13 @@ public abstract class TestSessionsBase {
*/
@Test
public void testCommitSessionValveInvalidSession() throws Exception {
- Callback c = (request, response) -> {
- HttpSession session = request.getSession();
+ final Callback c = (request, response) -> {
+ final HttpSession session = request.getSession();
session.invalidate();
response.getWriter().write("done");
};
- WebResponse response = setCallbackAndExecuteGet(c);
+ final WebResponse response = setCallbackAndExecuteGet(c);
assertEquals("done", response.getText());
}
@@ -389,12 +390,12 @@ public abstract class TestSessionsBase {
*/
@Test
public void testExtraSessionsNotCreated() throws Exception {
- Callback c = (request, response) -> {
+ final Callback c = (request, response) -> {
// Do nothing with sessions
response.getWriter().write("done");
};
- WebResponse response = setCallbackAndExecuteGet(c);
+ final WebResponse response = setCallbackAndExecuteGet(c);
assertEquals("done", response.getText());
assertEquals("The region should be empty", 0, region.size());
}
@@ -405,14 +406,14 @@ public abstract class TestSessionsBase {
*/
@Test
public void testLastAccessedTime() throws Exception {
- Callback c = (request, response) -> {
- HttpSession session = request.getSession();
+ final Callback c = (request, response) -> {
+ final HttpSession session = request.getSession();
// Hack to expose the session to our test context
session.getServletContext().setAttribute("session", session);
session.setAttribute("lastAccessTime", session.getLastAccessedTime());
try {
Thread.sleep(100);
- } catch (InterruptedException ex) {
+ } catch (final InterruptedException ex) {
// Ignore.
}
session.setAttribute("somethingElse", 1);
@@ -421,16 +422,16 @@ public abstract class TestSessionsBase {
};
servlet.getServletContext().setAttribute("callback", c);
- WebConversation wc = new WebConversation();
- WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Execute the callback
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
wc.getResponse(req);
- HttpSession session = (HttpSession) servlet.getServletContext().getAttribute("session");
- Long lastAccess = (Long) session.getAttribute("lastAccessTime");
+ final HttpSession session = (HttpSession) servlet.getServletContext().getAttribute("session");
+ final Long lastAccess = (Long) session.getAttribute("lastAccessTime");
assertTrue(
"Last access time not set correctly: " + lastAccess + " not <= "
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/DeltaSessionManagerJUnitTest.java b/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractDeltaSessionManagerTest.java
similarity index 71%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/DeltaSessionManagerJUnitTest.java
rename to extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractDeltaSessionManagerTest.java
index fec8571..ff976b1 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/DeltaSessionManagerJUnitTest.java
+++ b/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractDeltaSessionManagerTest.java
@@ -64,7 +64,7 @@ import org.apache.geode.cache.query.internal.LinkedResultSet;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.modules.session.catalina.internal.DeltaSessionStatistics;
-public abstract class DeltaSessionManagerJUnitTest {
+public abstract class AbstractDeltaSessionManagerTest {
protected DeltaSessionManager manager;
protected AbstractSessionCache sessionCache;
@@ -94,10 +94,10 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void getRegionAttributesIdSetsIdFromSessionCacheWhenAttributesIdIsNull() {
- String regionAttributesId = "attributesIdFromSessionCache";
+ final String regionAttributesId = "attributesIdFromSessionCache";
doReturn(regionAttributesId).when(sessionCache).getDefaultRegionAttributesId();
- String attrId = manager.getRegionAttributesId();
+ final String attrId = manager.getRegionAttributesId();
verify(sessionCache).getDefaultRegionAttributesId();
assertThat(attrId).isEqualTo(regionAttributesId);
@@ -105,10 +105,10 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void getEnableLocalCacheSetsIdFromSessionCacheWhenEnableLocalCacheIsNull() {
- boolean isLocalCacheEnabled = true;
+ final boolean isLocalCacheEnabled = true;
doReturn(isLocalCacheEnabled).when(sessionCache).getDefaultEnableLocalCache();
- Boolean localCacheEnabledValue = manager.getEnableLocalCache();
+ final Boolean localCacheEnabledValue = manager.getEnableLocalCache();
verify(sessionCache).getDefaultEnableLocalCache();
assertThat(localCacheEnabledValue).isEqualTo(isLocalCacheEnabled);
@@ -116,23 +116,23 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void findSessionsReturnsNullWhenIdIsNull() throws IOException {
- Session session = manager.findSession(null);
+ final Session session = manager.findSession(null);
assertThat(session).isNull();
}
@Test
public void findSessionsReturnsNullAndLogsMessageWhenContextNameIsNotValid() throws IOException {
- String sessionId = "sessionId";
- String contextName = "contextName";
- String invalidContextName = "invalidContextName";
+ final String sessionId = "sessionId";
+ final String contextName = "contextName";
+ final String invalidContextName = "invalidContextName";
- DeltaSession expectedSession = mock(DeltaSession.class);
+ final DeltaSession expectedSession = mock(DeltaSession.class);
when(sessionCache.getSession(sessionId)).thenReturn(expectedSession);
when(expectedSession.getContextName()).thenReturn(invalidContextName);
when(context.getName()).thenReturn(contextName);
- Session session = manager.findSession(sessionId);
+ final Session session = manager.findSession(sessionId);
verify(logger).info(anyString());
assertThat(session).isNull();
@@ -140,34 +140,34 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void findSessionsReturnsNullWhenIdIsNotFound() throws IOException {
- String sessionId = "sessionId";
+ final String sessionId = "sessionId";
when(sessionCache.getSession(sessionId)).thenReturn(null);
- Session session = manager.findSession(sessionId);
+ final Session session = manager.findSession(sessionId);
assertThat(session).isNull();
}
@Test
public void findSessionsReturnsProperSessionByIdWhenIdAndContextNameIsValid() throws IOException {
- String sessionId = "sessionId";
- String contextName = "contextName";
+ final String sessionId = "sessionId";
+ final String contextName = "contextName";
- DeltaSession expectedSession = mock(DeltaSession.class);
+ final DeltaSession expectedSession = mock(DeltaSession.class);
when(sessionCache.getSession(sessionId)).thenReturn(expectedSession);
when(expectedSession.getContextName()).thenReturn(contextName);
when(context.getName()).thenReturn(contextName);
- Session session = manager.findSession(sessionId);
+ final Session session = manager.findSession(sessionId);
assertThat(session).isEqualTo(expectedSession);
}
@Test
public void removeProperlyDestroysSessionFromSessionCacheWhenSessionIsNotExpired() {
- DeltaSession sessionToDestroy = mock(DeltaSession.class);
- String sessionId = "sessionId";
+ final DeltaSession sessionToDestroy = mock(DeltaSession.class);
+ final String sessionId = "sessionId";
when(sessionToDestroy.getId()).thenReturn(sessionId);
when(sessionToDestroy.getExpired()).thenReturn(false);
@@ -179,8 +179,8 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void removeDoesNotDestroySessionFromSessionCacheWhenSessionIsExpired() {
- DeltaSession sessionToDestroy = mock(DeltaSession.class);
- String sessionId = "sessionId";
+ final DeltaSession sessionToDestroy = mock(DeltaSession.class);
+ final String sessionId = "sessionId";
when(sessionToDestroy.getId()).thenReturn(sessionId);
when(sessionToDestroy.getExpired()).thenReturn(true);
@@ -192,7 +192,7 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void addPutsSessionIntoSessionCacheAndIncrementsStats() {
- DeltaSession sessionToPut = mock(DeltaSession.class);
+ final DeltaSession sessionToPut = mock(DeltaSession.class);
manager.add(sessionToPut);
@@ -202,16 +202,16 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void listIdsListsAllPresentIds() {
- Set<String> ids = new HashSet<>();
+ final Set<String> ids = new HashSet<>();
ids.add("id1");
ids.add("id2");
ids.add("id3");
when(sessionCache.keySet()).thenReturn(ids);
- String listOutput = manager.listSessionIds();
+ final String listOutput = manager.listSessionIds();
- for (String id : ids) {
+ for (final String id : ids) {
assertThat(listOutput).contains(id);
}
}
@@ -219,10 +219,10 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void loadActivatesAndAddsSingleSessionWithValidIdAndMoreRecentAccessTime()
throws IOException, ClassNotFoundException {
- String contextPath = "contextPath";
- String expectedStoreDir = "";
- DeltaSession newSession = mock(DeltaSession.class);
- DeltaSession existingSession = mock(DeltaSession.class);
+ final String contextPath = "contextPath";
+ final String expectedStoreDir = "";
+ final DeltaSession newSession = mock(DeltaSession.class);
+ final DeltaSession existingSession = mock(DeltaSession.class);
prepareMocksForLoadTest(contextPath, newSession, existingSession, expectedStoreDir);
@@ -235,10 +235,10 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void loadLogsWarningAndDoesNotAddSessionWhenSessionStoreNotFound()
throws IOException, ClassNotFoundException {
- String contextPath = "contextPath";
- String expectedStoreDir = "";
- DeltaSession newSession = mock(DeltaSession.class);
- DeltaSession existingSession = mock(DeltaSession.class);
+ final String contextPath = "contextPath";
+ final String expectedStoreDir = "";
+ final DeltaSession newSession = mock(DeltaSession.class);
+ final DeltaSession existingSession = mock(DeltaSession.class);
prepareMocksForLoadTest(contextPath, newSession, existingSession, expectedStoreDir);
@@ -253,10 +253,10 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void loadDoesNotAddSessionToManagerWithValidIdAndLessRecentAccessTime()
throws IOException, ClassNotFoundException {
- String contextPath = "contextPath";
- String expectedStoreDir = "";
- DeltaSession newSession = mock(DeltaSession.class);
- DeltaSession existingSession = mock(DeltaSession.class);
+ final String contextPath = "contextPath";
+ final String expectedStoreDir = "";
+ final DeltaSession newSession = mock(DeltaSession.class);
+ final DeltaSession existingSession = mock(DeltaSession.class);
prepareMocksForLoadTest(contextPath, newSession, existingSession, expectedStoreDir);
@@ -272,11 +272,11 @@ public abstract class DeltaSessionManagerJUnitTest {
public void unloadWritesSingleSessionToDiskWhenIdIsValid()
throws IOException, NameResolutionException, TypeMismatchException,
QueryInvocationTargetException, FunctionDomainException {
- String sessionId = "sessionId";
- DeltaSession session = mock(DeltaSession.class);
- FileOutputStream fos = mock(FileOutputStream.class);
- BufferedOutputStream bos = mock(BufferedOutputStream.class);
- ObjectOutputStream oos = mock(ObjectOutputStream.class);
+ final String sessionId = "sessionId";
+ final DeltaSession session = mock(DeltaSession.class);
+ final FileOutputStream fos = mock(FileOutputStream.class);
+ final BufferedOutputStream bos = mock(BufferedOutputStream.class);
+ final ObjectOutputStream oos = mock(ObjectOutputStream.class);
prepareMocksForUnloadTest(sessionId, fos, bos, oos, session);
@@ -289,17 +289,17 @@ public abstract class DeltaSessionManagerJUnitTest {
public void unloadDoesNotWriteSessionToDiskAndClosesOutputStreamsWhenOutputStreamThrowsIOException()
throws IOException, NameResolutionException, TypeMismatchException,
QueryInvocationTargetException, FunctionDomainException {
- String sessionId = "sessionId";
- DeltaSession session = mock(DeltaSession.class);
- FileOutputStream fos = mock(FileOutputStream.class);
- BufferedOutputStream bos = mock(BufferedOutputStream.class);
- ObjectOutputStream oos = mock(ObjectOutputStream.class);
+ final String sessionId = "sessionId";
+ final DeltaSession session = mock(DeltaSession.class);
+ final FileOutputStream fos = mock(FileOutputStream.class);
+ final BufferedOutputStream bos = mock(BufferedOutputStream.class);
+ final ObjectOutputStream oos = mock(ObjectOutputStream.class);
prepareMocksForUnloadTest(sessionId, fos, bos, oos, session);
- String exceptionMessage = "Output Stream IOException";
+ final String exceptionMessage = "Output Stream IOException";
- IOException exception = new IOException(exceptionMessage);
+ final IOException exception = new IOException(exceptionMessage);
doThrow(exception).when(manager).getObjectOutputStream(bos);
@@ -315,15 +315,15 @@ public abstract class DeltaSessionManagerJUnitTest {
public void unloadDoesNotWriteSessionToDiskAndClosesOutputStreamsWhenSessionIsWrongClass()
throws IOException, NameResolutionException, TypeMismatchException,
QueryInvocationTargetException, FunctionDomainException {
- String sessionId = "sessionId";
- DeltaSession session = mock(DeltaSession.class);
- FileOutputStream fos = mock(FileOutputStream.class);
- BufferedOutputStream bos = mock(BufferedOutputStream.class);
- ObjectOutputStream oos = mock(ObjectOutputStream.class);
+ final String sessionId = "sessionId";
+ final DeltaSession session = mock(DeltaSession.class);
+ final FileOutputStream fos = mock(FileOutputStream.class);
+ final BufferedOutputStream bos = mock(BufferedOutputStream.class);
+ final ObjectOutputStream oos = mock(ObjectOutputStream.class);
prepareMocksForUnloadTest(sessionId, fos, bos, oos, session);
- Session invalidSession =
+ final Session invalidSession =
mock(Session.class, withSettings().extraInterfaces(DeltaSessionInterface.class));
doReturn(invalidSession).when(manager).findSession(sessionId);
@@ -338,11 +338,11 @@ public abstract class DeltaSessionManagerJUnitTest {
public void successfulUnloadWithClientServerSessionCachePerformsLocalDestroy()
throws IOException, NameResolutionException, TypeMismatchException,
QueryInvocationTargetException, FunctionDomainException {
- String sessionId = "sessionId";
- DeltaSession session = mock(DeltaSession.class);
- FileOutputStream fos = mock(FileOutputStream.class);
- BufferedOutputStream bos = mock(BufferedOutputStream.class);
- ObjectOutputStream oos = mock(ObjectOutputStream.class);
+ final String sessionId = "sessionId";
+ final DeltaSession session = mock(DeltaSession.class);
+ final FileOutputStream fos = mock(FileOutputStream.class);
+ final BufferedOutputStream bos = mock(BufferedOutputStream.class);
+ final ObjectOutputStream oos = mock(ObjectOutputStream.class);
prepareMocksForUnloadTest(sessionId, fos, bos, oos, session);
@@ -357,10 +357,10 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void propertyChangeSetsMaxInactiveIntervalWithCorrectPropertyNameAndValue() {
- String propertyName = "sessionTimeout";
- PropertyChangeEvent event = mock(PropertyChangeEvent.class);
- Context eventContext = mock(Context.class);
- Integer newValue = 1;
+ final String propertyName = "sessionTimeout";
+ final PropertyChangeEvent event = mock(PropertyChangeEvent.class);
+ final Context eventContext = mock(Context.class);
+ final Integer newValue = 1;
when(event.getSource()).thenReturn(eventContext);
when(event.getPropertyName()).thenReturn(propertyName);
@@ -373,9 +373,9 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void propertyChangeDoesNotSetMaxInactiveIntervalWithIncorrectPropertyName() {
- String propertyName = "wrong name";
- PropertyChangeEvent event = mock(PropertyChangeEvent.class);
- Context eventContext = mock(Context.class);
+ final String propertyName = "wrong name";
+ final PropertyChangeEvent event = mock(PropertyChangeEvent.class);
+ final Context eventContext = mock(Context.class);
when(event.getSource()).thenReturn(eventContext);
when(event.getPropertyName()).thenReturn(propertyName);
@@ -387,11 +387,11 @@ public abstract class DeltaSessionManagerJUnitTest {
@Test
public void propertyChangeDoesNotSetNewMaxInactiveIntervalWithCorrectPropertyNameAndInvalidPropertyValue() {
- String propertyName = "sessionTimeout";
- PropertyChangeEvent event = mock(PropertyChangeEvent.class);
- Context eventContext = mock(Context.class);
- Integer newValue = -2;
- Integer oldValue = DEFAULT_MAX_INACTIVE_INTERVAL;
+ final String propertyName = "sessionTimeout";
+ final PropertyChangeEvent event = mock(PropertyChangeEvent.class);
+ final Context eventContext = mock(Context.class);
+ final Integer newValue = -2;
+ final Integer oldValue = DEFAULT_MAX_INACTIVE_INTERVAL;
when(event.getSource()).thenReturn(eventContext);
when(event.getPropertyName()).thenReturn(propertyName);
@@ -403,20 +403,21 @@ public abstract class DeltaSessionManagerJUnitTest {
verify(manager).setMaxInactiveInterval(oldValue);
}
- public void prepareMocksForUnloadTest(String sessionId, FileOutputStream fos,
- BufferedOutputStream bos, ObjectOutputStream oos, DeltaSession session)
+ public void prepareMocksForUnloadTest(final String sessionId, final FileOutputStream fos,
+ final BufferedOutputStream bos, final ObjectOutputStream oos,
+ final DeltaSession session)
throws NameResolutionException, TypeMismatchException, QueryInvocationTargetException,
FunctionDomainException, IOException {
- String regionName = "regionName";
- String contextPath = "contextPath";
- String catalinaBaseSystemProp = "Catalina/Base";
- String systemFileSeparator = "/";
- String expectedStoreDir = catalinaBaseSystemProp + systemFileSeparator + "temp";
+ final String regionName = "regionName";
+ final String contextPath = "contextPath";
+ final String catalinaBaseSystemProp = "Catalina/Base";
+ final String systemFileSeparator = "/";
+ final String expectedStoreDir = catalinaBaseSystemProp + systemFileSeparator + "temp";
- InternalQueryService queryService = mock(InternalQueryService.class);
- Query query = mock(Query.class);
- File store = mock(File.class);
- SelectResults results = new LinkedResultSet();
+ final InternalQueryService queryService = mock(InternalQueryService.class);
+ final Query query = mock(Query.class);
+ final File store = mock(File.class);
+ final SelectResults results = new LinkedResultSet();
when(sessionCache.getCache()).thenReturn(cache);
when(context.getPath()).thenReturn(contextPath);
@@ -438,19 +439,19 @@ public abstract class DeltaSessionManagerJUnitTest {
results.add(sessionId);
}
- public void prepareMocksForLoadTest(String contextPath, DeltaSession newSession,
- DeltaSession existingSession, String expectedStoreDir)
+ public void prepareMocksForLoadTest(final String contextPath, final DeltaSession newSession,
+ final DeltaSession existingSession, String expectedStoreDir)
throws IOException, ClassNotFoundException {
- String catalinaBaseSystemProp = "Catalina/Base";
- String systemFileSeparator = "/";
+ final String catalinaBaseSystemProp = "Catalina/Base";
+ final String systemFileSeparator = "/";
expectedStoreDir = catalinaBaseSystemProp + systemFileSeparator + "temp";
- String newSessionId = "newSessionId";
+ final String newSessionId = "newSessionId";
- File store = mock(File.class);
- FileInputStream fis = mock(FileInputStream.class);
- BufferedInputStream bis = mock(BufferedInputStream.class);
- ObjectInputStream ois = mock(ObjectInputStream.class);
- Loader loader = mock(Loader.class);
+ final File store = mock(File.class);
+ final FileInputStream fis = mock(FileInputStream.class);
+ final BufferedInputStream bis = mock(BufferedInputStream.class);
+ final ObjectInputStream ois = mock(ObjectInputStream.class);
+ final Loader loader = mock(Loader.class);
when(context.getPath()).thenReturn(contextPath);
when(context.getLoader()).thenReturn(loader);
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/ClientServerSessionCacheJUnitTest.java b/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/ClientServerSessionCacheJUnitTest.java
deleted file mode 100644
index e295a3b..0000000
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/ClientServerSessionCacheJUnitTest.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.apache.geode.modules.session.catalina;
-
-import static org.apache.geode.cache.Region.SEPARATOR;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.servlet.http.HttpSession;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-
-import org.apache.geode.Statistics;
-import org.apache.geode.cache.AttributesMutator;
-import org.apache.geode.cache.CacheListener;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.InterestResultPolicy;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache.client.ClientCache;
-import org.apache.geode.cache.client.ClientRegionFactory;
-import org.apache.geode.cache.client.ClientRegionShortcut;
-import org.apache.geode.cache.client.internal.InternalClientCache;
-import org.apache.geode.cache.client.internal.PoolImpl;
-import org.apache.geode.cache.execute.Function;
-import org.apache.geode.cache.execute.FunctionException;
-import org.apache.geode.cache.execute.ResultCollector;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener;
-import org.apache.geode.modules.util.BootstrappingFunction;
-import org.apache.geode.modules.util.CreateRegionFunction;
-import org.apache.geode.modules.util.DebugCacheListener;
-import org.apache.geode.modules.util.RegionConfiguration;
-import org.apache.geode.modules.util.RegionStatus;
-import org.apache.geode.modules.util.SessionCustomExpiry;
-import org.apache.geode.modules.util.TouchPartitionedRegionEntriesFunction;
-import org.apache.geode.modules.util.TouchReplicatedRegionEntriesFunction;
-
-public class ClientServerSessionCacheJUnitTest extends AbstractSessionCacheJUnitTest {
-
- private List<RegionStatus> regionStatusResultList = new ArrayList<>();
- private ClientCache cache = mock(GemFireCacheImpl.class);
- private ResultCollector collector = mock(ResultCollector.class);
- private Statistics stats = mock(Statistics.class);
- @SuppressWarnings("unchecked")
- private ClientRegionFactory<String, HttpSession> regionFactory = mock(ClientRegionFactory.class);
- @SuppressWarnings("unchecked")
- private RegionAttributes<String, HttpSession> attributes = mock(RegionAttributes.class);
-
- @Before
- public void setUp() {
- sessionCache = spy(new ClientServerSessionCache(sessionManager, cache));
- doReturn(emptyExecution).when((ClientServerSessionCache) sessionCache)
- .getExecutionForFunctionOnServers();
- doReturn(emptyExecution).when((ClientServerSessionCache) sessionCache)
- .getExecutionForFunctionOnServersWithArguments(any());
- doReturn(emptyExecution).when((ClientServerSessionCache) sessionCache)
- .getExecutionForFunctionOnServerWithRegionConfiguration(any());
- doReturn(emptyExecution).when((ClientServerSessionCache) sessionCache)
- .getExecutionForFunctionOnRegionWithFilter(any());
-
- when(sessionManager.getLogger()).thenReturn(logger);
- when(sessionManager.getEnableLocalCache()).thenReturn(true);
- when(sessionManager.getRegionName()).thenReturn(sessionRegionName);
- when(sessionManager.getMaxInactiveInterval())
- .thenReturn(RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL);
-
- when(cache.getDistributedSystem()).thenReturn(distributedSystem);
- doReturn(regionFactory).when(cache)
- .createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU);
- when(((InternalClientCache) cache).isClient()).thenReturn(true);
-
- when(emptyExecution.execute(any(Function.class))).thenReturn(collector);
- when(emptyExecution.execute(any(String.class))).thenReturn(collector);
-
- when(collector.getResult()).thenReturn(regionStatusResultList);
-
- when(distributedSystem.createAtomicStatistics(any(), any())).thenReturn(stats);
-
- regionStatusResultList.clear();
- regionStatusResultList.add(RegionStatus.VALID);
- }
-
- @Test
- public void initializeSessionCacheSucceeds() {
- sessionCache.initialize();
-
- verify(emptyExecution).execute(any(BootstrappingFunction.class));
- verify(emptyExecution).execute(CreateRegionFunction.ID);
- verify(cache).createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU);
- verify(regionFactory, times(0)).setStatisticsEnabled(true);
- verify(regionFactory, times(0)).setCustomEntryIdleTimeout(any(SessionCustomExpiry.class));
- verify(regionFactory, times(0)).addCacheListener(any(SessionExpirationCacheListener.class));
- verify(regionFactory).create(sessionRegionName);
- }
-
- @Test
- public void bootstrappingFunctionThrowsException() {
- FunctionException exception = new FunctionException();
-
- ResultCollector exceptionCollector = mock(ResultCollector.class);
-
- when(emptyExecution.execute(new BootstrappingFunction())).thenReturn(exceptionCollector);
- when(exceptionCollector.getResult()).thenThrow(exception);
-
- sessionCache.initialize();
-
- verify(logger).warn("Caught unexpected exception:", exception);
- }
-
-
- @Test
- public void createOrRetrieveRegionThrowsException() {
- RuntimeException exception = new RuntimeException();
- doThrow(exception).when((ClientServerSessionCache) sessionCache).createLocalSessionRegion();
-
- assertThatThrownBy(() -> sessionCache.initialize()).hasCause(exception)
- .isInstanceOf(IllegalStateException.class);
-
- verify(logger).fatal("Unable to create or retrieve region", exception);
-
- }
-
- @Test
- public void createRegionFunctionFailsOnServer() {
- ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
-
- regionStatusResultList.clear();
- regionStatusResultList.add(RegionStatus.INVALID);
-
- assertThatThrownBy(() -> sessionCache.initialize()).isInstanceOf(IllegalStateException.class)
- .hasCauseInstanceOf(IllegalStateException.class).hasMessageContaining(
- "An exception occurred on the server while attempting to create or validate region named "
- + sessionRegionName
- + ". See the server log for additional details.");
-
- verify(logger).fatal(stringCaptor.capture(), any(Exception.class));
- assertThat(stringCaptor.getValue()).isEqualTo("Unable to create or retrieve region");
- }
-
- @Test
- public void nonDefaultMaxTimeoutIntervalSetsExpirationDetails() {
- // Setting the mocked return value of getMaxInactiveInterval to something distinctly not equal
- // to the default
- when(sessionManager.getMaxInactiveInterval())
- .thenReturn(RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL + 1);
-
- sessionCache.initialize();
-
- verify(regionFactory).setStatisticsEnabled(true);
- verify(regionFactory).setCustomEntryIdleTimeout(any(SessionCustomExpiry.class));
- verify(regionFactory).addCacheListener(any(SessionExpirationCacheListener.class));
- }
-
- @Test
- public void createLocalSessionRegionWithoutEnableLocalCache() {
- when(sessionManager.getEnableLocalCache()).thenReturn(false);
- doReturn(regionFactory).when(cache).createClientRegionFactory(ClientRegionShortcut.PROXY);
- when(regionFactory.create(sessionRegionName)).thenReturn(sessionRegion);
-
- sessionCache.initialize();
-
- verify(regionFactory).addCacheListener(any(SessionExpirationCacheListener.class));
- verify(sessionRegion).registerInterest("ALL_KEYS", InterestResultPolicy.KEYS);
- }
-
- @Test
- public void createOrRetrieveRegionWithNonNullSessionRegionDoesNotCreateRegion() {
- @SuppressWarnings("unchecked")
- CacheListener<String, HttpSession>[] cacheListeners =
- new CacheListener[] {new SessionExpirationCacheListener()};
- doReturn(sessionRegion).when(cache).getRegion(sessionRegionName);
- doReturn(attributes).when(sessionRegion).getAttributes();
- doReturn(cacheListeners).when(attributes).getCacheListeners();
-
- sessionCache.initialize();
-
- verify((ClientServerSessionCache) sessionCache, times(0)).createSessionRegionOnServers();
- verify((ClientServerSessionCache) sessionCache, times(0)).createLocalSessionRegion();
- }
-
- @Test
- public void createOrRetrieveRegionWithNonNullSessionRegionAndNoSessionExpirationCacheListenerCreatesListener() {
- @SuppressWarnings("unchecked")
- CacheListener<String, HttpSession>[] cacheListeners =
- new CacheListener[] {new DebugCacheListener()};
- @SuppressWarnings("unchecked")
- AttributesMutator<String, HttpSession> attributesMutator = mock(AttributesMutator.class);
- doReturn(sessionRegion).when(cache).getRegion(sessionRegionName);
- doReturn(attributes).when(sessionRegion).getAttributes();
- doReturn(cacheListeners).when(attributes).getCacheListeners();
- doReturn(attributesMutator).when(sessionRegion).getAttributesMutator();
-
- sessionCache.initialize();
-
- verify(attributesMutator).addCacheListener(any(SessionExpirationCacheListener.class));
- }
-
- @Test
- public void createOrRetrieveRegionWithNonNullSessionProxyRegionRegistersInterestForAllKeys() {
- @SuppressWarnings("unchecked")
- CacheListener<String, HttpSession>[] cacheListeners =
- new CacheListener[] {new SessionExpirationCacheListener()};
- doReturn(sessionRegion).when(cache).getRegion(sessionRegionName);
- doReturn(attributes).when(sessionRegion).getAttributes();
- doReturn(cacheListeners).when(attributes).getCacheListeners();
- when(attributes.getDataPolicy()).thenReturn(DataPolicy.EMPTY);
-
- sessionCache.initialize();
-
- verify(sessionRegion).registerInterest("ALL_KEYS", InterestResultPolicy.KEYS);
- }
-
- @Test
- public void touchSessionsInvokesPRFunctionForPRAndDoesNotThrowExceptionWhenFunctionDoesNotThrowException() {
- Set<String> sessionIds = new HashSet<>();
-
- when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.PARTITION.toString());
-
- sessionCache.touchSessions(sessionIds);
-
- verify(emptyExecution).execute(TouchPartitionedRegionEntriesFunction.ID);
- }
-
- @Test
- public void touchSessionsInvokesPRFunctionForPRAndThrowsExceptionWhenFunctionThrowsException() {
- Set<String> sessionIds = new HashSet<>();
- FunctionException exception = new FunctionException();
- ResultCollector exceptionCollector = mock(ResultCollector.class);
-
- when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.PARTITION.toString());
- when(emptyExecution.execute(TouchPartitionedRegionEntriesFunction.ID))
- .thenReturn(exceptionCollector);
- when(exceptionCollector.getResult()).thenThrow(exception);
-
- sessionCache.touchSessions(sessionIds);
- verify(logger).warn("Caught unexpected exception:", exception);
- }
-
- @Test
- public void touchSessionsInvokesRRFunctionForRRAndDoesNotThrowExceptionWhenFunctionDoesNotThrowException() {
- // Need to invoke this to set the session region
- when(regionFactory.create(sessionRegionName)).thenReturn(sessionRegion);
- sessionCache.initialize();
-
- Set<String> sessionIds = new HashSet<>();
-
- when(sessionRegion.getFullPath()).thenReturn(SEPARATOR + sessionRegionName);
- when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.REPLICATE.toString());
-
- sessionCache.touchSessions(sessionIds);
- verify(emptyExecution).execute(TouchReplicatedRegionEntriesFunction.ID);
- }
-
- @Test
- public void touchSessionsInvokesRRFunctionForRRAndThrowsExceptionWhenFunctionThrowsException() {
- // Need to invoke this to set the session region
- when(regionFactory.create(sessionRegionName)).thenReturn(sessionRegion);
- sessionCache.initialize();
-
- Set<String> sessionIds = new HashSet<>();
- FunctionException exception = new FunctionException();
- ResultCollector exceptionCollector = mock(ResultCollector.class);
-
- when(sessionRegion.getFullPath()).thenReturn(SEPARATOR + sessionRegionName);
- when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.REPLICATE.toString());
- when(emptyExecution.execute(TouchReplicatedRegionEntriesFunction.ID))
- .thenReturn(exceptionCollector);
- when(exceptionCollector.getResult()).thenThrow(exception);
-
- sessionCache.touchSessions(sessionIds);
- verify(logger).warn("Caught unexpected exception:", exception);
- }
-
- @Test
- public void isBackingCacheEnabledReturnsTrueWhenCommitValveFailfastDisabled() {
- assertThat(sessionCache.isBackingCacheAvailable()).isTrue();
- }
-
- @Test
- public void isBackingCacheEnabledReturnsValueWhenCommitValveFailfastEnabled() {
- boolean backingCacheEnabled = false;
- PoolImpl pool = mock(PoolImpl.class);
-
- when(sessionManager.isCommitValveFailfastEnabled()).thenReturn(true);
- doReturn(pool).when((ClientServerSessionCache) sessionCache).findPoolInPoolManager();
- when(pool.isPrimaryUpdaterAlive()).thenReturn(backingCacheEnabled);
-
- assertThat(sessionCache.isBackingCacheAvailable()).isEqualTo(backingCacheEnabled);
- }
-}
diff --git a/extensions/geode-modules-tomcat7/src/integrationTest/java/org/apache/geode/modules/session/Tomcat7SessionsJUnitTest.java b/extensions/geode-modules-tomcat7/src/integrationTest/java/org/apache/geode/modules/session/Tomcat7SessionsTest.java
similarity index 87%
rename from extensions/geode-modules-tomcat7/src/integrationTest/java/org/apache/geode/modules/session/Tomcat7SessionsJUnitTest.java
rename to extensions/geode-modules-tomcat7/src/integrationTest/java/org/apache/geode/modules/session/Tomcat7SessionsTest.java
index 2c048d5..f37eedd 100644
--- a/extensions/geode-modules-tomcat7/src/integrationTest/java/org/apache/geode/modules/session/Tomcat7SessionsJUnitTest.java
+++ b/extensions/geode-modules-tomcat7/src/integrationTest/java/org/apache/geode/modules/session/Tomcat7SessionsTest.java
@@ -28,7 +28,7 @@ import org.apache.geode.modules.session.catalina.Tomcat7DeltaSessionManager;
import org.apache.geode.test.junit.categories.HttpSessionTest;
@Category({HttpSessionTest.class})
-public class Tomcat7SessionsJUnitTest extends TestSessionsBase {
+public class Tomcat7SessionsTest extends AbstractSessionsTest {
// Set up the session manager we need
@BeforeClass
@@ -45,11 +45,11 @@ public class Tomcat7SessionsJUnitTest extends TestSessionsBase {
// TestSessions only live for a minute
sessionManager.getTheContext().setSessionTimeout(1);
- String key = "value_testSessionExpiration1";
- String value = "Foo";
+ final String key = "value_testSessionExpiration1";
+ final String value = "Foo";
- WebConversation wc = new WebConversation();
- WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
+ final WebConversation wc = new WebConversation();
+ final WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Set an attribute
req.setParameter("cmd", QueryCommand.SET.name());
diff --git a/extensions/geode-modules-tomcat7/src/test/java/org/apache/geode/modules/session/catalina/Tomcat7DeltaSessionManagerJUnitTest.java b/extensions/geode-modules-tomcat7/src/test/java/org/apache/geode/modules/session/catalina/Tomcat7DeltaSessionManagerTest.java
similarity index 96%
rename from extensions/geode-modules-tomcat7/src/test/java/org/apache/geode/modules/session/catalina/Tomcat7DeltaSessionManagerJUnitTest.java
rename to extensions/geode-modules-tomcat7/src/test/java/org/apache/geode/modules/session/catalina/Tomcat7DeltaSessionManagerTest.java
index f1bee51..e6fd534 100644
--- a/extensions/geode-modules-tomcat7/src/test/java/org/apache/geode/modules/session/catalina/Tomcat7DeltaSessionManagerJUnitTest.java
+++ b/extensions/geode-modules-tomcat7/src/test/java/org/apache/geode/modules/session/catalina/Tomcat7DeltaSessionManagerTest.java
@@ -34,7 +34,7 @@ import org.junit.Test;
import org.apache.geode.internal.cache.GemFireCacheImpl;
-public class Tomcat7DeltaSessionManagerJUnitTest extends DeltaSessionManagerJUnitTest {
+public class Tomcat7DeltaSessionManagerTest extends AbstractDeltaSessionManagerTest {
private Pipeline pipeline;
@Before
@@ -118,8 +118,8 @@ public class Tomcat7DeltaSessionManagerJUnitTest extends DeltaSessionManagerJUni
@Test
public void setContainerSetsProperContainerAndMaxInactiveInterval() {
- Context container = mock(Context.class);
- int containerMaxInactiveInterval = 3;
+ final Context container = mock(Context.class);
+ final int containerMaxInactiveInterval = 3;
doReturn(containerMaxInactiveInterval).when(container).getSessionTimeout();
diff --git a/extensions/geode-modules-tomcat8/src/test/java/org/apache/geode/modules/session/catalina/Tomcat8DeltaSessionManagerJUnitTest.java b/extensions/geode-modules-tomcat8/src/test/java/org/apache/geode/modules/session/catalina/Tomcat8DeltaSessionManagerTest.java
similarity index 98%
rename from extensions/geode-modules-tomcat8/src/test/java/org/apache/geode/modules/session/catalina/Tomcat8DeltaSessionManagerJUnitTest.java
rename to extensions/geode-modules-tomcat8/src/test/java/org/apache/geode/modules/session/catalina/Tomcat8DeltaSessionManagerTest.java
index 1bf7939..c293be3 100644
--- a/extensions/geode-modules-tomcat8/src/test/java/org/apache/geode/modules/session/catalina/Tomcat8DeltaSessionManagerJUnitTest.java
+++ b/extensions/geode-modules-tomcat8/src/test/java/org/apache/geode/modules/session/catalina/Tomcat8DeltaSessionManagerTest.java
@@ -33,7 +33,7 @@ import org.junit.Test;
import org.apache.geode.internal.cache.GemFireCacheImpl;
-public class Tomcat8DeltaSessionManagerJUnitTest extends DeltaSessionManagerJUnitTest {
+public class Tomcat8DeltaSessionManagerTest extends AbstractDeltaSessionManagerTest {
private Pipeline pipeline;
@Before
diff --git a/extensions/geode-modules-tomcat9/src/test/java/org/apache/geode/modules/session/catalina/Tomcat9DeltaSessionManagerJUnitTest.java b/extensions/geode-modules-tomcat9/src/test/java/org/apache/geode/modules/session/catalina/Tomcat9DeltaSessionManagerTest.java
similarity index 98%
rename from extensions/geode-modules-tomcat9/src/test/java/org/apache/geode/modules/session/catalina/Tomcat9DeltaSessionManagerJUnitTest.java
rename to extensions/geode-modules-tomcat9/src/test/java/org/apache/geode/modules/session/catalina/Tomcat9DeltaSessionManagerTest.java
index cc55763..5cdeb058 100644
--- a/extensions/geode-modules-tomcat9/src/test/java/org/apache/geode/modules/session/catalina/Tomcat9DeltaSessionManagerJUnitTest.java
+++ b/extensions/geode-modules-tomcat9/src/test/java/org/apache/geode/modules/session/catalina/Tomcat9DeltaSessionManagerTest.java
@@ -33,7 +33,7 @@ import org.junit.Test;
import org.apache.geode.internal.cache.GemFireCacheImpl;
-public class Tomcat9DeltaSessionManagerJUnitTest extends DeltaSessionManagerJUnitTest {
+public class Tomcat9DeltaSessionManagerTest extends AbstractDeltaSessionManagerTest {
private Pipeline pipeline;
@Before
diff --git a/extensions/geode-modules/build.gradle b/extensions/geode-modules/build.gradle
index db3d6ab..745d9b8 100644
--- a/extensions/geode-modules/build.gradle
+++ b/extensions/geode-modules/build.gradle
@@ -22,7 +22,6 @@ apply from: "${rootDir}/${scriptDir}/standard-subproject-configuration.gradle"
evaluationDependsOn(":geode-core")
-
dependencies {
compile(platform(project(':boms:geode-all-bom')))
implementation(project(':geode-logging'))
@@ -32,6 +31,9 @@ dependencies {
integrationTestImplementation(project(':extensions:geode-modules-test')) {
exclude module: 'geode-modules'
}
+ testImplementation(project(':extensions:geode-modules-test')) {
+ exclude module: 'geode-modules'
+ }
integrationTestImplementation(project(':geode-dunit')) {
exclude module: 'geode-core'
}
diff --git a/extensions/geode-modules/src/integrationTest/java/org/apache/geode/modules/session/Tomcat6SessionsJUnitTest.java b/extensions/geode-modules/src/integrationTest/java/org/apache/geode/modules/session/Tomcat6SessionsTest.java
similarity index 88%
rename from extensions/geode-modules/src/integrationTest/java/org/apache/geode/modules/session/Tomcat6SessionsJUnitTest.java
rename to extensions/geode-modules/src/integrationTest/java/org/apache/geode/modules/session/Tomcat6SessionsTest.java
index a80feb2..47da3f4 100644
--- a/extensions/geode-modules/src/integrationTest/java/org/apache/geode/modules/session/Tomcat6SessionsJUnitTest.java
+++ b/extensions/geode-modules/src/integrationTest/java/org/apache/geode/modules/session/Tomcat6SessionsTest.java
@@ -21,8 +21,8 @@ import org.apache.geode.modules.session.catalina.Tomcat6DeltaSessionManager;
import org.apache.geode.test.junit.categories.SessionTest;
@Category(SessionTest.class)
-// TODO: Remove the entire class once Tomcat6DeltaSessionManager is removed from the product.
-public class Tomcat6SessionsJUnitTest extends TestSessionsBase {
+@Deprecated
+public class Tomcat6SessionsTest extends AbstractSessionsTest {
@BeforeClass
public static void setupClass() throws Exception {
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractSessionCacheJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/AbstractSessionCacheTest.java
similarity index 84%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractSessionCacheJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/AbstractSessionCacheTest.java
index 04cc183..32cecd8 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractSessionCacheJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/AbstractSessionCacheTest.java
@@ -15,6 +15,7 @@
package org.apache.geode.modules.session.catalina;
+import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
@@ -25,6 +26,8 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.util.List;
+
import javax.servlet.http.HttpSession;
import org.apache.juli.logging.Log;
@@ -38,28 +41,27 @@ import org.apache.geode.cache.execute.Execution;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.modules.util.RegionConfiguration;
-public abstract class AbstractSessionCacheJUnitTest {
+public abstract class AbstractSessionCacheTest {
protected String sessionRegionName = "sessionRegion";
- private String sessionRegionAttributesId = RegionShortcut.PARTITION.toString();
- private int nonDefaultMaxInactiveInterval = RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL + 1;
- private boolean gatewayDeltaReplicationEnabled = true;
- private boolean gatewayReplicationEnabled = true;
- private boolean enableDebugListener = true;
+ private final String sessionRegionAttributesId = RegionShortcut.PARTITION.toString();
+ private final boolean gatewayDeltaReplicationEnabled = true;
+ private final boolean gatewayReplicationEnabled = true;
+ private final boolean enableDebugListener = true;
protected SessionManager sessionManager = mock(SessionManager.class);
- @SuppressWarnings("unchecked")
- protected Region<String, HttpSession> sessionRegion = mock(Region.class);
+ protected Region<String, HttpSession> sessionRegion = uncheckedCast(mock(Region.class));
protected DistributedSystem distributedSystem = mock(DistributedSystem.class);
protected Log logger = mock(Log.class);
- protected Execution emptyExecution = mock(Execution.class);
+ protected Execution<Object, Object, List<Object>> emptyExecution =
+ uncheckedCast(mock(Execution.class));
protected AbstractSessionCache sessionCache;
@Test
public void createRegionConfigurationSetsAppropriateValuesWithDefaultMaxInactiveInterval() {
- RegionConfiguration config = spy(new RegionConfiguration());
+ final RegionConfiguration config = spy(new RegionConfiguration());
doReturn(config).when(sessionCache).getNewRegionConfiguration();
when(sessionManager.getRegionName()).thenReturn(sessionRegionName);
@@ -84,11 +86,12 @@ public abstract class AbstractSessionCacheJUnitTest {
@Test
public void createRegionConfigurationSetsAppropriateValuesWithNonDefaultMaxInactiveInterval() {
- RegionConfiguration config = spy(new RegionConfiguration());
+ final RegionConfiguration config = spy(new RegionConfiguration());
doReturn(config).when(sessionCache).getNewRegionConfiguration();
when(sessionManager.getRegionName()).thenReturn(sessionRegionName);
when(sessionManager.getRegionAttributesId()).thenReturn(sessionRegionAttributesId);
+ final int nonDefaultMaxInactiveInterval = RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL + 1;
when(sessionManager.getMaxInactiveInterval()).thenReturn(nonDefaultMaxInactiveInterval);
when(sessionManager.getEnableGatewayDeltaReplication())
.thenReturn(gatewayDeltaReplicationEnabled);
@@ -108,8 +111,8 @@ public abstract class AbstractSessionCacheJUnitTest {
@Test
public void destroySessionDoesNotThrowExceptionWhenGetOperatingRegionThrowsEntryNotFoundException() {
- EntryNotFoundException exception = new EntryNotFoundException("Entry not found.");
- String sessionId = "sessionId";
+ final EntryNotFoundException exception = new EntryNotFoundException("Entry not found.");
+ final String sessionId = "sessionId";
// For Client/Server the operating Region is always the session Region, for peer to peer this is
// only true when
// local caching is not enabled. For the purposes of this test the behavior is equivalent
diff --git a/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/ClientServerSessionCacheTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/ClientServerSessionCacheTest.java
index 88fb0dd..d89901b 100644
--- a/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/ClientServerSessionCacheTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/ClientServerSessionCacheTest.java
@@ -12,28 +12,321 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
+
package org.apache.geode.modules.session.catalina;
+import static org.apache.geode.cache.Region.SEPARATOR;
+import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.http.HttpSession;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.apache.geode.Statistics;
+import org.apache.geode.cache.AttributesMutator;
+import org.apache.geode.cache.CacheListener;
+import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.InterestResultPolicy;
import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientRegionFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.client.internal.InternalClientCache;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.execute.Function;
+import org.apache.geode.cache.execute.FunctionException;
+import org.apache.geode.cache.execute.ResultCollector;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener;
+import org.apache.geode.modules.util.BootstrappingFunction;
+import org.apache.geode.modules.util.CreateRegionFunction;
+import org.apache.geode.modules.util.DebugCacheListener;
+import org.apache.geode.modules.util.RegionConfiguration;
+import org.apache.geode.modules.util.RegionStatus;
+import org.apache.geode.modules.util.SessionCustomExpiry;
+import org.apache.geode.modules.util.TouchPartitionedRegionEntriesFunction;
+import org.apache.geode.modules.util.TouchReplicatedRegionEntriesFunction;
+
+public class ClientServerSessionCacheTest extends AbstractSessionCacheTest {
+
+ private final List<Object> regionStatusResultList = new ArrayList<>();
+ private final ClientCache cache = mock(GemFireCacheImpl.class);
+ private final ResultCollector<Object, List<Object>> collector =
+ uncheckedCast(mock(ResultCollector.class));
+ private final Statistics stats = mock(Statistics.class);
+ private final ClientRegionFactory<String, HttpSession> regionFactory =
+ uncheckedCast(mock(ClientRegionFactory.class));
+ private final RegionAttributes<String, HttpSession> attributes =
+ uncheckedCast(mock(RegionAttributes.class));
+
+ @Before
+ public void setUp() {
+ sessionCache = spy(new ClientServerSessionCache(sessionManager, cache));
+ doReturn(emptyExecution).when((ClientServerSessionCache) sessionCache)
+ .getExecutionForFunctionOnServers();
+ doReturn(emptyExecution).when((ClientServerSessionCache) sessionCache)
+ .getExecutionForFunctionOnServersWithArguments(any());
+ doReturn(emptyExecution).when((ClientServerSessionCache) sessionCache)
+ .getExecutionForFunctionOnServerWithRegionConfiguration(any());
+ doReturn(emptyExecution).when((ClientServerSessionCache) sessionCache)
+ .getExecutionForFunctionOnRegionWithFilter(any());
+
+ when(sessionManager.getLogger()).thenReturn(logger);
+ when(sessionManager.getEnableLocalCache()).thenReturn(true);
+ when(sessionManager.getRegionName()).thenReturn(sessionRegionName);
+ when(sessionManager.getMaxInactiveInterval())
+ .thenReturn(RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL);
+
+ when(cache.getDistributedSystem()).thenReturn(distributedSystem);
+ doReturn(regionFactory).when(cache)
+ .createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU);
+ doReturn(sessionRegion).when(regionFactory).create(any());
+ when(((InternalClientCache) cache).isClient()).thenReturn(true);
+
+ when(emptyExecution.execute(any(Function.class))).thenReturn(collector);
+ when(emptyExecution.execute(any(String.class))).thenReturn(collector);
+
+ when(collector.getResult()).thenReturn(regionStatusResultList);
+
+ when(distributedSystem.createAtomicStatistics(any(), any())).thenReturn(stats);
+
+ regionStatusResultList.clear();
+ regionStatusResultList.add(RegionStatus.VALID);
+ }
+
+ @Test
+ public void initializeSessionCacheSucceeds() {
+ sessionCache.initialize();
+
+ verify(emptyExecution).execute(any(BootstrappingFunction.class));
+ verify(emptyExecution).execute(CreateRegionFunction.ID);
+ verify(cache).createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU);
+ verify(regionFactory, times(0)).setStatisticsEnabled(true);
+ verify(regionFactory, times(0)).setCustomEntryIdleTimeout(any(SessionCustomExpiry.class));
+ verify(regionFactory, times(0)).addCacheListener(any(SessionExpirationCacheListener.class));
+ verify(regionFactory).create(sessionRegionName);
+ }
+
+ @Test
+ public void bootstrappingFunctionThrowsException() {
+ final FunctionException exception = new FunctionException();
+
+ final ResultCollector<Object, List<Object>> exceptionCollector =
+ uncheckedCast(mock(ResultCollector.class));
+
+ when(emptyExecution.execute(new BootstrappingFunction())).thenReturn(exceptionCollector);
+ when(exceptionCollector.getResult()).thenThrow(exception);
+
+ sessionCache.initialize();
+
+ verify(logger).warn("Caught unexpected exception:", exception);
+ }
+
+
+ @Test
+ public void createOrRetrieveRegionThrowsException() {
+ final RuntimeException exception = new RuntimeException();
+ doThrow(exception).when((ClientServerSessionCache) sessionCache).createLocalSessionRegion();
+
+ assertThatThrownBy(() -> sessionCache.initialize()).hasCause(exception)
+ .isInstanceOf(IllegalStateException.class);
+
+ verify(logger).fatal("Unable to create or retrieve region", exception);
+
+ }
+
+ @Test
+ public void createRegionFunctionFailsOnServer() {
+ final ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
+
+ regionStatusResultList.clear();
+ regionStatusResultList.add(RegionStatus.INVALID);
+
+ assertThatThrownBy(() -> sessionCache.initialize()).isInstanceOf(IllegalStateException.class)
+ .hasCauseInstanceOf(IllegalStateException.class).hasMessageContaining(
+ "An exception occurred on the server while attempting to create or validate region named "
+ + sessionRegionName
+ + ". See the server log for additional details.");
-public class ClientServerSessionCacheTest {
+ verify(logger).fatal(stringCaptor.capture(), any(Exception.class));
+ assertThat(stringCaptor.getValue()).isEqualTo("Unable to create or retrieve region");
+ }
+
+ @Test
+ public void nonDefaultMaxTimeoutIntervalSetsExpirationDetails() {
+ // Setting the mocked return value of getMaxInactiveInterval to something distinctly not equal
+ // to the default
+ when(sessionManager.getMaxInactiveInterval())
+ .thenReturn(RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL + 1);
+
+ sessionCache.initialize();
+
+ verify(regionFactory).setStatisticsEnabled(true);
+ verify(regionFactory).setCustomEntryIdleTimeout(any(SessionCustomExpiry.class));
+ verify(regionFactory).addCacheListener(any(SessionExpirationCacheListener.class));
+ }
+
+ @Test
+ public void createLocalSessionRegionWithoutEnableLocalCache() {
+ when(sessionManager.getEnableLocalCache()).thenReturn(false);
+ doReturn(regionFactory).when(cache).createClientRegionFactory(ClientRegionShortcut.PROXY);
+ when(regionFactory.create(sessionRegionName)).thenReturn(sessionRegion);
+
+ sessionCache.initialize();
+
+ verify(regionFactory).addCacheListener(any(SessionExpirationCacheListener.class));
+ verify(sessionRegion).registerInterestForAllKeys(InterestResultPolicy.KEYS);
+ }
+ @Test
+ public void createOrRetrieveRegionWithNonNullSessionRegionDoesNotCreateRegion() {
+ final CacheListener<String, HttpSession>[] cacheListeners =
+ uncheckedCast(new CacheListener[] {new SessionExpirationCacheListener()});
+ doReturn(sessionRegion).when(cache).getRegion(sessionRegionName);
+ doReturn(attributes).when(sessionRegion).getAttributes();
+ doReturn(cacheListeners).when(attributes).getCacheListeners();
+
+ sessionCache.initialize();
+
+ verify((ClientServerSessionCache) sessionCache, times(0)).createSessionRegionOnServers();
+ verify((ClientServerSessionCache) sessionCache, times(0)).createLocalSessionRegion();
+ }
+
+ @Test
+ public void createOrRetrieveRegionWithNonNullSessionRegionAndNoSessionExpirationCacheListenerCreatesListener() {
+ final CacheListener<String, HttpSession>[] cacheListeners =
+ uncheckedCast(new CacheListener[] {new DebugCacheListener()});
+ final AttributesMutator<String, HttpSession> attributesMutator =
+ uncheckedCast(mock(AttributesMutator.class));
+ doReturn(sessionRegion).when(cache).getRegion(sessionRegionName);
+ doReturn(attributes).when(sessionRegion).getAttributes();
+ doReturn(cacheListeners).when(attributes).getCacheListeners();
+ doReturn(attributesMutator).when(sessionRegion).getAttributesMutator();
+
+ sessionCache.initialize();
+
+ verify(attributesMutator).addCacheListener(any(SessionExpirationCacheListener.class));
+ }
+
+ @Test
+ public void createOrRetrieveRegionWithNonNullSessionProxyRegionRegistersInterestForAllKeys() {
+ final CacheListener<String, HttpSession>[] cacheListeners =
+ uncheckedCast(new CacheListener[] {new SessionExpirationCacheListener()});
+ doReturn(sessionRegion).when(cache).getRegion(sessionRegionName);
+ doReturn(attributes).when(sessionRegion).getAttributes();
+ doReturn(cacheListeners).when(attributes).getCacheListeners();
+ when(attributes.getDataPolicy()).thenReturn(DataPolicy.EMPTY);
+
+ sessionCache.initialize();
+
+ verify(sessionRegion).registerInterestForAllKeys(InterestResultPolicy.KEYS);
+ }
+
+ @Test
+ public void touchSessionsInvokesPRFunctionForPRAndDoesNotThrowExceptionWhenFunctionDoesNotThrowException() {
+ final Set<String> sessionIds = new HashSet<>();
+
+ when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.PARTITION.toString());
+
+ sessionCache.touchSessions(sessionIds);
+
+ verify(emptyExecution).execute(TouchPartitionedRegionEntriesFunction.ID);
+ }
+
+ @Test
+ public void touchSessionsInvokesPRFunctionForPRAndThrowsExceptionWhenFunctionThrowsException() {
+ final Set<String> sessionIds = new HashSet<>();
+ final FunctionException exception = new FunctionException();
+ final ResultCollector<Object, List<Object>> exceptionCollector =
+ uncheckedCast(mock(ResultCollector.class));
+
+ when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.PARTITION.toString());
+ when(emptyExecution.execute(TouchPartitionedRegionEntriesFunction.ID))
+ .thenReturn(exceptionCollector);
+ when(exceptionCollector.getResult()).thenThrow(exception);
+
+ sessionCache.touchSessions(sessionIds);
+ verify(logger).warn("Caught unexpected exception:", exception);
+ }
+
+ @Test
+ public void touchSessionsInvokesRRFunctionForRRAndDoesNotThrowExceptionWhenFunctionDoesNotThrowException() {
+ // Need to invoke this to set the session region
+ when(regionFactory.create(sessionRegionName)).thenReturn(sessionRegion);
+ sessionCache.initialize();
+
+ final Set<String> sessionIds = new HashSet<>();
+
+ when(sessionRegion.getFullPath()).thenReturn(SEPARATOR + sessionRegionName);
+ when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.REPLICATE.toString());
+
+ sessionCache.touchSessions(sessionIds);
+ verify(emptyExecution).execute(TouchReplicatedRegionEntriesFunction.ID);
+ }
+
+ @Test
+ public void touchSessionsInvokesRRFunctionForRRAndThrowsExceptionWhenFunctionThrowsException() {
+ // Need to invoke this to set the session region
+ when(regionFactory.create(sessionRegionName)).thenReturn(sessionRegion);
+ sessionCache.initialize();
+
+ final Set<String> sessionIds = new HashSet<>();
+ final FunctionException exception = new FunctionException();
+ final ResultCollector<Object, List<Object>> exceptionCollector =
+ uncheckedCast(mock(ResultCollector.class));
+
+ when(sessionRegion.getFullPath()).thenReturn(SEPARATOR + sessionRegionName);
+ when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.REPLICATE.toString());
+ when(emptyExecution.execute(TouchReplicatedRegionEntriesFunction.ID))
+ .thenReturn(exceptionCollector);
+ when(exceptionCollector.getResult()).thenThrow(exception);
+
+ sessionCache.touchSessions(sessionIds);
+ verify(logger).warn("Caught unexpected exception:", exception);
+ }
+
+ @Test
+ public void isBackingCacheEnabledReturnsTrueWhenCommitValveFailfastDisabled() {
+ assertThat(sessionCache.isBackingCacheAvailable()).isTrue();
+ }
+
+ @Test
+ public void isBackingCacheEnabledReturnsValueWhenCommitValveFailfastEnabled() {
+ final boolean backingCacheEnabled = false;
+ final PoolImpl pool = mock(PoolImpl.class);
+
+ when(sessionManager.isCommitValveFailfastEnabled()).thenReturn(true);
+ doReturn(pool).when((ClientServerSessionCache) sessionCache).findPoolInPoolManager();
+ when(pool.isPrimaryUpdaterAlive()).thenReturn(backingCacheEnabled);
+
+ assertThat(sessionCache.isBackingCacheAvailable()).isEqualTo(backingCacheEnabled);
+ }
@Test
public void registerInterestForSessionRegion() {
- SessionManager manager = mock(SessionManager.class);
- ClientCache clientCache = mock(ClientCache.class);
- Region region = mock(Region.class);
- ClientServerSessionCache cache = spy(new ClientServerSessionCache(manager, clientCache));
+ final SessionManager manager = mock(SessionManager.class);
+ final ClientCache clientCache = mock(ClientCache.class);
+ final Region region = mock(Region.class);
+ final ClientServerSessionCache cache = spy(new ClientServerSessionCache(manager, clientCache));
doReturn(region).when(cache).createLocalSessionRegion();
cache.createLocalSessionRegionWithRegisterInterest();
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/DeltaSessionFacadeJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/DeltaSessionFacadeTest.java
similarity index 88%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/DeltaSessionFacadeJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/DeltaSessionFacadeTest.java
index 81254c7..0dac329 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/DeltaSessionFacadeJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/DeltaSessionFacadeTest.java
@@ -22,13 +22,13 @@ import static org.mockito.Mockito.verify;
import org.junit.Test;
-public class DeltaSessionFacadeJUnitTest {
+public class DeltaSessionFacadeTest {
@Test
public void DeltaSessionFacadeMakesProperCallsOnSessionWhenInvoked() {
- DeltaSessionInterface session = spy(new DeltaSession());
+ final DeltaSessionInterface session = spy(new DeltaSession());
- DeltaSessionFacade facade = new DeltaSessionFacade(session);
+ final DeltaSessionFacade facade = new DeltaSessionFacade(session);
doNothing().when(session).commit();
doReturn(true).when(session).isValid();
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/DeltaSessionJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/DeltaSessionTest.java
similarity index 71%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/DeltaSessionJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/DeltaSessionTest.java
index 1d55ce0..fc0c159 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/DeltaSessionJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/DeltaSessionTest.java
@@ -46,15 +46,15 @@ import org.apache.geode.internal.util.BlobHelper;
import org.apache.geode.modules.session.catalina.internal.DeltaSessionAttributeEvent;
import org.apache.geode.modules.session.catalina.internal.DeltaSessionStatistics;
-public class DeltaSessionJUnitTest {
+public class DeltaSessionTest {
- private DeltaSessionManager manager = mock(DeltaSessionManager.class);
- private Region<String, HttpSession> sessionRegion = mock(Region.class);
- private SessionCache sessionCache = mock(ClientServerSessionCache.class);
+ private final DeltaSessionManager manager = mock(DeltaSessionManager.class);
+ private final Region<String, HttpSession> sessionRegion = mock(Region.class);
+ private final SessionCache sessionCache = mock(ClientServerSessionCache.class);
DeltaSessionStatistics stats = mock(DeltaSessionStatistics.class);
private final String sessionRegionName = "sessionRegionName";
private final String contextName = "contextName";
- private Log logger = mock(Log.class);
+ private final Log logger = mock(Log.class);
@Before
public void setup() {
@@ -72,7 +72,7 @@ public class DeltaSessionJUnitTest {
@Test
public void sessionConstructionThrowsIllegalArgumentExceptionIfProvidedManagerIsNotDeltaSessionManager() {
- Manager invalidManager = mock(Manager.class);
+ final Manager invalidManager = mock(Manager.class);
assertThatThrownBy(() -> new DeltaSession(invalidManager))
.isInstanceOf(IllegalArgumentException.class)
@@ -81,35 +81,35 @@ public class DeltaSessionJUnitTest {
@Test
public void sessionConstructionDoesNotThrowExceptionWithValidArgument() {
- DeltaSession session = new DeltaSession(manager);
+ final DeltaSession session = new DeltaSession(manager);
verify(logger).debug(anyString());
}
@Test
public void getSessionCreatesFacadeWhenFacadeIsNullAndPackageProtectionDisabled() {
- DeltaSession session = new DeltaSession(manager);
+ final DeltaSession session = new DeltaSession(manager);
- HttpSession returnedSession = session.getSession();
+ final HttpSession returnedSession = session.getSession();
assertThat(returnedSession).isNotNull();
}
@Test
public void getSessionCreatesFacadeWhenFacadeIsNullAndPackageProtectionEnabled() {
- DeltaSession session = spy(new DeltaSession(manager));
- DeltaSessionFacade facade = mock(DeltaSessionFacade.class);
+ final DeltaSession session = spy(new DeltaSession(manager));
+ final DeltaSessionFacade facade = mock(DeltaSessionFacade.class);
doReturn(true).when(session).isPackageProtectionEnabled();
doReturn(facade).when(session).getNewFacade(any(DeltaSession.class));
- HttpSession returnedSession = session.getSession();
+ final HttpSession returnedSession = session.getSession();
assertThat(returnedSession).isEqualTo(facade);
}
@Test
public void processExpiredIncrementsStatisticsCountForExpiredSessions() {
- DeltaSession session = spy(new DeltaSession(manager));
+ final DeltaSession session = spy(new DeltaSession(manager));
doNothing().when((StandardSession) session).expire(false);
session.processExpired();
@@ -119,13 +119,13 @@ public class DeltaSessionJUnitTest {
@Test
public void applyEventsAppliesEachEventAndPutsSessionIntoRegion() {
- DeltaSessionAttributeEvent event1 = mock(DeltaSessionAttributeEvent.class);
- DeltaSessionAttributeEvent event2 = mock(DeltaSessionAttributeEvent.class);
- List<DeltaSessionAttributeEvent> events = new ArrayList<>();
+ final DeltaSessionAttributeEvent event1 = mock(DeltaSessionAttributeEvent.class);
+ final DeltaSessionAttributeEvent event2 = mock(DeltaSessionAttributeEvent.class);
+ final List<DeltaSessionAttributeEvent> events = new ArrayList<>();
events.add(event1);
events.add(event2);
- Region<String, DeltaSessionInterface> region = mock(Region.class);
- DeltaSession session = spy(new DeltaSession(manager));
+ final Region<String, DeltaSessionInterface> region = mock(Region.class);
+ final DeltaSession session = spy(new DeltaSession(manager));
session.applyAttributeEvents(region, events);
@@ -139,8 +139,8 @@ public class DeltaSessionJUnitTest {
@Test
public void commitThrowsIllegalStateExceptionWhenCalledOnInvalidSession() {
- DeltaSession session = spy(new DeltaSession(manager));
- String sessionId = "invalidatedSession";
+ final DeltaSession session = spy(new DeltaSession(manager));
+ final String sessionId = "invalidatedSession";
doReturn(sessionId).when(session).getId();
assertThatThrownBy(() -> session.commit()).isInstanceOf(IllegalStateException.class)
@@ -149,35 +149,35 @@ public class DeltaSessionJUnitTest {
@Test
public void getSizeInBytesReturnsProperValueForMultipleAttributes() {
- String attrName1 = "attrName1";
- String attrName2 = "attrName2";
- List attrList = new ArrayList<String>();
+ final String attrName1 = "attrName1";
+ final String attrName2 = "attrName2";
+ final List attrList = new ArrayList<String>();
attrList.add(attrName1);
attrList.add(attrName2);
- Enumeration<String> attrNames = Collections.enumeration(attrList);
+ final Enumeration<String> attrNames = Collections.enumeration(attrList);
- byte[] value1 = {0, 0, 0, 0};
- byte[] value2 = {0, 0, 0, 0, 0};
- int totalSize = value1.length + value2.length;
+ final byte[] value1 = {0, 0, 0, 0};
+ final byte[] value2 = {0, 0, 0, 0, 0};
+ final int totalSize = value1.length + value2.length;
- DeltaSession session = spy(new DeltaSession(manager));
+ final DeltaSession session = spy(new DeltaSession(manager));
doReturn(attrNames).when(session).getAttributeNames();
doReturn(value1).when(session).getAttributeWithoutDeserialize(attrName1);
doReturn(value2).when(session).getAttributeWithoutDeserialize(attrName2);
- int sessionSize = session.getSizeInBytes();
+ final int sessionSize = session.getSizeInBytes();
assertThat(sessionSize).isEqualTo(totalSize);
}
@Test
public void serializeLogsWarningWhenExceptionIsThrownDuringSerialization() throws IOException {
- Object obj = "unserialized object";
- String exceptionMessaage = "Serialization failed.";
- IOException exception = new IOException(exceptionMessaage);
+ final Object obj = "unserialized object";
+ final String exceptionMessaage = "Serialization failed.";
+ final IOException exception = new IOException(exceptionMessaage);
- DeltaSession session = spy(new DeltaSession(manager));
+ final DeltaSession session = spy(new DeltaSession(manager));
doThrow(exception).when(session).serializeViaBlobHelper(obj);
session.serialize(obj);
@@ -186,11 +186,11 @@ public class DeltaSessionJUnitTest {
@Test
public void serializeReturnsSerializedObject() throws IOException {
- Object obj = "unserialized object";
- byte[] serializedObj = BlobHelper.serializeToBlob(obj);
+ final Object obj = "unserialized object";
+ final byte[] serializedObj = BlobHelper.serializeToBlob(obj);
- DeltaSession session = spy(new DeltaSession(manager));
- byte[] result = session.serialize(obj);
+ final DeltaSession session = spy(new DeltaSession(manager));
+ final byte[] result = session.serialize(obj);
assertThat(result).isEqualTo(serializedObj);
}
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/PeerToPeerSessionCacheJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/PeerToPeerSessionCacheTest.java
similarity index 90%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/PeerToPeerSessionCacheJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/PeerToPeerSessionCacheTest.java
index 2bea8de..34e5dbf 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/PeerToPeerSessionCacheJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/PeerToPeerSessionCacheTest.java
@@ -46,14 +46,12 @@ import org.apache.geode.modules.util.SessionCustomExpiry;
import org.apache.geode.modules.util.TouchPartitionedRegionEntriesFunction;
import org.apache.geode.modules.util.TouchReplicatedRegionEntriesFunction;
-public class PeerToPeerSessionCacheJUnitTest extends AbstractSessionCacheJUnitTest {
+public class PeerToPeerSessionCacheTest extends AbstractSessionCacheTest {
- private String localRegionName = sessionRegionName + "_local";
- @SuppressWarnings("unchecked")
- private RegionFactory<String, HttpSession> regionFactory = mock(RegionFactory.class);
- @SuppressWarnings("unchecked")
- private Region<String, HttpSession> localRegion = mock(Region.class);
- private Cache cache = mock(Cache.class);
+ private final String localRegionName = sessionRegionName + "_local";
+ private final RegionFactory<String, HttpSession> regionFactory = mock(RegionFactory.class);
+ private final Region<String, HttpSession> localRegion = mock(Region.class);
+ private final Cache cache = mock(Cache.class);
@Before
public void setUp() {
@@ -152,8 +150,8 @@ public class PeerToPeerSessionCacheJUnitTest extends AbstractSessionCacheJUnitTe
@Test
public void touchSessionsWithPartitionedRegionSucceeds() {
- Set<String> sessionIds = new HashSet<>();
- ResultCollector collector = mock(ResultCollector.class);
+ final Set<String> sessionIds = new HashSet<>();
+ final ResultCollector collector = mock(ResultCollector.class);
when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.PARTITION.toString());
doReturn(emptyExecution).when((PeerToPeerSessionCache) sessionCache)
@@ -171,8 +169,8 @@ public class PeerToPeerSessionCacheJUnitTest extends AbstractSessionCacheJUnitTe
// Need to invoke this to set the session region
sessionCache.initialize();
- Set<String> sessionIds = new HashSet<>();
- ResultCollector collector = mock(ResultCollector.class);
+ final Set<String> sessionIds = new HashSet<>();
+ final ResultCollector collector = mock(ResultCollector.class);
when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.REPLICATE.toString());
doReturn(emptyExecution).when((PeerToPeerSessionCache) sessionCache)
@@ -187,9 +185,9 @@ public class PeerToPeerSessionCacheJUnitTest extends AbstractSessionCacheJUnitTe
@Test
public void touchSessionsCatchesThrownException() {
- Set<String> sessionIds = new HashSet<>();
- ResultCollector collector = mock(ResultCollector.class);
- FunctionException exception = new FunctionException();
+ final Set<String> sessionIds = new HashSet<>();
+ final ResultCollector collector = mock(ResultCollector.class);
+ final FunctionException exception = new FunctionException();
when(sessionManager.getRegionAttributesId()).thenReturn(RegionShortcut.PARTITION.toString());
doReturn(emptyExecution).when((PeerToPeerSessionCache) sessionCache)
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/callback/SessionExpirationCacheListenerJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/callback/SessionExpirationCacheListenerTest.java
similarity index 80%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/callback/SessionExpirationCacheListenerJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/callback/SessionExpirationCacheListenerTest.java
index 7228fe8..b1c8a00 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/callback/SessionExpirationCacheListenerJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/callback/SessionExpirationCacheListenerTest.java
@@ -27,12 +27,12 @@ import org.apache.geode.cache.EntryEvent;
import org.apache.geode.cache.Operation;
import org.apache.geode.modules.session.catalina.DeltaSession;
-public class SessionExpirationCacheListenerJUnitTest {
+public class SessionExpirationCacheListenerTest {
@Test
- public void TestAfterDestroyProcessesSessionExpiredByGemfire() {
- SessionExpirationCacheListener listener = new SessionExpirationCacheListener();
- EntryEvent<String, HttpSession> event = mock(EntryEvent.class);
- DeltaSession session = mock(DeltaSession.class);
+ public void testAfterDestroyProcessesSessionExpired() {
+ final SessionExpirationCacheListener listener = new SessionExpirationCacheListener();
+ final EntryEvent<String, HttpSession> event = mock(EntryEvent.class);
+ final DeltaSession session = mock(DeltaSession.class);
when(event.getOperation()).thenReturn(Operation.EXPIRE_DESTROY);
when(event.getOldValue()).thenReturn(session);
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionAttributeEventBatchJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionAttributeEventBatchTest.java
similarity index 77%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionAttributeEventBatchJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionAttributeEventBatchTest.java
index bee73b8..9906618 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionAttributeEventBatchJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionAttributeEventBatchTest.java
@@ -30,7 +30,7 @@ import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
import org.apache.geode.modules.session.catalina.DeltaSessionInterface;
-public class DeltaSessionAttributeEventBatchJUnitTest {
+public class DeltaSessionAttributeEventBatchTest {
String regionName = "regionName";
String sessionId = "sessionId";
LogWriter logWriter = mock(LogWriter.class);
@@ -38,23 +38,22 @@ public class DeltaSessionAttributeEventBatchJUnitTest {
@Test
public void TestApplyForBatch() {
- List<DeltaSessionAttributeEvent> eventList = new ArrayList<>();
- DeltaSessionAttributeEvent event1 = mock(DeltaSessionAttributeEvent.class);
- DeltaSessionAttributeEvent event2 = mock(DeltaSessionAttributeEvent.class);
+ final List<DeltaSessionAttributeEvent> eventList = new ArrayList<>();
+ final DeltaSessionAttributeEvent event1 = mock(DeltaSessionAttributeEvent.class);
+ final DeltaSessionAttributeEvent event2 = mock(DeltaSessionAttributeEvent.class);
eventList.add(event1);
eventList.add(event2);
-
- Cache cache = mock(Cache.class);
- Region<String, DeltaSessionInterface> region = mock(Region.class);
- DeltaSessionInterface deltaSessionInterface = mock(DeltaSessionInterface.class);
+ final Cache cache = mock(Cache.class);
+ final Region<String, DeltaSessionInterface> region = mock(Region.class);
+ final DeltaSessionInterface deltaSessionInterface = mock(DeltaSessionInterface.class);
doReturn(region).when(cache).getRegion(regionName);
when(cache.getLogger()).thenReturn(logWriter);
when(logWriter.fineEnabled()).thenReturn(false);
when(region.get(sessionId)).thenReturn(deltaSessionInterface);
- DeltaSessionAttributeEventBatch batch =
+ final DeltaSessionAttributeEventBatch batch =
new DeltaSessionAttributeEventBatch(regionName, sessionId, eventList);
batch.apply(cache);
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionDestroyAttributeEventJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionDestroyAttributeEventTest.java
similarity index 79%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionDestroyAttributeEventJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionDestroyAttributeEventTest.java
index 5ea2648..7f2a944 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionDestroyAttributeEventJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionDestroyAttributeEventTest.java
@@ -22,13 +22,14 @@ import org.junit.Test;
import org.apache.geode.modules.session.catalina.DeltaSessionInterface;
-public class DeltaSessionDestroyAttributeEventJUnitTest {
+public class DeltaSessionDestroyAttributeEventTest {
@Test
public void DeltaSessionDestroyAttributeEventAppliesAttributeToSession() {
- String attributeName = "DestroyAttribute";
+ final String attributeName = "DestroyAttribute";
- DeltaSessionDestroyAttributeEvent event = new DeltaSessionDestroyAttributeEvent(attributeName);
- DeltaSessionInterface deltaSessionInterface = mock(DeltaSessionInterface.class);
+ final DeltaSessionDestroyAttributeEvent event =
+ new DeltaSessionDestroyAttributeEvent(attributeName);
+ final DeltaSessionInterface deltaSessionInterface = mock(DeltaSessionInterface.class);
event.apply((deltaSessionInterface));
verify(deltaSessionInterface).localDestroyAttribute(attributeName);
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionStatisticsJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionStatisticsTest.java
similarity index 85%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionStatisticsJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionStatisticsTest.java
index 51b8129..8a005f9 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionStatisticsJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionStatisticsTest.java
@@ -28,18 +28,19 @@ import org.junit.Test;
import org.apache.geode.Statistics;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
-public class DeltaSessionStatisticsJUnitTest {
+public class DeltaSessionStatisticsTest {
@Test
public void CreatedDeltaSessionStatisticsAccessProperStats() {
- String appName = "DeltaSessionStatisticsTest";
+ final String appName = "DeltaSessionStatisticsTest";
- InternalDistributedSystem internalDistributedSystem = mock(InternalDistributedSystem.class);
- Statistics statistics = mock(Statistics.class);
+ final InternalDistributedSystem internalDistributedSystem =
+ mock(InternalDistributedSystem.class);
+ final Statistics statistics = mock(Statistics.class);
when(internalDistributedSystem.createAtomicStatistics(any(), any())).thenReturn(statistics);
- DeltaSessionStatistics deltaSessionStatistics =
+ final DeltaSessionStatistics deltaSessionStatistics =
new DeltaSessionStatistics(internalDistributedSystem, appName);
deltaSessionStatistics.incSessionsCreated();
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionUpdateAttributeEventJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionUpdateAttributeEventTest.java
similarity index 81%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionUpdateAttributeEventJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionUpdateAttributeEventTest.java
index d356afd..50e439b 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionUpdateAttributeEventJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/session/catalina/internal/DeltaSessionUpdateAttributeEventTest.java
@@ -22,15 +22,15 @@ import org.junit.Test;
import org.apache.geode.modules.session.catalina.DeltaSessionInterface;
-public class DeltaSessionUpdateAttributeEventJUnitTest {
+public class DeltaSessionUpdateAttributeEventTest {
@Test
public void DeltaSessionDestroyAttributeEventAppliesAttributeToSession() {
- String attributeName = "UpdateAttribute";
- String attributeValue = "UpdateValue";
+ final String attributeName = "UpdateAttribute";
+ final String attributeValue = "UpdateValue";
- DeltaSessionUpdateAttributeEvent event =
+ final DeltaSessionUpdateAttributeEvent event =
new DeltaSessionUpdateAttributeEvent(attributeName, attributeValue);
- DeltaSessionInterface deltaSessionInterface = mock(DeltaSessionInterface.class);
+ final DeltaSessionInterface deltaSessionInterface = mock(DeltaSessionInterface.class);
event.apply((deltaSessionInterface));
verify(deltaSessionInterface).localUpdateAttribute(attributeName, attributeValue);
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/util/CreateRegionFunctionJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/util/CreateRegionFunctionTest.java
similarity index 85%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/util/CreateRegionFunctionJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/util/CreateRegionFunctionTest.java
index 5009489..c653f0e 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/util/CreateRegionFunctionJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/util/CreateRegionFunctionTest.java
@@ -30,10 +30,10 @@ import org.apache.geode.cache.EvictionAttributes;
import org.apache.geode.cache.RegionAttributes;
// TODO: Remove the deprecated method invocations once RegionAttributesCreation is also updated.
-public class CreateRegionFunctionJUnitTest {
+public class CreateRegionFunctionTest {
private RegionAttributes getRegionAttributesWithModifiedDiskDirs(final File[] diskDirs) {
- RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
+ final RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
when(mockRegionAttributes.getDiskStoreName()).thenReturn(null);
when(mockRegionAttributes.getDataPolicy()).thenReturn(DataPolicy.NORMAL);
when(mockRegionAttributes.getCacheListeners()).thenReturn(new CacheListener[] {});
@@ -45,7 +45,7 @@ public class CreateRegionFunctionJUnitTest {
}
private RegionAttributes getRegionAttributesWithModifiedDiskDirSize(final int[] diskDirSize) {
- RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
+ final RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
when(mockRegionAttributes.getDiskStoreName()).thenReturn(null);
when(mockRegionAttributes.getDataPolicy()).thenReturn(DataPolicy.NORMAL);
when(mockRegionAttributes.getCacheListeners()).thenReturn(new CacheListener[] {});
@@ -59,18 +59,19 @@ public class CreateRegionFunctionJUnitTest {
@Test
public void regionComparisonMustBeSuccessfulWhenDiskStoreNamesForBothAreNullAndDiskPropertiesAreDifferent() {
- CreateRegionFunction createRegionFunction = mock(CreateRegionFunction.class);
+ final CreateRegionFunction createRegionFunction = mock(CreateRegionFunction.class);
doCallRealMethod().when(createRegionFunction).compareRegionAttributes(any(), any());
- RegionAttributes existingRegionAttributes =
+ final RegionAttributes existingRegionAttributes =
getRegionAttributesWithModifiedDiskDirSize(new int[] {1});
- RegionAttributes requestedRegionAttributes =
+ final RegionAttributes requestedRegionAttributes =
getRegionAttributesWithModifiedDiskDirSize(new int[] {2});
createRegionFunction.compareRegionAttributes(existingRegionAttributes,
requestedRegionAttributes);
- RegionAttributes existingRegionAttributes2 = getRegionAttributesWithModifiedDiskDirs(null);
- RegionAttributes requestedRegionAttributes2 =
+ final RegionAttributes existingRegionAttributes2 =
+ getRegionAttributesWithModifiedDiskDirs(null);
+ final RegionAttributes requestedRegionAttributes2 =
getRegionAttributesWithModifiedDiskDirs(new File[] {});
createRegionFunction.compareRegionAttributes(existingRegionAttributes2,
requestedRegionAttributes2);
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/util/TouchPartitionedRegionEntriesFunctionJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/util/TouchPartitionedRegionEntriesFunctionTest.java
similarity index 84%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/util/TouchPartitionedRegionEntriesFunctionJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/util/TouchPartitionedRegionEntriesFunctionTest.java
index 6852681..5d09a09 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/util/TouchPartitionedRegionEntriesFunctionJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/util/TouchPartitionedRegionEntriesFunctionTest.java
@@ -37,15 +37,15 @@ import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.RegionFunctionContext;
import org.apache.geode.cache.execute.ResultSender;
-public class TouchPartitionedRegionEntriesFunctionJUnitTest {
+public class TouchPartitionedRegionEntriesFunctionTest {
- private TouchPartitionedRegionEntriesFunction function =
+ private final TouchPartitionedRegionEntriesFunction function =
spy(new TouchPartitionedRegionEntriesFunction());
- private FunctionContext context = mock(RegionFunctionContext.class);
- private Cache cache = mock(Cache.class);
- private LogWriter logger = mock(LogWriter.class);
- private Region primaryDataSet = mock(Region.class);
- private ResultSender resultSender = mock(ResultSender.class);
+ private final FunctionContext context = mock(RegionFunctionContext.class);
+ private final Cache cache = mock(Cache.class);
+ private final LogWriter logger = mock(LogWriter.class);
+ private final Region primaryDataSet = mock(Region.class);
+ private final ResultSender resultSender = mock(ResultSender.class);
@Before
public void setUp() {
@@ -69,7 +69,7 @@ public class TouchPartitionedRegionEntriesFunctionJUnitTest {
@Test
public void executeDoesNotThrowExceptionWithProperlyDefinedContextAndMultipleKeys() {
- HashSet<String> keys = new HashSet();
+ final HashSet<String> keys = new HashSet();
keys.add("Key1");
keys.add("Key2");
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/util/TouchReplicatedRegionEntriesFunctionJUnitTest.java b/extensions/geode-modules/src/test/java/org/apache/geode/modules/util/TouchReplicatedRegionEntriesFunctionTest.java
similarity index 79%
rename from extensions/geode-modules-test/src/main/java/org/apache/geode/modules/util/TouchReplicatedRegionEntriesFunctionJUnitTest.java
rename to extensions/geode-modules/src/test/java/org/apache/geode/modules/util/TouchReplicatedRegionEntriesFunctionTest.java
index 294317a..f7e80c8 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/util/TouchReplicatedRegionEntriesFunctionJUnitTest.java
+++ b/extensions/geode-modules/src/test/java/org/apache/geode/modules/util/TouchReplicatedRegionEntriesFunctionTest.java
@@ -33,17 +33,17 @@ import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.RegionFunctionContext;
import org.apache.geode.cache.execute.ResultSender;
-public class TouchReplicatedRegionEntriesFunctionJUnitTest {
- private TouchReplicatedRegionEntriesFunction function =
+public class TouchReplicatedRegionEntriesFunctionTest {
+ private final TouchReplicatedRegionEntriesFunction function =
spy(new TouchReplicatedRegionEntriesFunction());
- private FunctionContext context = mock(RegionFunctionContext.class);
- private Cache cache = mock(Cache.class);
- private LogWriter logger = mock(LogWriter.class);
- private Region region = mock(Region.class);
- private ResultSender resultSender = mock(ResultSender.class);
- private String regionName = "regionName";
- private HashSet<String> keys = new HashSet<>();
- private Object[] arguments = new Object[] {regionName, keys};
+ private final FunctionContext context = mock(RegionFunctionContext.class);
+ private final Cache cache = mock(Cache.class);
+ private final LogWriter logger = mock(LogWriter.class);
+ private final Region region = mock(Region.class);
+ private final ResultSender resultSender = mock(ResultSender.class);
+ private final String regionName = "regionName";
+ private final HashSet<String> keys = new HashSet<>();
+ private final Object[] arguments = new Object[] {regionName, keys};
@Before
public void setUp() {