diff --git a/jetty-core/jetty-session/src/test/java/org/eclipse/jetty/session/AbstractSessionDataStoreTest.java b/jetty-core/jetty-session/src/test/java/org/eclipse/jetty/session/AbstractSessionDataStoreTest.java index cb429991d17..26f2df6fc7c 100644 --- a/jetty-core/jetty-session/src/test/java/org/eclipse/jetty/session/AbstractSessionDataStoreTest.java +++ b/jetty-core/jetty-session/src/test/java/org/eclipse/jetty/session/AbstractSessionDataStoreTest.java @@ -109,6 +109,7 @@ public abstract class AbstractSessionDataStoreTest //create the SessionDataStore _sessionIdManager = new DefaultSessionIdManager(_server); + _sessionIdManager.setWorkerName(""); _server.addBean(_sessionIdManager, true); _sessionManager = new TestableSessionManager(); diff --git a/jetty-core/jetty-session/src/test/java/org/eclipse/jetty/session/JdbcTestHelper.java b/jetty-core/jetty-session/src/test/java/org/eclipse/jetty/session/JdbcTestHelper.java index 8cd6908310c..96a006f6733 100644 --- a/jetty-core/jetty-session/src/test/java/org/eclipse/jetty/session/JdbcTestHelper.java +++ b/jetty-core/jetty-session/src/test/java/org/eclipse/jetty/session/JdbcTestHelper.java @@ -54,7 +54,6 @@ public class JdbcTestHelper public static final String LAST_SAVE_COL = "lstime"; public static final String MAP_COL = "mo"; public static final String MAX_IDLE_COL = "mi"; - public static final String TABLE = "mysessions"; public static final String ID_COL = "mysessionid"; public static final String ACCESS_COL = "atime"; public static final String CONTEXT_COL = "cpath"; @@ -94,12 +93,12 @@ public class JdbcTestHelper } } - public static void shutdown(String connectionUrl) + public static void shutdown(String sessionTableName) throws Exception { try (Connection connection = getConnection()) { - connection.prepareStatement("truncate table " + TABLE).executeUpdate(); + connection.prepareStatement("truncate table " + sessionTableName).executeUpdate(); } } @@ -130,24 +129,24 @@ public class JdbcTestHelper /** * @return a fresh JDBCSessionDataStoreFactory */ - public static SessionDataStoreFactory newSessionDataStoreFactory() + public static SessionDataStoreFactory newSessionDataStoreFactory(String sessionTableName) { - return newSessionDataStoreFactory(buildDatabaseAdaptor()); + return newSessionDataStoreFactory(buildDatabaseAdaptor(), sessionTableName); } - public static SessionDataStoreFactory newSessionDataStoreFactory(DatabaseAdaptor da) + public static SessionDataStoreFactory newSessionDataStoreFactory(DatabaseAdaptor da, String sessionTableName) { JDBCSessionDataStoreFactory factory = new JDBCSessionDataStoreFactory(); factory.setDatabaseAdaptor(da); - JDBCSessionDataStore.SessionTableSchema sessionTableSchema = newSessionTableSchema(); + JDBCSessionDataStore.SessionTableSchema sessionTableSchema = newSessionTableSchema(sessionTableName); factory.setSessionTableSchema(sessionTableSchema); return factory; } - public static JDBCSessionDataStore.SessionTableSchema newSessionTableSchema() + public static JDBCSessionDataStore.SessionTableSchema newSessionTableSchema(String sessionTableName) { JDBCSessionDataStore.SessionTableSchema sessionTableSchema = new JDBCSessionDataStore.SessionTableSchema(); - sessionTableSchema.setTableName(TABLE); + sessionTableSchema.setTableName(sessionTableName); sessionTableSchema.setIdColumn(ID_COL); sessionTableSchema.setAccessTimeColumn(ACCESS_COL); sessionTableSchema.setContextPathColumn(CONTEXT_COL); @@ -162,10 +161,10 @@ public class JdbcTestHelper return sessionTableSchema; } - public static void prepareTables() throws SQLException + public static void prepareTables(String sessionTableName) throws SQLException { DatabaseAdaptor da = buildDatabaseAdaptor(); - JDBCSessionDataStore.SessionTableSchema sessionTableSchema = newSessionTableSchema(); + JDBCSessionDataStore.SessionTableSchema sessionTableSchema = newSessionTableSchema(sessionTableName); sessionTableSchema.setDatabaseAdaptor(da); sessionTableSchema.prepareTables(); } @@ -199,13 +198,13 @@ public class JdbcTestHelper } } - public static boolean existsInSessionTable(String id, boolean verbose) + public static boolean existsInSessionTable(String id, boolean verbose, String sessionTableName) throws Exception { try (Connection con = getConnection()) { PreparedStatement statement = con.prepareStatement("select * from " + - TABLE + + sessionTableName + " where " + ID_COL + " = ?"); statement.setString(1, id); ResultSet result = statement.executeQuery(); @@ -225,7 +224,7 @@ public class JdbcTestHelper } @SuppressWarnings("unchecked") - public static boolean checkSessionPersisted(SessionData data) + public static boolean checkSessionPersisted(SessionData data, String sessionTableName) throws Exception { PreparedStatement statement = null; @@ -233,7 +232,7 @@ public class JdbcTestHelper try (Connection con = getConnection()) { statement = con.prepareStatement( - "select * from " + TABLE + + "select * from " + sessionTableName + " where " + ID_COL + " = ? and " + CONTEXT_COL + " = ? and virtualHost = ?"); statement.setString(1, data.getId()); @@ -293,11 +292,11 @@ public class JdbcTestHelper return true; } - public static void insertSession(SessionData data) throws Exception + public static void insertSession(SessionData data, String sessionTableName) throws Exception { try (Connection con = getConnection()) { - PreparedStatement statement = con.prepareStatement("insert into " + TABLE + + PreparedStatement statement = con.prepareStatement("insert into " + sessionTableName + " (" + ID_COL + ", " + CONTEXT_COL + ", virtualHost, " + LAST_NODE_COL + ", " + ACCESS_COL + ", " + LAST_ACCESS_COL + ", " + CREATE_COL + ", " + COOKIE_COL + ", " + LAST_SAVE_COL + ", " + EXPIRY_COL + ", " + MAX_IDLE_COL + "," + MAP_COL + " ) " + @@ -336,12 +335,12 @@ public class JdbcTestHelper public static void insertUnreadableSession(String id, String contextPath, String vhost, String lastNode, long created, long accessed, long lastAccessed, long maxIdle, long expiry, - long cookieSet, long lastSaved) + long cookieSet, long lastSaved, String sessionTableName) throws Exception { try (Connection con = getConnection()) { - PreparedStatement statement = con.prepareStatement("insert into " + TABLE + + PreparedStatement statement = con.prepareStatement("insert into " + sessionTableName + " (" + ID_COL + ", " + CONTEXT_COL + ", virtualHost, " + LAST_NODE_COL + ", " + ACCESS_COL + ", " + LAST_ACCESS_COL + ", " + CREATE_COL + ", " + COOKIE_COL + ", " + LAST_SAVE_COL + ", " + EXPIRY_COL + ", " + MAX_IDLE_COL + "," + MAP_COL + " ) " + @@ -368,13 +367,13 @@ public class JdbcTestHelper } } - public static Set getSessionIds() + public static Set getSessionIds(String sessionTableName) throws Exception { HashSet ids = new HashSet<>(); try (Connection con = getConnection()) { - PreparedStatement statement = con.prepareStatement("select " + ID_COL + " from " + TABLE); + PreparedStatement statement = con.prepareStatement("select " + ID_COL + " from " + sessionTableName); ResultSet result = statement.executeQuery(); while (result.next()) { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/pom.xml b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/pom.xml index e7838ae18de..f50f174b4bb 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/pom.xml +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/pom.xml @@ -63,5 +63,9 @@ awaitility test + + org.eclipse.jetty.tests + jetty-test-session-common + diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredInvalidationSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredInvalidationSessionTest.java index b5bf04628c2..a7f33606243 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredInvalidationSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredInvalidationSessionTest.java @@ -14,6 +14,7 @@ package org.eclipse.jetty.ee10.session; import java.io.IOException; +import java.io.Serial; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; @@ -28,11 +29,13 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.fail; /** @@ -97,7 +100,7 @@ public abstract class AbstractClusteredInvalidationSessionTest extends AbstractS assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); // Be sure the session is also present in node2 Request request2 = client.newRequest(urls[1] + "?action=increment"); @@ -132,6 +135,7 @@ public abstract class AbstractClusteredInvalidationSessionTest extends AbstractS public static class TestServlet extends HttpServlet { + @Serial private static final long serialVersionUID = 1L; @Override @@ -167,7 +171,7 @@ public abstract class AbstractClusteredInvalidationSessionTest extends AbstractS else if ("test".equals(action)) { HttpSession session = request.getSession(false); - assertEquals(null, session); + assertNull(session); } } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredOrphanedSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredOrphanedSessionTest.java index ceab3422dea..ff22d9d76d9 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredOrphanedSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredOrphanedSessionTest.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredSessionScavengingTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredSessionScavengingTest.java index 55820cb79a4..05d8ab0c41b 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredSessionScavengingTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractClusteredSessionScavengingTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.ee10.session; import java.io.IOException; import java.io.PrintWriter; +import java.io.Serial; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -39,6 +40,7 @@ import org.eclipse.jetty.session.ManagedSession; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -81,12 +83,6 @@ public abstract class AbstractClusteredSessionScavengingTest extends AbstractSes return new TestSessionCache(manager); } } - - public void pause(int secs) - throws InterruptedException - { - Thread.sleep(TimeUnit.SECONDS.toMillis(secs)); - } @Test public void testClusteredScavenge() throws Exception @@ -141,7 +137,7 @@ public abstract class AbstractClusteredSessionScavengingTest extends AbstractSes assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); assertTrue(response1.getContentAsString().startsWith("init")); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); String id = SessionTestSupport.extractSessionId(sessionCookie); assertEquals(1, ((DefaultSessionCache)m1.getSessionCache()).getSessionsCurrent()); assertEquals(1, ((DefaultSessionCache)m1.getSessionCache()).getSessionsMax()); @@ -156,10 +152,8 @@ public abstract class AbstractClusteredSessionScavengingTest extends AbstractSes //Now do requests for the session to node2. This will update the expiry time on the session. //Send requests for the next maxInactiveInterval, pausing a little between each request. int requestInterval = 500; //ms pause between requests - long start = System.currentTimeMillis(); - long end = expiry; - long time = start; - while (time < end) + long time = System.currentTimeMillis(); + while (time < expiry) { Request request = client.newRequest("http://localhost:" + port2 + contextPath + servletMapping.substring(1)); ContentResponse response2 = request.send(); @@ -231,6 +225,7 @@ public abstract class AbstractClusteredSessionScavengingTest extends AbstractSes public static class TestServlet extends HttpServlet { + @Serial private static final long serialVersionUID = 1L; @Override diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractWebAppObjectInSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractWebAppObjectInSessionTest.java index c7fb84fe200..4fbe773a685 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractWebAppObjectInSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractWebAppObjectInSessionTest.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceFactory; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/FooInvocationHandler.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/FooInvocationHandler.java deleted file mode 100644 index d4630fb47da..00000000000 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/FooInvocationHandler.java +++ /dev/null @@ -1,39 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.session; - -import java.io.Serializable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -/** - * ProxiableSessionAttributeObjectInvocationHandler - */ -public class FooInvocationHandler implements InvocationHandler, Serializable -{ - private static final long serialVersionUID = -4009478822490178554L; - - private Foo foo; - - public FooInvocationHandler(Foo f) - { - foo = f; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable - { - return method.invoke(foo, args); - } -} diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/TestFoo.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/TestFoo.java deleted file mode 100644 index ae6a172a09a..00000000000 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/TestFoo.java +++ /dev/null @@ -1,47 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.session; - -import java.io.Serializable; - -/** - * TestFoo - */ -public class TestFoo implements Foo, Serializable -{ - private static final long serialVersionUID = 953717519120144555L; - - private int i = -99; - - @Override - public int getInt() - { - return this.i; - } - - @Override - public void setInt(int i) - { - this.i = i; - } - - @Override - public boolean equals(Object obj) - { - if (obj == null) - return false; - - return (((Foo)obj).getInt() == getInt()); - } -} diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/AsyncTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/AsyncTest.java index 50502cdd6a1..48e21163225 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/AsyncTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/AsyncTest.java @@ -34,11 +34,16 @@ import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.Foo; +import org.eclipse.jetty.session.test.FooInvocationHandler; +import org.eclipse.jetty.session.test.TestFoo; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -80,7 +85,7 @@ public class AsyncTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //session should now be evicted from the cache after request exited String id = SessionTestSupport.extractSessionId(sessionCookie); @@ -126,7 +131,7 @@ public class AsyncTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); String id = SessionTestSupport.extractSessionId(sessionCookie); //session should now be evicted from the cache after request exited @@ -176,7 +181,7 @@ public class AsyncTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //session should now be evicted from the cache after request exited String id = SessionTestSupport.extractSessionId(sessionCookie); @@ -222,7 +227,7 @@ public class AsyncTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); String id = SessionTestSupport.extractSessionId(sessionCookie); //session should now be evicted from the cache after request exited @@ -273,8 +278,8 @@ public class AsyncTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - - assertTrue(sessionCookie != null); + + assertNotNull(sessionCookie); //session should now be evicted from the cache A after request exited String id = SessionTestSupport.extractSessionId(sessionCookie); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ConcurrencyTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ConcurrencyTest.java index 89b9ee593b6..44388cf7fa5 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ConcurrencyTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ConcurrencyTest.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.client.Request; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.eclipse.jetty.util.NanoTime; import org.junit.jupiter.api.Test; @@ -75,7 +76,7 @@ public class ConcurrencyTest ContentResponse response1 = client.GET(url + "?action=init"); assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //simulate 10 clients making 10 requests each for the same session ExecutorService executor = Executors.newCachedThreadPool(); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/CreationTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/CreationTest.java index 11866c65da0..161d2f43fb9 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/CreationTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/CreationTest.java @@ -37,6 +37,7 @@ import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.eclipse.jetty.util.StringUtil; import org.hamcrest.Matchers; import org.junit.jupiter.api.Disabled; @@ -95,7 +96,7 @@ public class CreationTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); } finally { @@ -141,7 +142,7 @@ public class CreationTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //session should now be evicted from the cache String id = SessionTestSupport.extractSessionId(sessionCookie); @@ -450,7 +451,7 @@ public class CreationTest } return; } - else if (action != null && "test".equals(action)) + else if ("test".equals(action)) { HttpSession session = request.getSession(false); assertNotNull(session); @@ -513,12 +514,11 @@ public class CreationTest { HttpSession session = request.getSession(false); assertNull(session); - if (session == null) - session = request.getSession(true); + session = request.getSession(true); // Be sure nothing from contextA is present Object objectA = session.getAttribute("value"); - assertTrue(objectA == null); + assertNull(objectA); // Add something, so in contextA we can check if it is visible (it must not). session.setAttribute("B", "B"); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/DuplicateCookieTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/DuplicateCookieTest.java index a731cbcf840..7601b37e191 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/DuplicateCookieTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/DuplicateCookieTest.java @@ -35,6 +35,7 @@ import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.component.LifeCycle; import org.junit.jupiter.api.Test; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/IdleSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/IdleSessionTest.java index f78d1e98a2e..8a670b0fa93 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/IdleSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/IdleSessionTest.java @@ -32,6 +32,8 @@ import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.ManagedSession; import org.eclipse.jetty.session.NullSessionCacheFactory; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStore; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.eclipse.jetty.util.thread.AutoLock; import org.junit.jupiter.api.Test; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ModifyMaxInactiveIntervalTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ModifyMaxInactiveIntervalTest.java index c62aa9d9ca3..864ea49be76 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ModifyMaxInactiveIntervalTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ModifyMaxInactiveIntervalTest.java @@ -30,11 +30,12 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * ModifyMaxInactiveIntervalTest @@ -73,7 +74,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); String id = SessionTestSupport.extractSessionId(sessionCookie); //check that the maxInactive is -1 @@ -120,7 +121,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to reduce the maxinactive interval Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive); @@ -175,7 +176,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to increase the maxinactive interval Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive); @@ -232,7 +233,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to reduce the maxinactive interval Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive + "&wait=" + sleep); @@ -261,7 +262,6 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase int oldMaxInactive = 10; int newMaxInactive = 2; int evict = 4; - int sleep = evict; int scavenge = __scavenge; DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); @@ -286,10 +286,10 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to reduce the maxinactive interval - Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive + "&wait=" + sleep); + Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive + "&wait=" + evict); response = request.send(); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); @@ -338,7 +338,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to change the maxinactive interval Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive + "&wait=" + 2); @@ -390,7 +390,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request that will sleep long enough for the session expiry time to have passed //before trying to access the session and ensure it is still there @@ -439,7 +439,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to change the maxinactive interval Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive); @@ -492,7 +492,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //Test that the maxInactiveInterval matches the expected value Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=test&val=" + maxInactive); @@ -528,8 +528,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase { //change the expiry time for the session, maybe sleeping before the change String tmp = request.getParameter("val"); - int interval = -1; - interval = (tmp == null ? -1 : Integer.parseInt(tmp)); + int interval = (tmp == null ? -1 : Integer.parseInt(tmp)); tmp = request.getParameter("wait"); int wait = (tmp == null ? 0 : Integer.parseInt(tmp)); @@ -566,8 +565,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase throw new ServletException("Session is null for action=sleep"); String tmp = request.getParameter("val"); - int interval = 0; - interval = (tmp == null ? 0 : Integer.parseInt(tmp)); + int interval = (tmp == null ? 0 : Integer.parseInt(tmp)); if (interval > 0) { @@ -597,11 +595,9 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase return; } String tmp = request.getParameter("val"); - int interval = 0; - interval = (tmp == null ? 0 : Integer.parseInt(tmp)); + int interval = (tmp == null ? 0 : Integer.parseInt(tmp)); assertEquals(interval, session.getMaxInactiveInterval()); - return; } } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/NonClusteredSessionScavengingTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/NonClusteredSessionScavengingTest.java index 81a6ac6bec9..89ba254a7cd 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/NonClusteredSessionScavengingTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/NonClusteredSessionScavengingTest.java @@ -31,6 +31,8 @@ import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; @@ -92,7 +94,7 @@ public class NonClusteredSessionScavengingTest extends AbstractSessionTestBase ContentResponse response1 = client.GET(url + "?action=create"); assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //test session was created SessionManager m1 = context1.getSessionHandler(); @@ -148,7 +150,7 @@ public class NonClusteredSessionScavengingTest extends AbstractSessionTestBase ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping.substring(1) + "?action=create"); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); // Let's wait for the scavenger to run pause(maxInactivePeriod + scavengePeriod); @@ -205,7 +207,7 @@ public class NonClusteredSessionScavengingTest extends AbstractSessionTestBase ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping.substring(1) + "?action=create"); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); // Let's wait for the scavenger to run pause(2 * scavengePeriod); @@ -248,13 +250,13 @@ public class NonClusteredSessionScavengingTest extends AbstractSessionTestBase assertNull(s); s = request.getSession(true); assertNotNull(s); - assertFalse(s.getId().equals(id)); + assertNotEquals(s.getId(), id); } else if ("old-test".equals(action)) { HttpSession s = request.getSession(false); assertNotNull(s); - assertTrue(s.getId().equals(id)); + assertEquals(s.getId(), id); } else { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/RedirectSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/RedirectSessionTest.java index f7e6d8ee4e4..819d2d5a5fb 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/RedirectSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/RedirectSessionTest.java @@ -26,6 +26,7 @@ import org.eclipse.jetty.ee10.servlet.ServletContextHandler; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ReentrantRequestSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ReentrantRequestSessionTest.java index 4e32e0adff7..c51f74dd8f2 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ReentrantRequestSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/ReentrantRequestSessionTest.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -70,7 +71,7 @@ public class ReentrantRequestSessionTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //make a request that will make a simultaneous request for the same session Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=reenter&port=" + port + "&path=" + contextPath + servletMapping); @@ -141,7 +142,7 @@ public class ReentrantRequestSessionTest } else { - assertTrue(session != null); + assertNotNull(session); session.setAttribute("reentrant", "true"); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/RemoveSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/RemoveSessionTest.java index 9f2166f904b..5f078809fba 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/RemoveSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/RemoveSessionTest.java @@ -32,6 +32,7 @@ import org.eclipse.jetty.session.DefaultSessionCache; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -78,7 +79,7 @@ public class RemoveSessionTest ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create"); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //ensure sessionCreated bindingListener is called assertTrue(testListener.isCreated()); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SameContextForwardedSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SameContextForwardedSessionTest.java index aa850cb4657..f887991a4da 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SameContextForwardedSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SameContextForwardedSessionTest.java @@ -29,12 +29,12 @@ import org.eclipse.jetty.ee10.servlet.ServletHolder; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * SameContextForwardedSessionTest @@ -72,7 +72,7 @@ public class SameContextForwardedSessionTest ContentResponse response = client.GET("http://localhost:" + serverPort + "/context/one"); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //test that the session was created, and that it contains the attributes from servlet3 and servlet1 testServletContextHandler.getSessionHandler().getSessionCache().contains(SessionTestSupport.extractSessionId(sessionCookie)); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionInvalidateCreateScavengeTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionInvalidateCreateScavengeTest.java index e3540800394..4e8884e2888 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionInvalidateCreateScavengeTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionInvalidateCreateScavengeTest.java @@ -37,6 +37,8 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionInvalidationTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionInvalidationTest.java index 5e367bfbc45..63401cad2b3 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionInvalidationTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionInvalidationTest.java @@ -30,6 +30,7 @@ import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.NullSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -38,7 +39,6 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * SessionInvalidationTest @@ -80,7 +80,7 @@ public class SessionInvalidationTest ContentResponse response1 = client.GET(url + "?action=init"); assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); // Make a request which will invalidate the existing session Request request2 = client.newRequest(url + "?action=test"); @@ -130,7 +130,7 @@ public class SessionInvalidationTest ContentResponse response1 = client.GET(url + "?action=init"); assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); // Make a request which will invalidate the existing session Request request2 = client.newRequest(url + "?action=test"); @@ -177,14 +177,14 @@ public class SessionInvalidationTest //invalidate existing session session.invalidate(); - assertThrows(IllegalStateException.class, () -> session.invalidate()); - assertThrows(IllegalStateException.class, () -> session.getLastAccessedTime()); - assertThrows(IllegalStateException.class, () -> session.getCreationTime()); + assertThrows(IllegalStateException.class, session::invalidate); + assertThrows(IllegalStateException.class, session::getLastAccessedTime); + assertThrows(IllegalStateException.class, session::getCreationTime); assertThrows(IllegalStateException.class, () -> session.getAttribute("foo")); - assertThrows(IllegalStateException.class, () -> session.getAttributeNames()); + assertThrows(IllegalStateException.class, session::getAttributeNames); assertThrows(IllegalStateException.class, () -> session.removeAttribute("foo")); assertThrows(IllegalStateException.class, () -> session.setAttribute("a", "b")); - assertDoesNotThrow(() -> session.getId()); + assertDoesNotThrow(session::getId); } else if ("get".equals(action)) { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionRenewTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionRenewTest.java index 5085a1e8135..7778f1d96df 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionRenewTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionRenewTest.java @@ -39,12 +39,16 @@ import org.eclipse.jetty.session.SessionCacheFactory; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; +import org.eclipse.jetty.session.test.TestSessionDataStore; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -176,7 +180,7 @@ public class SessionRenewTest ContentResponse renewResponse = request.send(); assertEquals(HttpServletResponse.SC_OK, renewResponse.getStatus()); String newSessionCookie = renewResponse.getHeaders().get("Set-Cookie"); - assertTrue(newSessionCookie != null); + assertNotNull(newSessionCookie); String updatedId = SessionTestSupport.extractSessionId(newSessionCookie); //session ids should be updated on all contexts @@ -227,7 +231,7 @@ public class SessionRenewTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); assertFalse(testListener.isCalled()); //make a request to change the sessionid @@ -308,7 +312,7 @@ public class SessionRenewTest else if ("renew".equals(action)) { HttpSession beforeSession = request.getSession(false); - assertTrue(beforeSession != null); + assertNotNull(beforeSession); String beforeSessionId = beforeSession.getId(); //((Session)beforeSession).renewId(request); @@ -316,11 +320,11 @@ public class SessionRenewTest HttpSession afterSession = request.getSession(false); - assertTrue(afterSession != null); + assertNotNull(afterSession); String afterSessionId = afterSession.getId(); - assertTrue(beforeSession == afterSession); //same object - assertFalse(beforeSessionId.equals(afterSessionId)); //different id + assertSame(beforeSession, afterSession); //same object + assertNotEquals(beforeSessionId, afterSessionId); //different id ManagedSession coreAfterSession = ServletContextRequest.getServletContextRequest(request).getManagedSession(); SessionManager sessionManager = coreAfterSession.getSessionManager(); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/pom.xml b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/pom.xml index 893bdae7285..4233f4dbd58 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/pom.xml +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/pom.xml @@ -68,5 +68,10 @@ slf4j-simple test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/ClusteredOrphanedSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/ClusteredOrphanedSessionTest.java index a98c17e88b7..293ddf756b3 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/ClusteredOrphanedSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/ClusteredOrphanedSessionTest.java @@ -15,8 +15,7 @@ package org.eclipse.jetty.ee10.session.gcloud; import org.eclipse.jetty.ee10.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.GCloudSessionTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -26,25 +25,11 @@ import org.testcontainers.junit.jupiter.Testcontainers; public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest { - public static GCloudSessionTestSupport __testSupport; - - @BeforeAll - public static void setUp() throws Exception - { - __testSupport = new GCloudSessionTestSupport(); - __testSupport.setUp(); - } - - @AfterAll - public static void tearDown() throws Exception - { - __testSupport.deleteSessions(); - __testSupport.tearDown(); - } + public GCloudSessionTestSupport testSupport = new GCloudSessionTestSupport(getClass().getSimpleName()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore()); + return testSupport.newSessionDataStoreFactory(); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/ClusteredSessionScavengingTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/ClusteredSessionScavengingTest.java index e7d0d6885c3..c7db0c30975 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/ClusteredSessionScavengingTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/ClusteredSessionScavengingTest.java @@ -15,8 +15,7 @@ package org.eclipse.jetty.ee10.session.gcloud; import org.eclipse.jetty.ee10.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.GCloudSessionTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -26,25 +25,11 @@ import org.testcontainers.junit.jupiter.Testcontainers; public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest { - public static GCloudSessionTestSupport __testSupport; - - @BeforeAll - public static void setUp() throws Exception - { - __testSupport = new GCloudSessionTestSupport(); - __testSupport.setUp(); - } - - @AfterAll - public static void tearDown() throws Exception - { - __testSupport.deleteSessions(); - __testSupport.tearDown(); - } + public GCloudSessionTestSupport testSupport = new GCloudSessionTestSupport(getClass().getSimpleName()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore()); + return testSupport.newSessionDataStoreFactory(); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/GCloudSessionDataStoreTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/GCloudSessionDataStoreTest.java index 2d4c47cac71..64135688b05 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/GCloudSessionDataStoreTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/GCloudSessionDataStoreTest.java @@ -16,9 +16,8 @@ package org.eclipse.jetty.ee10.session.gcloud; import org.eclipse.jetty.session.AbstractSessionDataStoreTest; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; +import org.eclipse.jetty.session.test.tools.GCloudSessionTestSupport; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -33,54 +32,41 @@ public class GCloudSessionDataStoreTest extends AbstractSessionDataStoreTest super(); } - public static GCloudSessionTestSupport __testSupport; - - @BeforeAll - public static void configure() throws Exception - { - __testSupport = new GCloudSessionTestSupport(); - __testSupport.setUp(); - } - - @AfterAll - public static void tearDown() throws Exception - { - __testSupport.tearDown(); - } + public GCloudSessionTestSupport testSupport = new GCloudSessionTestSupport(getClass().getSimpleName()); @AfterEach - public void teardown() throws Exception + public void cleanup() throws Exception { - __testSupport.deleteSessions(); + testSupport.deleteSessions(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore()); + return testSupport.newSessionDataStoreFactory(); } @Override public void persistSession(SessionData data) throws Exception { - __testSupport.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), - data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), - data.getCookieSet(), data.getLastSaved(), data.getAllAttributes()); + testSupport.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), + data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), + data.getCookieSet(), data.getLastSaved(), data.getAllAttributes()); } @Override public void persistUnreadableSession(SessionData data) throws Exception { - __testSupport.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), - data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), - data.getCookieSet(), data.getLastSaved(), null); + testSupport.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), + data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), + data.getCookieSet(), data.getLastSaved(), null); } @Override public boolean checkSessionExists(SessionData data) throws Exception { - return __testSupport.checkSessionExists(data.getId()); + return testSupport.checkSessionExists(data.getId()); } @Override @@ -90,7 +76,7 @@ public class GCloudSessionDataStoreTest extends AbstractSessionDataStoreTest Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return __testSupport.checkSessionPersisted(data); + return testSupport.checkSessionPersisted(data); } finally { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/InvalidationSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/InvalidationSessionTest.java index 7b9b4f66558..d550b0709da 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/InvalidationSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/InvalidationSessionTest.java @@ -15,8 +15,7 @@ package org.eclipse.jetty.ee10.session.gcloud; import org.eclipse.jetty.ee10.session.AbstractClusteredInvalidationSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.GCloudSessionTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -25,25 +24,11 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class InvalidationSessionTest extends AbstractClusteredInvalidationSessionTest { - public static GCloudSessionTestSupport __testSupport; - - @BeforeAll - public static void setUp() throws Exception - { - __testSupport = new GCloudSessionTestSupport(); - __testSupport.setUp(); - } - - @AfterAll - public static void tearDown() throws Exception - { - __testSupport.deleteSessions(); - __testSupport.tearDown(); - } + public GCloudSessionTestSupport testSupport = new GCloudSessionTestSupport(getClass().getSimpleName()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore()); + return testSupport.newSessionDataStoreFactory(); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/pom.xml b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/pom.xml index c4bec44152f..325adea57f9 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/pom.xml +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/pom.xml @@ -10,36 +10,9 @@ EE10 :: Tests :: Sessions :: Hazelcast ${project.groupId}.sessions.hazelcast - false - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-test-resources - - unpack - - - - - org.eclipse.jetty.toolchain - jetty-test-policy - ${jetty-test-policy.version} - jar - true - **/*.keystore,**/*.pem - ${jetty.test.policy.loc} - - - - - - org.apache.maven.plugins maven-surefire-plugin @@ -120,6 +93,11 @@ jetty-slf4j-impl test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/ClusteredOrphanedSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/ClusteredOrphanedSessionTest.java index c3ea286bbcb..ee2973282f6 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/ClusteredOrphanedSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/ClusteredOrphanedSessionTest.java @@ -14,10 +14,9 @@ package org.eclipse.jetty.ee10.session.hazelcast; import org.eclipse.jetty.ee10.session.AbstractClusteredOrphanedSessionTest; -import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; /** * ClusteredOrphanedSessionTest @@ -26,15 +25,7 @@ import org.junit.jupiter.api.BeforeEach; public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest { - HazelcastSessionDataStoreFactory factory; - - HazelcastTestHelper _testHelper; - - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @AfterEach public void shutdown() diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/ClusteredSessionScavengingTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/ClusteredSessionScavengingTest.java index fa1716bdcfb..11a48312214 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/ClusteredSessionScavengingTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/ClusteredSessionScavengingTest.java @@ -14,10 +14,9 @@ package org.eclipse.jetty.ee10.session.hazelcast; import org.eclipse.jetty.ee10.session.AbstractClusteredSessionScavengingTest; -import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; /** * ClusteredSessionScavengingTest @@ -25,15 +24,7 @@ import org.junit.jupiter.api.BeforeEach; public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest { - HazelcastSessionDataStoreFactory factory; - - HazelcastTestHelper _testHelper; - - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @AfterEach public void shutdown() diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastClusteredInvalidationSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastClusteredInvalidationSessionTest.java index 8ebd4cf5b0f..13f51ee4ea8 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastClusteredInvalidationSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastClusteredInvalidationSessionTest.java @@ -16,21 +16,15 @@ package org.eclipse.jetty.ee10.session.hazelcast; import org.eclipse.jetty.ee10.session.AbstractClusteredInvalidationSessionTest; import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; public class HazelcastClusteredInvalidationSessionTest extends AbstractClusteredInvalidationSessionTest { HazelcastSessionDataStoreFactory factory; - HazelcastTestHelper _testHelper; - - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @AfterEach public void shutdown() diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastSessionDataStoreTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastSessionDataStoreTest.java index d097c921f6e..faf7ad4f074 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastSessionDataStoreTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastSessionDataStoreTest.java @@ -24,8 +24,8 @@ import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.UnreadableSessionDataException; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.fail; @@ -35,25 +35,19 @@ import static org.junit.jupiter.api.Assertions.fail; */ public class HazelcastSessionDataStoreTest extends AbstractSessionDataStoreTest { + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); + public HazelcastSessionDataStoreTest() throws Exception { super(); } - HazelcastTestHelper _testHelper; - @Override public SessionDataStoreFactory createSessionDataStoreFactory() { return _testHelper.createSessionDataStoreFactory(false); } - @BeforeEach - public void configure() - { - _testHelper = new HazelcastTestHelper(); - } - @AfterEach public void shutdown() { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/ClientOrphanedSessionClientTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/ClientOrphanedSessionClientTest.java index c0c91888d20..4d7db6ab40d 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/ClientOrphanedSessionClientTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/ClientOrphanedSessionClientTest.java @@ -14,15 +14,14 @@ package org.eclipse.jetty.ee10.session.hazelcast.client; import org.eclipse.jetty.ee10.session.AbstractClusteredOrphanedSessionTest; -import org.eclipse.jetty.ee10.session.hazelcast.HazelcastTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; public class ClientOrphanedSessionClientTest extends AbstractClusteredOrphanedSessionTest { - HazelcastTestHelper _testHelper; + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() @@ -30,12 +29,6 @@ public class ClientOrphanedSessionClientTest return _testHelper.createSessionDataStoreFactory(true); } - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } - @AfterEach public void shutdown() { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/ClientSessionScavengingClientTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/ClientSessionScavengingClientTest.java index 6fb227d6044..c8ce2c3629d 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/ClientSessionScavengingClientTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/ClientSessionScavengingClientTest.java @@ -14,15 +14,14 @@ package org.eclipse.jetty.ee10.session.hazelcast.client; import org.eclipse.jetty.ee10.session.AbstractClusteredSessionScavengingTest; -import org.eclipse.jetty.ee10.session.hazelcast.HazelcastTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; public class ClientSessionScavengingClientTest extends AbstractClusteredSessionScavengingTest { - HazelcastTestHelper _testHelper; + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() @@ -30,12 +29,6 @@ public class ClientSessionScavengingClientTest return _testHelper.createSessionDataStoreFactory(true); } - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } - @AfterEach public void shutdown() { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/HazelcastSessionDataStoreClientTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/HazelcastSessionDataStoreClientTest.java index 4388606f6a0..45efafd351d 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/HazelcastSessionDataStoreClientTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/client/HazelcastSessionDataStoreClientTest.java @@ -14,7 +14,6 @@ package org.eclipse.jetty.ee10.session.hazelcast.client; import org.eclipse.jetty.ee10.servlet.ServletContextHandler; -import org.eclipse.jetty.ee10.session.hazelcast.HazelcastTestHelper; import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStore; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; @@ -25,8 +24,8 @@ import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.UnreadableSessionDataException; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.fail; @@ -41,7 +40,7 @@ public class HazelcastSessionDataStoreClientTest extends AbstractSessionDataStor super(); } - HazelcastTestHelper _testHelper; + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() @@ -49,12 +48,6 @@ public class HazelcastSessionDataStoreClientTest extends AbstractSessionDataStor return _testHelper.createSessionDataStoreFactory(true); } - @BeforeEach - public void configure() - { - _testHelper = new HazelcastTestHelper(); - } - @AfterEach public void shutdown() { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/pom.xml b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/pom.xml index 4011d0076e9..db880e4f0f3 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/pom.xml +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/pom.xml @@ -9,10 +9,7 @@ jetty-ee10-test-sessions-infinispan EE10 :: Tests :: Sessions :: Infinispan - true ${project.groupId}.sessions.infinispan - - 11.0.9.Final infinispan/server @@ -32,32 +29,6 @@ - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-test-resources - - unpack - - - - - org.eclipse.jetty.toolchain - jetty-test-policy - ${jetty-test-policy.version} - jar - true - **/*.keystore,**/*.pem - ${jetty.test.policy.loc} - - - - - - @@ -113,10 +84,10 @@ infinispan-core test - - org.wildfly.common - wildfly-common - + + org.wildfly.common + wildfly-common + @@ -170,6 +141,11 @@ junit-jupiter test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredOrphanedSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredOrphanedSessionTest.java index 5667e8bdab1..13a2e79a9f4 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredOrphanedSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredOrphanedSessionTest.java @@ -16,6 +16,7 @@ package org.eclipse.jetty.ee10.session.infinispan; import org.eclipse.jetty.ee10.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.AfterEach; @@ -31,17 +32,21 @@ public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessi public WorkDir workDir; public InfinispanTestSupport testSupport; + public ClusteredOrphanedSessionTest() + { + testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + } + @BeforeEach public void setup() throws Exception { - testSupport = new InfinispanTestSupport(); testSupport.setup(workDir.getEmptyPathDir()); } @AfterEach public void teardown() throws Exception { - testSupport.teardown(); + testSupport.clearCache(); } @Override diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredSerializedSessionScavengingTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredSerializedSessionScavengingTest.java index ab89a3dc5c8..0b228d2cd57 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredSerializedSessionScavengingTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredSerializedSessionScavengingTest.java @@ -16,6 +16,7 @@ package org.eclipse.jetty.ee10.session.infinispan; import org.eclipse.jetty.ee10.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.AfterEach; @@ -30,12 +31,12 @@ import org.junit.jupiter.api.extension.ExtendWith; public class ClusteredSerializedSessionScavengingTest extends AbstractClusteredSessionScavengingTest { public WorkDir workDir; - public static InfinispanTestSupport testSupport; + public InfinispanTestSupport testSupport; @BeforeEach public void setup() throws Exception { - testSupport = new InfinispanTestSupport(); + testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); testSupport.setUseFileStore(true); testSupport.setSerializeSessionData(true); testSupport.setup(workDir.getEmptyPathDir()); @@ -45,7 +46,7 @@ public class ClusteredSerializedSessionScavengingTest extends AbstractClusteredS public void teardown() throws Exception { if (testSupport != null) - testSupport.teardown(); + testSupport.clearCache(); } @Override @@ -56,9 +57,6 @@ public class ClusteredSerializedSessionScavengingTest extends AbstractClusteredS super.testClusteredScavenge(); } - /** - * @see org.eclipse.jetty.server.session.AbstractSessionTestBase#createSessionDataStoreFactory() - */ @Override public SessionDataStoreFactory createSessionDataStoreFactory() { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredSessionScavengingTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredSessionScavengingTest.java index ea1cdec5c1d..28f37a7d949 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredSessionScavengingTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/ClusteredSessionScavengingTest.java @@ -16,6 +16,7 @@ package org.eclipse.jetty.ee10.session.infinispan; import org.eclipse.jetty.ee10.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.AfterEach; @@ -35,7 +36,7 @@ public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScav @BeforeEach public void setup() throws Exception { - testSupport = new InfinispanTestSupport(); + testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); testSupport.setUseFileStore(true); testSupport.setup(workDir.getEmptyPathDir()); } @@ -44,7 +45,7 @@ public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScav public void teardown() throws Exception { if (testSupport != null) - testSupport.teardown(); + testSupport.clearCache(); } @Override diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanFileSessionDataStoreTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanFileSessionDataStoreTest.java index 81ba1ed1a92..7bb029e9d76 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanFileSessionDataStoreTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanFileSessionDataStoreTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.EmbeddedQueryManager; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.QueryManager; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.BeforeEach; @@ -38,7 +39,7 @@ public class InfinispanFileSessionDataStoreTest extends InfinispanSessionDataSto @BeforeEach public void configure() throws Exception { - _testSupport = new InfinispanTestSupport(); + _testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); _testSupport.setUseFileStore(true); _testSupport.setup(workDir.getEmptyPathDir()); } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanSessionDataStoreTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanSessionDataStoreTest.java index c5240101d45..c13cef1ff00 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanSessionDataStoreTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanSessionDataStoreTest.java @@ -26,6 +26,7 @@ import org.eclipse.jetty.session.infinispan.InfinispanSessionData; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStore; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.QueryManager; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.infinispan.query.Search; @@ -59,14 +60,14 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest @BeforeEach public void configure() throws Exception { - _testSupport = new InfinispanTestSupport(); + _testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); _testSupport.setup(workDir.getEmptyPathDir()); } @AfterEach public void teardown() throws Exception { - _testSupport.teardown(); + _testSupport.clearCache(); } @Override @@ -86,7 +87,7 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - _testSupport.createSession(data); + _testSupport.createSession((InfinispanSessionData)data); } finally { @@ -120,6 +121,7 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest * try and provoke an exception in the InfinispanSessionDataStore.load() method. */ @Override + @Test public void testLoadSessionFails() throws Exception { setUp(); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/LoggingUtil.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/LoggingUtil.java deleted file mode 100644 index 4e23ee56676..00000000000 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/LoggingUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.session.infinispan; - -public final class LoggingUtil -{ - /** - * It's easier to setup logging in code for this test project, - * then it is to setup the various system properties and files for every test - * execution (maven, CI, and IDE). - */ - public static void init() - { - // Wire up jboss logging (used by infinispan) to slf4j - System.setProperty("org.jboss.logging.provider", "slf4j"); - - // Wire up java.util.logging (used by hibernate, infinispan, and others) to slf4j. - if (!org.slf4j.bridge.SLF4JBridgeHandler.isInstalled()) - { - org.slf4j.bridge.SLF4JBridgeHandler.install(); - } - } -} diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/SerializedInfinispanSessionDataStoreTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/SerializedInfinispanSessionDataStoreTest.java index 31a2ec930a6..91d1311b98d 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/SerializedInfinispanSessionDataStoreTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/SerializedInfinispanSessionDataStoreTest.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.session.infinispan.InfinispanSessionData; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStore; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.QueryManager; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.infinispan.query.Search; @@ -60,7 +61,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat @BeforeEach public void setup() throws Exception { - _testSupport = new InfinispanTestSupport(); + _testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); _testSupport.setSerializeSessionData(true); _testSupport.setup(workDir.getEmptyPathDir()); } @@ -68,7 +69,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat @AfterEach public void teardown() throws Exception { - _testSupport.teardown(); + _testSupport.clearCache(); } @Override @@ -89,7 +90,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - _testSupport.createSession(data); + _testSupport.createSession((InfinispanSessionData)data); } finally { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteClusteredInvalidationSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteClusteredInvalidationSessionTest.java index 131fd767bdf..61114dc404a 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteClusteredInvalidationSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteClusteredInvalidationSessionTest.java @@ -14,11 +14,10 @@ package org.eclipse.jetty.ee10.session.infinispan.remote; import org.eclipse.jetty.ee10.session.AbstractClusteredInvalidationSessionTest; -import org.eclipse.jetty.ee10.session.infinispan.LoggingUtil; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.LoggingUtil; +import org.eclipse.jetty.session.test.tools.RemoteInfinispanTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -33,27 +32,19 @@ public class RemoteClusteredInvalidationSessionTest extends AbstractClusteredInv LoggingUtil.init(); } - public static RemoteInfinispanTestSupport __testSupport; + public RemoteInfinispanTestSupport testSupport; - @BeforeAll - public static void setup() throws Exception + public RemoteClusteredInvalidationSessionTest() throws Exception { - __testSupport = new RemoteInfinispanTestSupport("remote-session-test"); - __testSupport.setup(); - } - - @AfterAll - public static void teardown() throws Exception - { - __testSupport.teardown(); - __testSupport.shutdown(); + testSupport = new RemoteInfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + testSupport.setup(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); - factory.setCache(__testSupport.getCache()); + factory.setCache(testSupport.getCache()); return factory; } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteClusteredSessionScavengingTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteClusteredSessionScavengingTest.java index 58f43f0cff2..9d28bb6c91d 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteClusteredSessionScavengingTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteClusteredSessionScavengingTest.java @@ -14,11 +14,10 @@ package org.eclipse.jetty.ee10.session.infinispan.remote; import org.eclipse.jetty.ee10.session.AbstractClusteredSessionScavengingTest; -import org.eclipse.jetty.ee10.session.infinispan.LoggingUtil; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.LoggingUtil; +import org.eclipse.jetty.session.test.tools.RemoteInfinispanTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -33,27 +32,19 @@ public class RemoteClusteredSessionScavengingTest extends AbstractClusteredSessi LoggingUtil.init(); } - public static RemoteInfinispanTestSupport __testSupport; + public RemoteInfinispanTestSupport testSupport; - @BeforeAll - public static void setup() throws Exception + public RemoteClusteredSessionScavengingTest() throws Exception { - __testSupport = new RemoteInfinispanTestSupport("remote-session-test"); - __testSupport.setup(); - } - - @AfterAll - public static void teardown() throws Exception - { - __testSupport.teardown(); - __testSupport.shutdown(); + testSupport = new RemoteInfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + testSupport.setup(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); - factory.setCache(__testSupport.getCache()); + factory.setCache(testSupport.getCache()); return factory; } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteInfinispanSessionDataStoreTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteInfinispanSessionDataStoreTest.java index b4ae37a20d8..a8789237e7d 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteInfinispanSessionDataStoreTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteInfinispanSessionDataStoreTest.java @@ -14,7 +14,6 @@ package org.eclipse.jetty.ee10.session.infinispan.remote; import org.eclipse.jetty.ee10.servlet.ServletContextHandler; -import org.eclipse.jetty.ee10.session.infinispan.LoggingUtil; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.AbstractSessionDataStoreTest; @@ -28,13 +27,13 @@ import org.eclipse.jetty.session.infinispan.InfinispanSessionData; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStore; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.RemoteQueryManager; +import org.eclipse.jetty.session.test.tools.LoggingUtil; +import org.eclipse.jetty.session.test.tools.RemoteInfinispanTestSupport; import org.infinispan.client.hotrod.Search; import org.infinispan.query.dsl.Query; import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.dsl.QueryResult; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Testcontainers; @@ -54,43 +53,32 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto LoggingUtil.init(); } - public static RemoteInfinispanTestSupport __testSupport; + public RemoteInfinispanTestSupport testSupport; public RemoteInfinispanSessionDataStoreTest() throws Exception { super(); - } - - @BeforeAll - public static void initRemoteSupport() throws Exception - { - __testSupport = new RemoteInfinispanTestSupport("remote-session-test"); + testSupport = new RemoteInfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); } @BeforeEach public void configure() throws Exception { - __testSupport.setup(); + testSupport.setup(); } @AfterEach public void teardown() throws Exception { - __testSupport.teardown(); - } - - @AfterAll - public static void shutdown() throws Exception - { - __testSupport.shutdown(); + testSupport.clearCache(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); - factory.setCache(__testSupport.getCache()); - factory.setQueryManager(new RemoteQueryManager(__testSupport.getCache())); + factory.setCache(testSupport.getCache()); + factory.setQueryManager(new RemoteQueryManager(testSupport.getCache())); return factory; } @@ -101,7 +89,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - __testSupport.createSession((InfinispanSessionData)data); + testSupport.createSession((InfinispanSessionData)data); } finally { @@ -123,7 +111,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return __testSupport.checkSessionExists((InfinispanSessionData)data); + return testSupport.checkSessionExists((InfinispanSessionData)data); } finally { @@ -138,7 +126,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return __testSupport.checkSessionPersisted(data); + return testSupport.checkSessionPersisted(data); } finally { @@ -151,6 +139,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto * try and provoke an exception in the InfinispanSessionDataStore.load() method. */ @Override + @Test public void testLoadSessionFails() throws Exception { DefaultSessionIdManager idMgr = new DefaultSessionIdManager(new Server()); @@ -158,6 +147,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/test"); context.getSessionHandler().setSessionIdManager(idMgr); + idMgr.setWorkerName(""); SessionDataStoreFactory factory = createSessionDataStoreFactory(); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); @@ -184,19 +174,19 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000); sd1.setLastNode("fred1"); sd1.serializeAttributes(); - __testSupport.getCache().put("session1", sd1); + testSupport.getCache().put("session1", sd1); InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000); sd2.setLastNode("fred2"); sd2.serializeAttributes(); - __testSupport.getCache().put("session2", sd2); + testSupport.getCache().put("session2", sd2); InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000); sd3.setLastNode("fred3"); sd3.serializeAttributes(); - __testSupport.getCache().put("session3", sd3); + testSupport.getCache().put("session3", sd3); - QueryFactory qf = Search.getQueryFactory(__testSupport.getCache()); + QueryFactory qf = Search.getQueryFactory(testSupport.getCache()); Query query = qf.create("from org_eclipse_jetty_session_infinispan.InfinispanSessionData where " + " expiry < :time"); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteInfinispanTestSupport.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteInfinispanTestSupport.java deleted file mode 100644 index fef36f86530..00000000000 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/remote/RemoteInfinispanTestSupport.java +++ /dev/null @@ -1,238 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.session.infinispan.remote; - -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.lang.annotation.ElementType; -import java.nio.charset.StandardCharsets; -import java.util.Properties; - -import org.eclipse.jetty.session.SessionData; -import org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer; -import org.eclipse.jetty.session.infinispan.InfinispanSessionData; -import org.eclipse.jetty.util.IO; -import org.hibernate.search.cfg.Environment; -import org.hibernate.search.cfg.SearchMapping; -import org.infinispan.client.hotrod.RemoteCache; -import org.infinispan.client.hotrod.RemoteCacheManager; -import org.infinispan.client.hotrod.configuration.ClientIntelligence; -import org.infinispan.client.hotrod.configuration.Configuration; -import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; -import org.infinispan.commons.configuration.XMLStringConfiguration; -import org.infinispan.commons.marshall.ProtoStreamMarshaller; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.BindMode; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.containers.wait.strategy.Wait; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * RemoteInfinispanTestSupport - */ -public class RemoteInfinispanTestSupport -{ - private static final Logger LOG = LoggerFactory.getLogger(RemoteInfinispanTestSupport.class); - public static final String DEFAULT_CACHE_NAME = "session_test_cache"; - public RemoteCache _cache; - private final String _name; - public RemoteCacheManager _manager; - private static final Logger INFINISPAN_LOG = - LoggerFactory.getLogger("org.eclipse.jetty.server.session.remote.infinispanLogs"); - - private static final String IMAGE_NAME = System.getProperty("infinispan.docker.image.name", "infinispan/server") + - ":" + System.getProperty("infinispan.docker.image.version", "11.0.9.Final"); - - private final GenericContainer infinispan = new GenericContainer(IMAGE_NAME) - .withEnv("USER", "theuser") - .withEnv("PASS", "foobar") - .withEnv("MGMT_USER", "admin") - .withEnv("MGMT_PASS", "admin") - .withEnv("CONFIG_PATH", "/user-config/config.yaml") - .waitingFor(Wait.forLogMessage(".*Infinispan Server.*started in.*\\s", 1)) - .withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224) - .withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG)) - .withClasspathResourceMapping("/config.yaml", "/user-config/config.yaml", BindMode.READ_ONLY); - private static final String INFINISPAN_VERSION = System.getProperty("infinispan.docker.image.version", "11.0.9.Final"); - - public RemoteInfinispanTestSupport() - { - this(null); - } - - public RemoteInfinispanTestSupport(String cacheName) - { - if (cacheName == null) - cacheName = DEFAULT_CACHE_NAME + System.nanoTime(); - - _name = cacheName; - - if (!infinispan.isRunning()) - { - try - { - long start = System.currentTimeMillis(); - - infinispan.start(); - System.setProperty("hotrod.host", infinispan.getContainerIpAddress()); - - LOG.info("Infinispan container started for {}:{} - {}ms", - infinispan.getContainerIpAddress(), - infinispan.getMappedPort(11222), - System.currentTimeMillis() - start); - } - catch (Exception e) - { - LOG.error(e.getMessage(), e); - throw new RuntimeException(e); - } - } - try - { - SearchMapping mapping = new SearchMapping(); - mapping.entity(InfinispanSessionData.class).indexed().providedId() - .property("expiry", ElementType.METHOD).field(); - - Properties properties = new Properties(); - properties.put(Environment.MODEL_MAPPING, mapping); - - ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().withProperties(properties) - .addServer() - .host(infinispan.getContainerIpAddress()) - .port(infinispan.getMappedPort(11222)) - // we just want to limit connectivity to list of host:port we knows at start - // as infinispan create new host:port dynamically but due to how docker expose host/port we cannot do that - .clientIntelligence(ClientIntelligence.BASIC) - .marshaller(new ProtoStreamMarshaller()); - - if (INFINISPAN_VERSION.startsWith("1")) - { - configurationBuilder.security().authentication() - .saslMechanism("DIGEST-MD5") - .username("theuser").password("foobar"); - } - - configurationBuilder.addContextInitializer(new InfinispanSerializationContextInitializer()); - Configuration configuration = configurationBuilder.build(); - - _manager = new RemoteCacheManager(configuration); - - //upload the session.proto file to the remote cache - ByteArrayOutputStream baos; - try (InputStream is = RemoteInfinispanSessionDataStoreTest.class.getClassLoader().getResourceAsStream("session.proto")) - { - if (is == null) - throw new IllegalStateException("inputstream is null"); - - baos = new ByteArrayOutputStream(); - IO.copy(is, baos); - } - - String content = baos.toString(StandardCharsets.UTF_8); - _manager.administration().getOrCreateCache("___protobuf_metadata", (String)null).put("session.proto", content); - } - catch (Exception e) - { - LOG.error(e.getMessage(), e); - throw new RuntimeException(e); - } - - } - - public RemoteCache getCache() - { - return _cache; - } - - public void setup() throws Exception - { - String xml = String.format("" + - "" + "" + - "" + - "" + - "" + - "", _name); - - XMLStringConfiguration xmlConfig = new XMLStringConfiguration(xml); - _cache = _manager.administration().getOrCreateCache(_name, xmlConfig); - } - - public void teardown() throws Exception - { - _cache.clear(); - } - - public void shutdown() throws Exception - { - infinispan.stop(); - } - - public void createSession(InfinispanSessionData data) - throws Exception - { - data.serializeAttributes(); - _cache.put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data); - } - - public void createUnreadableSession(InfinispanSessionData data) - { - //Unused by test - } - - public boolean checkSessionExists(InfinispanSessionData data) - throws Exception - { - return (_cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()) != null); - } - - public boolean checkSessionPersisted(SessionData data) - throws Exception - { - Object obj = _cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); - if (obj == null) - return false; - - InfinispanSessionData saved = (InfinispanSessionData)obj; - if (saved.getSerializedAttributes() != null) - saved.deserializeAttributes(); - - assertEquals(data.getId(), saved.getId()); - assertEquals(data.getContextPath(), saved.getContextPath()); - assertEquals(data.getVhost(), saved.getVhost()); - assertEquals(data.getAccessed(), saved.getAccessed()); - assertEquals(data.getLastAccessed(), saved.getLastAccessed()); - assertEquals(data.getCreated(), saved.getCreated()); - assertEquals(data.getCookieSet(), saved.getCookieSet()); - assertEquals(data.getLastNode(), saved.getLastNode()); - //don't test lastSaved because that is set on SessionData only after return from SessionDataStore.save() - assertEquals(data.getExpiry(), saved.getExpiry()); - assertEquals(data.getMaxInactiveMs(), saved.getMaxInactiveMs()); - - //same number of attributes - assertEquals(data.getAllAttributes().size(), saved.getAllAttributes().size()); - //same keys - assertTrue(data.getKeys().equals(saved.getKeys())); - //same values - for (String name : data.getKeys()) - { - assertTrue(data.getAttribute(name).equals(saved.getAttribute(name))); - } - - return true; - } -} diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/pom.xml b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/pom.xml index 7b0725cd9b1..8a5b9d29812 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/pom.xml +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/pom.xml @@ -9,7 +9,6 @@ jetty-ee10-test-sessions-jdbc EE10 :: Tests :: Sessions :: JDBC - false ${project.groupId}.sessions.jdbc @@ -92,5 +91,10 @@ mariadb-java-client test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredInvalidationSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredInvalidationSessionTest.java index 6cadfc18a84..d1350738d58 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredInvalidationSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredInvalidationSessionTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.ee10.session.AbstractClusteredInvalidationSessionTest; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -25,15 +26,24 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredInvalidationSessionTest extends AbstractClusteredInvalidationSessionTest { + + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() throws Exception + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + } + @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredOrphanedSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredOrphanedSessionTest.java index 8d77b04528f..264007cecdf 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredOrphanedSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredOrphanedSessionTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.ee10.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -25,15 +26,24 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest { + + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() throws Exception + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + } + @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredSessionMigrationTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredSessionMigrationTest.java index 3ba0d6ea925..475229c0571 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredSessionMigrationTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredSessionMigrationTest.java @@ -23,7 +23,6 @@ import jakarta.servlet.http.HttpSession; import org.eclipse.jetty.client.ContentResponse; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.Request; -import org.eclipse.jetty.ee10.session.AbstractSessionTestBase; import org.eclipse.jetty.ee10.session.SessionTestSupport; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; @@ -31,7 +30,9 @@ import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Testcontainers; @@ -51,16 +52,25 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @Testcontainers(disabledWithoutDocker = true) public class ClusteredSessionMigrationTest extends AbstractSessionTestBase { + + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() throws Exception + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + } + @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } @Test diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredSessionScavengingTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredSessionScavengingTest.java index 492f0749bd8..13bf253b148 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredSessionScavengingTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ClusteredSessionScavengingTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.ee10.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -25,15 +26,23 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest { + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() throws Exception + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + } + @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/JDBCSessionDataStoreTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/JDBCSessionDataStoreTest.java index 6f5db2ef3b9..4d585c8f7e3 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/JDBCSessionDataStoreTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/JDBCSessionDataStoreTest.java @@ -33,29 +33,32 @@ public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest super(); } + private String sessionTableName; + @BeforeEach - public void configure() throws Exception + public void setupSessionTableName() throws Exception { - JdbcTestHelper.prepareTables(); + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + JdbcTestHelper.prepareTables(sessionTableName); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @Override public void persistSession(SessionData data) throws Exception { - JdbcTestHelper.insertSession(data); + JdbcTestHelper.insertSession(data, sessionTableName); } @Override @@ -64,7 +67,7 @@ public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest JdbcTestHelper.insertUnreadableSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), data.getCookieSet(), - data.getLastSaved()); + data.getLastSaved(), sessionTableName); } @Test @@ -76,7 +79,7 @@ public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest @Override public boolean checkSessionExists(SessionData data) throws Exception { - return JdbcTestHelper.existsInSessionTable(data.getId(), false); + return JdbcTestHelper.existsInSessionTable(data.getId(), false, sessionTableName); } @Override @@ -86,7 +89,7 @@ public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return JdbcTestHelper.checkSessionPersisted(data); + return JdbcTestHelper.checkSessionPersisted(data, sessionTableName); } finally { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ReloadedSessionMissingClassTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ReloadedSessionMissingClassTest.java index e051636a0e4..dcb19d42611 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ReloadedSessionMissingClassTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/ReloadedSessionMissingClassTest.java @@ -35,6 +35,7 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.testcontainers.junit.jupiter.Testcontainers; @@ -52,6 +53,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @ExtendWith(WorkDirExtension.class) public class ReloadedSessionMissingClassTest { + + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() throws Exception + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + JdbcTestHelper.prepareTables(sessionTableName); + } + @Test public void testSessionReloadWithMissingClass(WorkDir workDir) throws Exception { @@ -88,7 +99,7 @@ public class ReloadedSessionMissingClassTest DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT); - SessionDataStoreFactory storeFactory = JdbcTestHelper.newSessionDataStoreFactory(); + SessionDataStoreFactory storeFactory = JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); ((AbstractSessionDataStoreFactory)storeFactory).setGracePeriodSec(SessionTestSupport.DEFAULT_SCAVENGE_SEC); SessionTestSupport server1 = new SessionTestSupport(0, SessionTestSupport.DEFAULT_MAX_INACTIVE, SessionTestSupport.DEFAULT_SCAVENGE_SEC, cacheFactory, storeFactory); @@ -146,6 +157,6 @@ public class ReloadedSessionMissingClassTest @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/SessionTableSchemaTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/SessionTableSchemaTest.java index 71e51096eb3..cabe98039b5 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/SessionTableSchemaTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/SessionTableSchemaTest.java @@ -45,9 +45,12 @@ public class SessionTableSchemaTest DatabaseAdaptor _da; JDBCSessionDataStore.SessionTableSchema _tableSchema; + private String sessionTableName; + @BeforeEach public void setUp() throws Exception { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); //pretend to be an Oracle-like database that treats "" as NULL _da = new DatabaseAdaptor() { @@ -59,14 +62,14 @@ public class SessionTableSchemaTest } }; _da.setDriverInfo(JdbcTestHelper.DRIVER_CLASS, JdbcTestHelper.DEFAULT_CONNECTION_URL); - _tableSchema = JdbcTestHelper.newSessionTableSchema(); + _tableSchema = JdbcTestHelper.newSessionTableSchema(sessionTableName); JdbcTestHelper.setDatabaseAdaptor(_tableSchema, _da); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } /** @@ -79,12 +82,12 @@ public class SessionTableSchemaTest * @param vhost the virtual host of the session * @throws Exception */ - public static void insertSessionWithoutAttributes(String id, String contextPath, String vhost) + public void insertSessionWithoutAttributes(String id, String contextPath, String vhost) throws Exception { try (Connection con = JdbcTestHelper.getConnection()) { - PreparedStatement statement = con.prepareStatement("insert into " + JdbcTestHelper.TABLE + + PreparedStatement statement = con.prepareStatement("insert into " + sessionTableName + " (" + JdbcTestHelper.ID_COL + ", " + JdbcTestHelper.CONTEXT_COL + ", virtualHost, " + JdbcTestHelper.LAST_NODE_COL + ", " + JdbcTestHelper.ACCESS_COL + ", " + JdbcTestHelper.LAST_ACCESS_COL + ", " + JdbcTestHelper.CREATE_COL + ", " + JdbcTestHelper.COOKIE_COL + ", " + JdbcTestHelper.LAST_SAVE_COL + ", " + JdbcTestHelper.EXPIRY_COL + " " + ") " + @@ -186,7 +189,7 @@ public class SessionTableSchemaTest PreparedStatement s = _tableSchema.getDeleteStatement(con, id, sc); assertEquals(1, s.executeUpdate()); - assertFalse(JdbcTestHelper.existsInSessionTable(id, false)); + assertFalse(JdbcTestHelper.existsInSessionTable(id, false, sessionTableName)); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/WebAppObjectInSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/WebAppObjectInSessionTest.java index 3773efd25bd..fa6c42f871c 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/WebAppObjectInSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee10/session/jdbc/WebAppObjectInSessionTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.ee10.session.AbstractWebAppObjectInSessionTest; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Testcontainers; @@ -27,10 +28,20 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class WebAppObjectInSessionTest extends AbstractWebAppObjectInSessionTest { + + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() throws Exception + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + JdbcTestHelper.prepareTables(sessionTableName); + } + @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @Test @@ -42,6 +53,6 @@ public class WebAppObjectInSessionTest extends AbstractWebAppObjectInSessionTest @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/pom.xml b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/pom.xml index 402c3942686..88a80bc0dd5 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/pom.xml +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/pom.xml @@ -57,5 +57,10 @@ junit-jupiter test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee10/session/memcached/CachingSessionDataStoreTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee10/session/memcached/CachingSessionDataStoreTest.java index 330d2bc8310..50f738b30be 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee10/session/memcached/CachingSessionDataStoreTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee10/session/memcached/CachingSessionDataStoreTest.java @@ -25,13 +25,13 @@ import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.Request; import org.eclipse.jetty.ee10.servlet.ServletContextHandler; import org.eclipse.jetty.ee10.session.SessionTestSupport; -import org.eclipse.jetty.ee10.session.memcached.MemcachedTestHelper.MockDataStore; import org.eclipse.jetty.session.CachingSessionDataStore; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataMap; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MemcachedTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Testcontainers; @@ -93,11 +93,11 @@ public class CachingSessionDataStoreTest // //Update a session and check that is is NOT loaded via the persistent store // - ((MockDataStore)persistentStore).zeroLoadCount(); + ((MemcachedTestHelper.MockDataStore)persistentStore).zeroLoadCount(); Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=update"); response = request.send(); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); - assertEquals(0, ((MockDataStore)persistentStore).getLoadCount()); + assertEquals(0, ((MemcachedTestHelper.MockDataStore)persistentStore).getLoadCount()); //check it was updated in the persistent store SessionData sd = persistentStore.load(id); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee10/session/memcached/MemcachedTestHelper.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee10/session/memcached/MemcachedTestHelper.java deleted file mode 100644 index edcb1075563..00000000000 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee10/session/memcached/MemcachedTestHelper.java +++ /dev/null @@ -1,200 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.session.memcached; - -import java.net.InetSocketAddress; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import net.rubyeye.xmemcached.XMemcachedClientBuilder; -import org.eclipse.jetty.memcached.session.MemcachedSessionDataMapFactory; -import org.eclipse.jetty.session.AbstractSessionDataStore; -import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; -import org.eclipse.jetty.session.CachingSessionDataStoreFactory; -import org.eclipse.jetty.session.SessionData; -import org.eclipse.jetty.session.SessionDataStore; -import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.eclipse.jetty.session.SessionManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.output.Slf4jLogConsumer; - -/** - * MemcachedTestHelper - */ -public class MemcachedTestHelper -{ - - public static class MockDataStore extends AbstractSessionDataStore - { - private Map _store = new HashMap<>(); - private int _loadCount = 0; - - @Override - public boolean isPassivating() - { - return true; - } - - @Override - public boolean doExists(String id) throws Exception - { - return _store.get(id) != null; - } - - @Override - public SessionData doLoad(String id) throws Exception - { - _loadCount++; - return _store.get(id); - } - - public void zeroLoadCount() - { - _loadCount = 0; - } - - public int getLoadCount() - { - return _loadCount; - } - - @Override - public boolean delete(String id) throws Exception - { - return (_store.remove(id) != null); - } - - @Override - public void doStore(String id, SessionData data, long lastSaveTime) throws Exception - { - _store.put(id, data); - } - - @Override - public Set doCheckExpired(Set candidates, long time) - { - Set expiredIds = new HashSet<>(); - if (candidates != null) - { - for (String id : candidates) - { - SessionData sd = _store.get(id); - if (sd == null) - expiredIds.add(id); - else if (sd.isExpiredAt(time)) - expiredIds.add(id); - } - } - - for (String id : _store.keySet()) - { - SessionData sd = _store.get(id); - if (sd.isExpiredAt(time)) - expiredIds.add(id); - } - - return expiredIds; - } - - @Override - public Set doGetExpired(long timeLimit) - { - return Collections.emptySet(); - } - - @Override - public void doCleanOrphans(long timeLimit) - { - //noop - } - - @Override - protected void doStop() throws Exception - { - super.doStop(); - } - } - - public static class MockDataStoreFactory extends AbstractSessionDataStoreFactory - { - - @Override - public SessionDataStore getSessionDataStore(SessionManager manager) throws Exception - { - return new MockDataStore(); - } - } - - private static final Logger LOG = LoggerFactory.getLogger(MemcachedTestHelper.class); - - private static final Logger MEMCACHED_LOG = LoggerFactory.getLogger("org.eclipse.jetty.memcached.sessions.MemcachedLogs"); - - @SuppressWarnings({"rawtypes", "unchecked"}) - static GenericContainer memcached = - new GenericContainer("memcached:" + System.getProperty("memcached.docker.version", "1.6.6")) - .withExposedPorts(11211) - .withLogConsumer(new Slf4jLogConsumer(MEMCACHED_LOG)); - - public static void shutdown() throws Exception - { - memcached.stop(); - } - - public static SessionDataStoreFactory newSessionDataStoreFactory() - { - if (!memcached.isRunning()) - { - try - { - long start = System.currentTimeMillis(); - memcached.start(); - LOG.info("time to start memcache instance {}ms on {}:{}", System.currentTimeMillis() - start, - memcached.getHost(), memcached.getMappedPort(11211)); - } - catch (Exception e) - { - LOG.error(e.getMessage(), e); - throw new RuntimeException(e.getMessage(), e); - } - } - MockDataStoreFactory storeFactory = new MockDataStoreFactory(); - MemcachedSessionDataMapFactory mapFactory = new MemcachedSessionDataMapFactory(); - String host = memcached.getContainerIpAddress(); - int port = memcached.getMappedPort(11211); - InetSocketAddress inetSocketAddress = new InetSocketAddress(host, port); - mapFactory.setAddresses(inetSocketAddress); - - try - { - XMemcachedClientBuilder builder = new XMemcachedClientBuilder(Arrays.asList(inetSocketAddress)); - builder.build().flushAll(); - } - catch (Exception e) - { - LOG.error(e.getMessage(), e); - throw new RuntimeException(e.getMessage(), e); - } - - CachingSessionDataStoreFactory factory = new CachingSessionDataStoreFactory(); - factory.setSessionDataMapFactory(mapFactory); - factory.setSessionStoreFactory(storeFactory); - return factory; - } -} diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/pom.xml b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/pom.xml index fe7fccb2c5c..6f7fe9e6004 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/pom.xml +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/pom.xml @@ -9,9 +9,7 @@ jetty-ee10-test-sessions-mongodb EE10 :: Tests :: Sessions :: Mongo - false ${project.groupId}.sessions.mongo - localhost @@ -24,32 +22,6 @@ - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-test-resources - - unpack - - - - - org.eclipse.jetty.toolchain - jetty-test-policy - ${jetty-test-policy.version} - jar - true - **/*.keystore,**/*.pem - ${jetty.test.policy.loc} - - - - - - @@ -125,5 +97,10 @@ slf4j-simple test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/AttributeNameTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/AttributeNameTest.java index e043a65e335..882b5135798 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/AttributeNameTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/AttributeNameTest.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.nosql.mongodb.MongoSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.eclipse.jetty.util.NanoTime; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -48,16 +49,21 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @Testcontainers(disabledWithoutDocker = true) public class AttributeNameTest { + + private static final String DB_NAME = "DB" + AttributeNameTest.class.getSimpleName() + System.nanoTime(); + + private static final String COLLECTION_NAME = "COLLECTION" + AttributeNameTest.class.getSimpleName() + System.nanoTime(); + @BeforeAll public static void beforeClass() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterAll public static void afterClass() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); MongoTestHelper.shutdown(); } @@ -72,7 +78,7 @@ public class AttributeNameTest DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT); - MongoSessionDataStoreFactory storeFactory = MongoTestHelper.newSessionDataStoreFactory(); + MongoSessionDataStoreFactory storeFactory = MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); storeFactory.setGracePeriodSec(scavengePeriod); SessionTestSupport server1 = new SessionTestSupport(0, maxInactivePeriod, scavengePeriod, cacheFactory, storeFactory); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredInvalidateSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredInvalidateSessionTest.java index ec4af878fa8..156631af11c 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredInvalidateSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredInvalidateSessionTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.ee10.session.nosql.mongodb; import org.eclipse.jetty.ee10.session.AbstractClusteredInvalidationSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.testcontainers.junit.jupiter.Testcontainers; @@ -22,22 +23,27 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredInvalidateSessionTest extends AbstractClusteredInvalidationSessionTest { + + private static String DB_NAME = "DB" + ClusteredInvalidateSessionTest.class.getSimpleName() + System.nanoTime(); + + private static String COLLECTION_NAME = "COLLECTION" + ClusteredInvalidateSessionTest.class.getSimpleName() + System.nanoTime(); + @BeforeAll public static void beforeClass() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterAll public static void afterClass() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); MongoTestHelper.shutdown(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return MongoTestHelper.newSessionDataStoreFactory(); + return MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredOrphanedSessionTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredOrphanedSessionTest.java index 13d7e448d02..dcee16e00cb 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredOrphanedSessionTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredOrphanedSessionTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.ee10.session.nosql.mongodb; import org.eclipse.jetty.ee10.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -26,23 +27,27 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest { + private static String DB_NAME = "DB" + ClusteredOrphanedSessionTest.class.getSimpleName() + System.nanoTime(); + + private static String COLLECTION_NAME = "COLLECTION" + ClusteredOrphanedSessionTest.class.getSimpleName() + System.nanoTime(); + @BeforeAll public static void beforeClass() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterAll public static void afterClass() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); MongoTestHelper.shutdown(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return MongoTestHelper.newSessionDataStoreFactory(); + return MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); } @Test diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredSessionScavengingTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredSessionScavengingTest.java index f2ef72761be..641f6637b86 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredSessionScavengingTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/ClusteredSessionScavengingTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.ee10.session.nosql.mongodb; import org.eclipse.jetty.ee10.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.testcontainers.junit.jupiter.Testcontainers; @@ -22,22 +23,26 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest { + private static String DB_NAME = "DB" + ClusteredSessionScavengingTest.class.getSimpleName() + System.nanoTime(); + + private static String COLLECTION_NAME = "COLLECTION" + ClusteredSessionScavengingTest.class.getSimpleName() + System.nanoTime(); + @BeforeAll public static void beforeClass() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterAll public static void afterClass() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); MongoTestHelper.shutdown(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return MongoTestHelper.newSessionDataStoreFactory(); + return MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/MongoSessionDataStoreTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/MongoSessionDataStoreTest.java index a8b6bbfe842..6d4b173128b 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/MongoSessionDataStoreTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/MongoSessionDataStoreTest.java @@ -27,8 +27,10 @@ import org.eclipse.jetty.session.SessionContext; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Testcontainers; @@ -42,6 +44,24 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @Testcontainers(disabledWithoutDocker = true) public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest { + + private static String DB_NAME = "DB" + MongoSessionDataStoreTest.class.getSimpleName() + System.nanoTime(); + + private static String COLLECTION_NAME = "COLLECTION" + MongoSessionDataStoreTest.class.getSimpleName() + System.nanoTime(); + + @BeforeAll + public static void beforeClass() throws Exception + { + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); + } + + @AfterAll + public static void afterClass() throws Exception + { + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); + MongoTestHelper.shutdown(); + } + public MongoSessionDataStoreTest() throws Exception { super(); @@ -50,13 +70,13 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest @BeforeEach public void beforeEach() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterEach public void afterEach() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); } @AfterAll @@ -68,27 +88,29 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return MongoTestHelper.newSessionDataStoreFactory(); + return MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); } @Override public void persistSession(SessionData data) throws Exception { MongoTestHelper.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), - data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), data.getAllAttributes()); + data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), data.getAllAttributes(), + DB_NAME, COLLECTION_NAME); } @Override public void persistUnreadableSession(SessionData data) throws Exception { MongoTestHelper.createUnreadableSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), - data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), null); + data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), null, + DB_NAME, COLLECTION_NAME); } @Override public boolean checkSessionExists(SessionData data) throws Exception { - return MongoTestHelper.checkSessionExists(data.getId()); + return MongoTestHelper.checkSessionExists(data.getId(), DB_NAME, COLLECTION_NAME); } @Override @@ -98,7 +120,7 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return MongoTestHelper.checkSessionPersisted(data); + return MongoTestHelper.checkSessionPersisted(data, DB_NAME, COLLECTION_NAME); } finally { @@ -135,7 +157,8 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest "foo", 1000L, System.currentTimeMillis() - 1000L, System.currentTimeMillis() - 2000L, -1, -1, - attributes); + attributes, + DB_NAME, COLLECTION_NAME); store.start(); @@ -152,6 +175,6 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest store.store("1234", loaded); //and that it has now been written out with the new format - MongoTestHelper.checkSessionPersisted(loaded); + MongoTestHelper.checkSessionPersisted(loaded, DB_NAME, COLLECTION_NAME); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/MongoTestHelper.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/MongoTestHelper.java deleted file mode 100644 index 7cb8e341206..00000000000 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/MongoTestHelper.java +++ /dev/null @@ -1,348 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.session.nosql.mongodb; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectOutputStream; -import java.net.UnknownHostException; -import java.util.Map; - -import com.mongodb.BasicDBObject; -import com.mongodb.DBCollection; -import com.mongodb.DBObject; -import com.mongodb.MongoClient; -import com.mongodb.MongoException; -import com.mongodb.WriteConcern; -import org.eclipse.jetty.nosql.mongodb.MongoSessionDataStore; -import org.eclipse.jetty.nosql.mongodb.MongoSessionDataStoreFactory; -import org.eclipse.jetty.nosql.mongodb.MongoUtils; -import org.eclipse.jetty.session.SessionData; -import org.eclipse.jetty.util.ClassLoadingObjectInputStream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.MongoDBContainer; -import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.utility.DockerImageName; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * MongoTestHelper - */ -public class MongoTestHelper -{ - private static final Logger LOG = LoggerFactory.getLogger(MongoTestHelper.class); - private static final Logger MONGO_LOG = LoggerFactory.getLogger("org.eclipse.jetty.nosql.mongodb.MongoLogs"); - - public static final String DB_NAME = "HttpSessions"; - public static final String COLLECTION_NAME = "testsessions"; - - private static final int MONGO_PORT = 27017; - - static MongoDBContainer mongo = - new MongoDBContainer(DockerImageName.parse("mongo:" + System.getProperty("mongo.docker.version", "3.2.20"))) - .withLogConsumer(new Slf4jLogConsumer(MONGO_LOG)); - - static MongoClient mongoClient; - - static String mongoHost; - static int mongoPort; - - public static MongoClient getMongoClient() throws UnknownHostException - { - if (mongoClient == null) - { - mongoClient = new MongoClient(mongoHost, mongoPort); - } - return mongoClient; - } - - public static void dropCollection() throws Exception - { - getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME).drop(); - } - - public static void shutdown() throws Exception - { - mongo.stop(); - } - - public static void createCollection() throws UnknownHostException, MongoException - { - getMongoClient().getDB(DB_NAME).createCollection(COLLECTION_NAME, null); - } - - public static DBCollection getCollection() throws UnknownHostException, MongoException - { - return getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); - } - - public static MongoSessionDataStoreFactory newSessionDataStoreFactory() - { - if (!mongo.isRunning()) - { - try - { - long start = System.currentTimeMillis(); - mongo.start(); - mongoHost = mongo.getHost(); - mongoPort = mongo.getMappedPort(MONGO_PORT); - LOG.info("Mongo container started for {}:{} - {}ms", mongoHost, mongoPort, - System.currentTimeMillis() - start); - mongoClient = new MongoClient(mongoHost, mongoPort); - } - catch (Exception e) - { - LOG.error(e.getMessage(), e); - throw new RuntimeException(e); - } - } - - MongoSessionDataStoreFactory storeFactory = new MongoSessionDataStoreFactory(); - storeFactory.setHost(mongoHost); - storeFactory.setPort(mongoPort); - storeFactory.setCollectionName(COLLECTION_NAME); - storeFactory.setDbName(DB_NAME); - return storeFactory; - } - - public static boolean checkSessionExists(String id) - throws Exception - { - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); - - DBObject fields = new BasicDBObject(); - fields.put(MongoSessionDataStore.__EXPIRY, 1); - fields.put(MongoSessionDataStore.__VALID, 1); - - DBObject sessionDocument = collection.findOne(new BasicDBObject(MongoSessionDataStore.__ID, id), fields); - - if (sessionDocument == null) - return false; //doesn't exist - - return true; - } - - public static boolean checkSessionPersisted(SessionData data) - throws Exception - { - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); - - DBObject fields = new BasicDBObject(); - - DBObject sessionDocument = collection.findOne(new BasicDBObject(MongoSessionDataStore.__ID, data.getId()), fields); - if (sessionDocument == null) - return false; //doesn't exist - - LOG.debug("{}", sessionDocument); - - Boolean valid = (Boolean)sessionDocument.get(MongoSessionDataStore.__VALID); - - if (valid == null || !valid) - return false; - - Long created = (Long)sessionDocument.get(MongoSessionDataStore.__CREATED); - Long accessed = (Long)sessionDocument.get(MongoSessionDataStore.__ACCESSED); - Long lastAccessed = (Long)sessionDocument.get(MongoSessionDataStore.__LAST_ACCESSED); - Long maxInactive = (Long)sessionDocument.get(MongoSessionDataStore.__MAX_IDLE); - Long expiry = (Long)sessionDocument.get(MongoSessionDataStore.__EXPIRY); - - Object version = MongoUtils.getNestedValue(sessionDocument, - MongoSessionDataStore.__CONTEXT + "." + data.getVhost().replace('.', '_') + ":" + data.getContextPath() + "." + MongoSessionDataStore.__VERSION); - Long lastSaved = (Long)MongoUtils.getNestedValue(sessionDocument, - MongoSessionDataStore.__CONTEXT + "." + data.getVhost().replace('.', '_') + ":" + data.getContextPath() + "." + MongoSessionDataStore.__LASTSAVED); - String lastNode = (String)MongoUtils.getNestedValue(sessionDocument, - MongoSessionDataStore.__CONTEXT + "." + data.getVhost().replace('.', '_') + ":" + data.getContextPath() + "." + MongoSessionDataStore.__LASTNODE); - byte[] attributes = (byte[])MongoUtils.getNestedValue(sessionDocument, - MongoSessionDataStore.__CONTEXT + "." + data.getVhost().replace('.', '_') + ":" + data.getContextPath() + "." + MongoSessionDataStore.__ATTRIBUTES); - - assertEquals(data.getCreated(), created.longValue()); - assertEquals(data.getAccessed(), accessed.longValue()); - assertEquals(data.getLastAccessed(), lastAccessed.longValue()); - assertEquals(data.getMaxInactiveMs(), maxInactive.longValue()); - assertEquals(data.getExpiry(), expiry.longValue()); - assertEquals(data.getLastNode(), lastNode); - assertNotNull(version); - assertNotNull(lastSaved); - - // get the session for the context - DBObject sessionSubDocumentForContext = - (DBObject)MongoUtils.getNestedValue(sessionDocument, - MongoSessionDataStore.__CONTEXT + "." + data.getVhost().replace('.', '_') + ":" + data.getContextPath()); - - assertNotNull(sessionSubDocumentForContext); - - if (!data.getAllAttributes().isEmpty()) - { - assertNotNull(attributes); - SessionData tmp = new SessionData(data.getId(), data.getContextPath(), data.getVhost(), created.longValue(), accessed.longValue(), lastAccessed.longValue(), maxInactive.longValue()); - try (ByteArrayInputStream bais = new ByteArrayInputStream(attributes); - ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(bais)) - { - SessionData.deserializeAttributes(tmp, ois); - } - - //same keys - assertTrue(data.getKeys().equals(tmp.getKeys())); - //same values - for (String name : data.getKeys()) - { - assertTrue(data.getAttribute(name).equals(tmp.getAttribute(name))); - } - } - - return true; - } - - public static void createUnreadableSession(String id, String contextPath, String vhost, - String lastNode, long created, long accessed, - long lastAccessed, long maxIdle, long expiry, - Map attributes) - throws Exception - { - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); - - // Form query for upsert - BasicDBObject key = new BasicDBObject(MongoSessionDataStore.__ID, id); - - // Form updates - BasicDBObject update = new BasicDBObject(); - boolean upsert = false; - BasicDBObject sets = new BasicDBObject(); - - Object version = 1L; - - // New session - - upsert = true; - sets.put(MongoSessionDataStore.__CREATED, created); - sets.put(MongoSessionDataStore.__VALID, true); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__VERSION, version); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__LASTSAVED, System.currentTimeMillis()); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__LASTNODE, lastNode); - - //Leaving out __MAX_IDLE to make it an invalid session object! - - sets.put(MongoSessionDataStore.__EXPIRY, expiry); - sets.put(MongoSessionDataStore.__ACCESSED, accessed); - sets.put(MongoSessionDataStore.__LAST_ACCESSED, lastAccessed); - - if (attributes != null) - { - SessionData tmp = new SessionData(id, contextPath, vhost, created, accessed, lastAccessed, maxIdle, attributes); - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos)) - { - SessionData.serializeAttributes(tmp, oos); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__ATTRIBUTES, baos.toByteArray()); - } - } - - update.put("$set", sets); - collection.update(key, update, upsert, false, WriteConcern.SAFE); - } - - public static void createSession(String id, String contextPath, String vhost, - String lastNode, long created, long accessed, - long lastAccessed, long maxIdle, long expiry, - Map attributes) - throws Exception - { - - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); - - // Form query for upsert - BasicDBObject key = new BasicDBObject(MongoSessionDataStore.__ID, id); - - // Form updates - BasicDBObject update = new BasicDBObject(); - boolean upsert = false; - BasicDBObject sets = new BasicDBObject(); - - Object version = 1L; - - // New session - upsert = true; - sets.put(MongoSessionDataStore.__CREATED, created); - sets.put(MongoSessionDataStore.__VALID, true); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__VERSION, version); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__LASTSAVED, System.currentTimeMillis()); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__LASTNODE, lastNode); - sets.put(MongoSessionDataStore.__MAX_IDLE, maxIdle); - sets.put(MongoSessionDataStore.__EXPIRY, expiry); - sets.put(MongoSessionDataStore.__ACCESSED, accessed); - sets.put(MongoSessionDataStore.__LAST_ACCESSED, lastAccessed); - - if (attributes != null) - { - SessionData tmp = new SessionData(id, contextPath, vhost, created, accessed, lastAccessed, maxIdle, attributes); - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos);) - { - SessionData.serializeAttributes(tmp, oos); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__ATTRIBUTES, baos.toByteArray()); - } - } - - update.put("$set", sets); - collection.update(key, update, upsert, false, WriteConcern.SAFE); - } - - public static void createLegacySession(String id, String contextPath, String vhost, - String lastNode, long created, long accessed, - long lastAccessed, long maxIdle, long expiry, - Map attributes) - throws Exception - { - //make old-style session to test if we can retrieve it - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); - - // Form query for upsert - BasicDBObject key = new BasicDBObject(MongoSessionDataStore.__ID, id); - - // Form updates - BasicDBObject update = new BasicDBObject(); - boolean upsert = false; - BasicDBObject sets = new BasicDBObject(); - - Object version = 1L; - - // New session - upsert = true; - sets.put(MongoSessionDataStore.__CREATED, created); - sets.put(MongoSessionDataStore.__VALID, true); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__VERSION, version); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__LASTSAVED, System.currentTimeMillis()); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__LASTNODE, lastNode); - sets.put(MongoSessionDataStore.__MAX_IDLE, maxIdle); - sets.put(MongoSessionDataStore.__EXPIRY, expiry); - sets.put(MongoSessionDataStore.__ACCESSED, accessed); - sets.put(MongoSessionDataStore.__LAST_ACCESSED, lastAccessed); - - if (attributes != null) - { - for (String name : attributes.keySet()) - { - Object value = attributes.get(name); - sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoUtils.encodeName(name), - MongoUtils.encodeName(value)); - } - } - update.put("$set", sets); - collection.update(key, update, upsert, false, WriteConcern.SAFE); - } -} diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/pom.xml b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/pom.xml index a62ce8ccd9f..2529e0639f2 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/pom.xml +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/pom.xml @@ -63,5 +63,9 @@ awaitility test + + org.eclipse.jetty.tests + jetty-test-session-common + diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredInvalidationSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredInvalidationSessionTest.java index af9320818e4..fd5830c2685 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredInvalidationSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredInvalidationSessionTest.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.junit.jupiter.api.Test; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredOrphanedSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredOrphanedSessionTest.java index a6de364a1db..6f793e66d98 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredOrphanedSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredOrphanedSessionTest.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredSessionScavengingTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredSessionScavengingTest.java index 9935f023610..f37607f938f 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredSessionScavengingTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractClusteredSessionScavengingTest.java @@ -39,6 +39,7 @@ import org.eclipse.jetty.session.ManagedSession; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractSessionTestBase.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractSessionTestBase.java deleted file mode 100644 index 2a01046d475..00000000000 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractSessionTestBase.java +++ /dev/null @@ -1,24 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee9.session; - -import org.eclipse.jetty.session.SessionDataStoreFactory; - -/** - * AbstractTestBase - */ -public abstract class AbstractSessionTestBase -{ - public abstract SessionDataStoreFactory createSessionDataStoreFactory(); -} diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractWebAppObjectInSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractWebAppObjectInSessionTest.java index 511e970bf49..3c714c1c77a 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractWebAppObjectInSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractWebAppObjectInSessionTest.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceFactory; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/Foo.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/Foo.java deleted file mode 100644 index cc2fc0908e1..00000000000 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/Foo.java +++ /dev/null @@ -1,24 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee9.session; - -/** - * Foo - */ -public interface Foo -{ - public int getInt(); - - public void setInt(int i); -} diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/SessionTestSupport.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/SessionTestSupport.java index 95546ceaa58..24f36d74500 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/SessionTestSupport.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/SessionTestSupport.java @@ -42,7 +42,6 @@ public class SessionTestSupport protected final ContextHandlerCollection _contexts; protected SessionIdManager _sessionIdManager; private HouseKeeper _housekeeper; - protected Object _config; protected SessionCacheFactory _cacheFactory; protected SessionDataStoreFactory _storeFactory; @@ -75,7 +74,7 @@ public class SessionTestSupport ((DefaultSessionIdManager)_sessionIdManager).setServer(_server); _housekeeper = new HouseKeeper(); _housekeeper.setIntervalSec(_scavengePeriod); - ((DefaultSessionIdManager)_sessionIdManager).setSessionHouseKeeper(_housekeeper); + _sessionIdManager.setSessionHouseKeeper(_housekeeper); } public SessionIdManager newSessionIdManager() diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/TestSessionDataStore.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/TestSessionDataStore.java deleted file mode 100644 index 21800ff9cce..00000000000 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/TestSessionDataStore.java +++ /dev/null @@ -1,116 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee9.session; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -import org.eclipse.jetty.session.AbstractSessionDataStore; -import org.eclipse.jetty.session.SessionData; - -/** - * TestSessionDataStore - * - * Make a fake session data store (non clustered!) that creates a new SessionData object - * every time load(id) is called. - */ -public class TestSessionDataStore extends AbstractSessionDataStore -{ - public Map _map = new ConcurrentHashMap<>(); - public AtomicInteger _numSaves = new AtomicInteger(0); - - public final boolean _passivating; - - public TestSessionDataStore() - { - _passivating = false; - } - - public TestSessionDataStore(boolean passivating) - { - _passivating = passivating; - } - - @Override - public boolean isPassivating() - { - return _passivating; - } - - @Override - public boolean doExists(String id) throws Exception - { - return _map.containsKey(id); - } - - @Override - public SessionData doLoad(String id) throws Exception - { - SessionData sd = _map.get(id); - if (sd == null) - return null; - SessionData nsd = new SessionData(id, "", "", System.currentTimeMillis(), System.currentTimeMillis(), System.currentTimeMillis(), 0); - nsd.copy(sd); - return nsd; - } - - @Override - public boolean delete(String id) throws Exception - { - return (_map.remove(id) != null); - } - - @Override - public void doStore(String id, SessionData data, long lastSaveTime) throws Exception - { - _map.put(id, data); - _numSaves.addAndGet(1); - } - - @Override - public Set doCheckExpired(Set candidates, long time) - { - HashSet set = new HashSet<>(); - long now = System.currentTimeMillis(); - - for (SessionData d : _map.values()) - { - if (d.getExpiry() > 0 && d.getExpiry() <= now) - set.add(d.getId()); - } - return set; - } - - @Override - public Set doGetExpired(long timeLimit) - { - Set set = new HashSet<>(); - - for (SessionData d:_map.values()) - { - if (d.getExpiry() > 0 && d.getExpiry() <= timeLimit) - set.add(d.getId()); - } - return set; - } - - @Override - public void doCleanOrphans(long timeLimit) - { - //noop - } -} diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/TestSessionDataStoreFactory.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/TestSessionDataStoreFactory.java deleted file mode 100644 index d814d747c85..00000000000 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/TestSessionDataStoreFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee9.session; - -import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; -import org.eclipse.jetty.session.SessionDataStore; -import org.eclipse.jetty.session.SessionManager; - -/** - * TestSessionDataStoreFactory - */ -public class TestSessionDataStoreFactory extends AbstractSessionDataStoreFactory -{ - @Override - public SessionDataStore getSessionDataStore(SessionManager sessionManager) throws Exception - { - TestSessionDataStore store = new TestSessionDataStore(); - store.setSavePeriodSec(getSavePeriodSec()); - return store; - } -} diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/AsyncTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/AsyncTest.java index 6f4ab8a6435..fa45181e32d 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/AsyncTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/AsyncTest.java @@ -32,11 +32,16 @@ import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.Foo; +import org.eclipse.jetty.session.test.FooInvocationHandler; +import org.eclipse.jetty.session.test.TestFoo; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -78,7 +83,7 @@ public class AsyncTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //session should now be evicted from the cache after request exited String id = SessionTestSupport.extractSessionId(sessionCookie); @@ -123,7 +128,7 @@ public class AsyncTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); String id = SessionTestSupport.extractSessionId(sessionCookie); //session should now be evicted from the cache after request exited @@ -173,7 +178,7 @@ public class AsyncTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //session should now be evicted from the cache after request exited String id = SessionTestSupport.extractSessionId(sessionCookie); @@ -219,7 +224,7 @@ public class AsyncTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); String id = SessionTestSupport.extractSessionId(sessionCookie); //session should now be evicted from the cache after request exited diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ConcurrencyTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ConcurrencyTest.java index 1d93fba765f..d5af3522a11 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ConcurrencyTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ConcurrencyTest.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.client.Request; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.eclipse.jetty.util.NanoTime; import org.junit.jupiter.api.Test; @@ -75,7 +76,7 @@ public class ConcurrencyTest ContentResponse response1 = client.GET(url + "?action=init"); assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //simulate 10 clients making 10 requests each for the same session ExecutorService executor = Executors.newCachedThreadPool(); @@ -140,7 +141,7 @@ public class ConcurrencyTest this.requestsCount = requestsCount; this.sessionCookie = sessionCookie; this.url = url; - this.name = "" + (COUNT++); + this.name = Integer.toString(COUNT++); } @Override diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/CreationTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/CreationTest.java index 6ccbda1240c..8d7c552862e 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/CreationTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/CreationTest.java @@ -37,6 +37,7 @@ import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.eclipse.jetty.util.StringUtil; import org.hamcrest.Matchers; import org.junit.jupiter.api.Disabled; @@ -94,7 +95,7 @@ public class CreationTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); } finally { @@ -139,7 +140,7 @@ public class CreationTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //session should now be evicted from the cache String id = SessionTestSupport.extractSessionId(sessionCookie); @@ -444,7 +445,7 @@ public class CreationTest } return; } - else if (action != null && "test".equals(action)) + else if ("test".equals(action)) { HttpSession session = request.getSession(false); assertNotNull(session); @@ -503,12 +504,11 @@ public class CreationTest { HttpSession session = request.getSession(false); assertNull(session); - if (session == null) - session = request.getSession(true); + session = request.getSession(true); // Be sure nothing from contextA is present Object objectA = session.getAttribute("value"); - assertTrue(objectA == null); + assertNull(objectA); // Add something, so in contextA we can check if it is visible (it must not). session.setAttribute("B", "B"); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/DuplicateCookieTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/DuplicateCookieTest.java index 575f87387e3..85b6cbc76ce 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/DuplicateCookieTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/DuplicateCookieTest.java @@ -36,6 +36,7 @@ import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.component.LifeCycle; import org.hamcrest.Matchers; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/IdleSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/IdleSessionTest.java index 28083db3e5d..208abbd8283 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/IdleSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/IdleSessionTest.java @@ -31,6 +31,8 @@ import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.ManagedSession; import org.eclipse.jetty.session.NullSessionCacheFactory; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStore; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.eclipse.jetty.util.thread.AutoLock; import org.junit.jupiter.api.Test; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ModifyMaxInactiveIntervalTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ModifyMaxInactiveIntervalTest.java index 39d84944670..6f64add76f8 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ModifyMaxInactiveIntervalTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ModifyMaxInactiveIntervalTest.java @@ -30,11 +30,12 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * ModifyMaxInactiveIntervalTest @@ -73,7 +74,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); String id = SessionTestSupport.extractSessionId(sessionCookie); //check that the maxInactive is -1 @@ -120,7 +121,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to reduce the maxinactive interval Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive); @@ -175,7 +176,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to increase the maxinactive interval Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive); @@ -207,7 +208,6 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase int oldMaxInactive = -1; int newMaxInactive = 120; //2min int evict = 2; - int sleep = evict; int scavenge = __scavenge; DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); @@ -232,10 +232,10 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to reduce the maxinactive interval - Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive + "&wait=" + sleep); + Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive + "&wait=" + evict); response = request.send(); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); @@ -261,7 +261,6 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase int oldMaxInactive = 10; int newMaxInactive = 2; int evict = 4; - int sleep = evict; int scavenge = __scavenge; DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); @@ -286,10 +285,10 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to reduce the maxinactive interval - Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive + "&wait=" + sleep); + Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive + "&wait=" + evict); response = request.send(); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); @@ -338,7 +337,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to change the maxinactive interval Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive + "&wait=" + 2); @@ -390,7 +389,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request that will sleep long enough for the session expiry time to have passed //before trying to access the session and ensure it is still there @@ -439,7 +438,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //do another request to change the maxinactive interval Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val=" + newMaxInactive); @@ -492,7 +491,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //Test that the maxInactiveInterval matches the expected value Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=test&val=" + maxInactive); @@ -528,8 +527,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase { //change the expiry time for the session, maybe sleeping before the change String tmp = request.getParameter("val"); - int interval = -1; - interval = (tmp == null ? -1 : Integer.parseInt(tmp)); + int interval = (tmp == null ? -1 : Integer.parseInt(tmp)); tmp = request.getParameter("wait"); int wait = (tmp == null ? 0 : Integer.parseInt(tmp)); @@ -566,8 +564,7 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase throw new ServletException("Session is null for action=sleep"); String tmp = request.getParameter("val"); - int interval = 0; - interval = (tmp == null ? 0 : Integer.parseInt(tmp)); + int interval = (tmp == null ? 0 : Integer.parseInt(tmp)); if (interval > 0) { @@ -597,11 +594,9 @@ public class ModifyMaxInactiveIntervalTest extends AbstractSessionTestBase return; } String tmp = request.getParameter("val"); - int interval = 0; - interval = (tmp == null ? 0 : Integer.parseInt(tmp)); + int interval = (tmp == null ? 0 : Integer.parseInt(tmp)); assertEquals(interval, session.getMaxInactiveInterval()); - return; } } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/NonClusteredSessionScavengingTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/NonClusteredSessionScavengingTest.java index 592bdc5a240..99c274dc3b4 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/NonClusteredSessionScavengingTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/NonClusteredSessionScavengingTest.java @@ -31,6 +31,8 @@ import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; @@ -92,7 +94,7 @@ public class NonClusteredSessionScavengingTest extends AbstractSessionTestBase ContentResponse response1 = client.GET(url + "?action=create"); assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //test session was created SessionManager m1 = context1.getSessionHandler().getSessionManager(); @@ -148,7 +150,7 @@ public class NonClusteredSessionScavengingTest extends AbstractSessionTestBase ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping.substring(1) + "?action=create"); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); // Let's wait for the scavenger to run pause(maxInactivePeriod + scavengePeriod); @@ -205,7 +207,7 @@ public class NonClusteredSessionScavengingTest extends AbstractSessionTestBase ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping.substring(1) + "?action=create"); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); // Let's wait for the scavenger to run pause(2 * scavengePeriod); @@ -248,13 +250,13 @@ public class NonClusteredSessionScavengingTest extends AbstractSessionTestBase assertNull(s); s = request.getSession(true); assertNotNull(s); - assertFalse(s.getId().equals(id)); + assertNotEquals(s.getId(), id); } else if ("old-test".equals(action)) { HttpSession s = request.getSession(false); assertNotNull(s); - assertTrue(s.getId().equals(id)); + assertEquals(s.getId(), id); } else { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/RedirectSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/RedirectSessionTest.java index bc50ee251b3..e9b09e3756d 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/RedirectSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/RedirectSessionTest.java @@ -26,6 +26,7 @@ import org.eclipse.jetty.ee9.servlet.ServletContextHandler; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ReentrantRequestSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ReentrantRequestSessionTest.java index c5a5d84f88b..3b9e2ee8bba 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ReentrantRequestSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/ReentrantRequestSessionTest.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -70,7 +71,7 @@ public class ReentrantRequestSessionTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //make a request that will make a simultaneous request for the same session Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=reenter&port=" + port + "&path=" + contextPath + servletMapping); @@ -141,7 +142,7 @@ public class ReentrantRequestSessionTest } else { - assertTrue(session != null); + assertNotNull(session); session.setAttribute("reentrant", "true"); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/RemoveSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/RemoveSessionTest.java index 21c7e48fa9c..17056787370 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/RemoveSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/RemoveSessionTest.java @@ -27,11 +27,11 @@ import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.Request; import org.eclipse.jetty.ee9.nested.SessionHandler; import org.eclipse.jetty.ee9.servlet.ServletContextHandler; -import org.eclipse.jetty.session.AbstractSessionCache; import org.eclipse.jetty.session.DefaultSessionCache; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -78,7 +78,7 @@ public class RemoveSessionTest ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create"); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //ensure sessionCreated bindingListener is called assertTrue(testListener.isCreated()); @@ -97,7 +97,7 @@ public class RemoveSessionTest assertEquals(1, ((DefaultSessionCache)m.getSessionManager().getSessionCache()).getSessionsTotal()); //check the session is no longer in the cache - assertFalse(((AbstractSessionCache)m.getSessionManager().getSessionCache()).contains(SessionTestSupport.extractSessionId(sessionCookie))); + assertFalse(m.getSessionManager().getSessionCache().contains(SessionTestSupport.extractSessionId(sessionCookie))); //check the session is not persisted any more assertFalse(m.getSessionManager().getSessionCache().getSessionDataStore().exists(SessionTestSupport.extractSessionId(sessionCookie))); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SameContextForwardedSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SameContextForwardedSessionTest.java index faa14d1dc21..09fc600b539 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SameContextForwardedSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SameContextForwardedSessionTest.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.ee9.servlet.ServletHolder; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -72,7 +73,7 @@ public class SameContextForwardedSessionTest ContentResponse response = client.GET("http://localhost:" + serverPort + "/context/one"); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); //test that the session was created, and that it contains the attributes from servlet3 and servlet1 testServletContextHandler.getSessionHandler().getSessionManager().getSessionCache().contains(SessionTestSupport.extractSessionId(sessionCookie)); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionInvalidateCreateScavengeTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionInvalidateCreateScavengeTest.java index b116cbc6412..a9cb495dc10 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionInvalidateCreateScavengeTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionInvalidateCreateScavengeTest.java @@ -37,6 +37,8 @@ import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionInvalidationTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionInvalidationTest.java index 7a02c33b42e..cf4a0967037 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionInvalidationTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionInvalidationTest.java @@ -30,6 +30,7 @@ import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.NullSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -80,7 +81,7 @@ public class SessionInvalidationTest ContentResponse response1 = client.GET(url + "?action=init"); assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); // Make a request which will invalidate the existing session Request request2 = client.newRequest(url + "?action=test"); @@ -130,7 +131,7 @@ public class SessionInvalidationTest ContentResponse response1 = client.GET(url + "?action=init"); assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); // Make a request which will invalidate the existing session Request request2 = client.newRequest(url + "?action=test"); @@ -177,18 +178,18 @@ public class SessionInvalidationTest //invalidate existing session session.invalidate(); - assertThrows(IllegalStateException.class, () -> session.invalidate()); - assertThrows(IllegalStateException.class, () -> session.getLastAccessedTime()); - assertThrows(IllegalStateException.class, () -> session.getCreationTime()); + assertThrows(IllegalStateException.class, session::invalidate); + assertThrows(IllegalStateException.class, session::getLastAccessedTime); + assertThrows(IllegalStateException.class, session::getCreationTime); assertThrows(IllegalStateException.class, () -> session.getAttribute("foo")); - assertThrows(IllegalStateException.class, () -> session.getAttributeNames()); + assertThrows(IllegalStateException.class, session::getAttributeNames); assertThrows(IllegalStateException.class, () -> session.getValue("foo")); - assertThrows(IllegalStateException.class, () -> session.getValueNames()); + assertThrows(IllegalStateException.class, session::getValueNames); assertThrows(IllegalStateException.class, () -> session.putValue("a", "b")); assertThrows(IllegalStateException.class, () -> session.removeAttribute("foo")); assertThrows(IllegalStateException.class, () -> session.removeValue("foo")); assertThrows(IllegalStateException.class, () -> session.setAttribute("a", "b")); - assertDoesNotThrow(() -> session.getId()); + assertDoesNotThrow(session::getId); } else if ("get".equals(action)) { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionRenewTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionRenewTest.java index 9e05c91181d..ff04f9bca43 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionRenewTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionRenewTest.java @@ -39,12 +39,16 @@ import org.eclipse.jetty.session.SessionCacheFactory; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; +import org.eclipse.jetty.session.test.TestSessionDataStore; +import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -176,7 +180,7 @@ public class SessionRenewTest ContentResponse renewResponse = request.send(); assertEquals(HttpServletResponse.SC_OK, renewResponse.getStatus()); String newSessionCookie = renewResponse.getHeaders().get("Set-Cookie"); - assertTrue(newSessionCookie != null); + assertNotNull(newSessionCookie); String updatedId = SessionTestSupport.extractSessionId(newSessionCookie); //session ids should be updated on all contexts @@ -227,7 +231,7 @@ public class SessionRenewTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); assertFalse(testListener.isCalled()); //make a request to change the sessionid @@ -308,7 +312,7 @@ public class SessionRenewTest else if ("renew".equals(action)) { HttpSession beforeSession = request.getSession(false); - assertTrue(beforeSession != null); + assertNotNull(beforeSession); String beforeSessionId = beforeSession.getId(); //((Session)beforeSession).renewId(request); @@ -316,11 +320,11 @@ public class SessionRenewTest HttpSession afterSession = request.getSession(false); - assertTrue(afterSession != null); + assertNotNull(afterSession); String afterSessionId = afterSession.getId(); - assertTrue(beforeSession == afterSession); //same object - assertFalse(beforeSessionId.equals(afterSessionId)); //different id + assertSame(beforeSession, afterSession); //same object + assertNotEquals(beforeSessionId, afterSessionId); //different id ManagedSession coreAfterSession = ((ServletSessionApi)afterSession).getSession(); SessionManager sessionManager = coreAfterSession.getSessionManager(); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/pom.xml b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/pom.xml index 2d9ac31315e..20a35d74ed2 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/pom.xml +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/pom.xml @@ -68,5 +68,10 @@ slf4j-simple test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/ClusteredOrphanedSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/ClusteredOrphanedSessionTest.java index b62b6c85afb..ad9598a8fc1 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/ClusteredOrphanedSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/ClusteredOrphanedSessionTest.java @@ -15,8 +15,7 @@ package org.eclipse.jetty.ee9.session.gcloud; import org.eclipse.jetty.ee9.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.GCloudSessionTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -26,25 +25,11 @@ import org.testcontainers.junit.jupiter.Testcontainers; public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest { - public static GCloudSessionTestSupport __testSupport; - - @BeforeAll - public static void setUp() throws Exception - { - __testSupport = new GCloudSessionTestSupport(); - __testSupport.setUp(); - } - - @AfterAll - public static void tearDown() throws Exception - { - __testSupport.deleteSessions(); - __testSupport.tearDown(); - } + public GCloudSessionTestSupport testSupport = new GCloudSessionTestSupport(getClass().getSimpleName()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore()); + return testSupport.newSessionDataStoreFactory(); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/ClusteredSessionScavengingTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/ClusteredSessionScavengingTest.java index b00ad3e79fa..efa7cb69a9d 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/ClusteredSessionScavengingTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/ClusteredSessionScavengingTest.java @@ -15,8 +15,7 @@ package org.eclipse.jetty.ee9.session.gcloud; import org.eclipse.jetty.ee9.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.GCloudSessionTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -26,25 +25,11 @@ import org.testcontainers.junit.jupiter.Testcontainers; public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest { - public static GCloudSessionTestSupport __testSupport; - - @BeforeAll - public static void setUp() throws Exception - { - __testSupport = new GCloudSessionTestSupport(); - __testSupport.setUp(); - } - - @AfterAll - public static void tearDown() throws Exception - { - __testSupport.deleteSessions(); - __testSupport.tearDown(); - } + public GCloudSessionTestSupport testSupport = new GCloudSessionTestSupport(getClass().getSimpleName()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore()); + return testSupport.newSessionDataStoreFactory(); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/GCloudSessionDataStoreTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/GCloudSessionDataStoreTest.java index 78633ae30ff..f0d6aa173a6 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/GCloudSessionDataStoreTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/GCloudSessionDataStoreTest.java @@ -16,9 +16,8 @@ package org.eclipse.jetty.ee9.session.gcloud; import org.eclipse.jetty.session.AbstractSessionDataStoreTest; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; +import org.eclipse.jetty.session.test.tools.GCloudSessionTestSupport; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -33,37 +32,24 @@ public class GCloudSessionDataStoreTest extends AbstractSessionDataStoreTest super(); } - public static GCloudSessionTestSupport __testSupport; - - @BeforeAll - public static void configure() throws Exception - { - __testSupport = new GCloudSessionTestSupport(); - __testSupport.setUp(); - } - - @AfterAll - public static void tearDown() throws Exception - { - __testSupport.tearDown(); - } + public GCloudSessionTestSupport testSupport = new GCloudSessionTestSupport(getClass().getSimpleName()); @AfterEach public void teardown() throws Exception { - __testSupport.deleteSessions(); + testSupport.deleteSessions(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore()); + return testSupport.newSessionDataStoreFactory(); } @Override public void persistSession(SessionData data) throws Exception { - __testSupport.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), + testSupport.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), data.getCookieSet(), data.getLastSaved(), data.getAllAttributes()); } @@ -72,7 +58,7 @@ public class GCloudSessionDataStoreTest extends AbstractSessionDataStoreTest public void persistUnreadableSession(SessionData data) throws Exception { - __testSupport.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), + testSupport.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), data.getCookieSet(), data.getLastSaved(), null); } @@ -80,7 +66,7 @@ public class GCloudSessionDataStoreTest extends AbstractSessionDataStoreTest @Override public boolean checkSessionExists(SessionData data) throws Exception { - return __testSupport.checkSessionExists(data.getId()); + return testSupport.checkSessionExists(data.getId()); } @Override @@ -90,7 +76,7 @@ public class GCloudSessionDataStoreTest extends AbstractSessionDataStoreTest Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return __testSupport.checkSessionPersisted(data); + return testSupport.checkSessionPersisted(data); } finally { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/GCloudSessionTestSupport.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/GCloudSessionTestSupport.java deleted file mode 100644 index b00996a849d..00000000000 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/GCloudSessionTestSupport.java +++ /dev/null @@ -1,325 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee9.session.gcloud; - -import java.io.ByteArrayOutputStream; -import java.io.ObjectOutputStream; -import java.net.InetAddress; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.google.cloud.NoCredentials; -import com.google.cloud.ServiceOptions; -import com.google.cloud.datastore.Batch; -import com.google.cloud.datastore.Blob; -import com.google.cloud.datastore.BlobValue; -import com.google.cloud.datastore.Datastore; -import com.google.cloud.datastore.DatastoreOptions; -import com.google.cloud.datastore.Entity; -import com.google.cloud.datastore.GqlQuery; -import com.google.cloud.datastore.Key; -import com.google.cloud.datastore.KeyFactory; -import com.google.cloud.datastore.Query; -import com.google.cloud.datastore.Query.ResultType; -import com.google.cloud.datastore.QueryResults; -import com.google.cloud.datastore.StructuredQuery.PropertyFilter; -import org.eclipse.jetty.gcloud.session.GCloudSessionDataStore; -import org.eclipse.jetty.gcloud.session.GCloudSessionDataStore.EntityDataModel; -import org.eclipse.jetty.gcloud.session.GCloudSessionDataStoreFactory; -import org.eclipse.jetty.session.SessionData; -import org.eclipse.jetty.session.SessionDataStore; -import org.eclipse.jetty.session.SessionManager; -import org.eclipse.jetty.util.ClassLoadingObjectInputStream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.DatastoreEmulatorContainer; -import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.utility.DockerImageName; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * GCloudSessionTestSupport - */ -public class GCloudSessionTestSupport -{ - Datastore _ds; - KeyFactory _keyFactory; - - private static final Logger LOGGER = LoggerFactory.getLogger(GCloudSessionTestSupport.class); - private static final Logger GCLOUD_LOG = LoggerFactory.getLogger("org.eclipse.jetty.gcloud.session.gcloudLogs"); - - public DatastoreEmulatorContainer emulator = new DatastoreEmulatorContainer( - DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:316.0.0-emulators") - ).withLogConsumer(new Slf4jLogConsumer(GCLOUD_LOG)) - .withFlags("--consistency=1.0"); - - public static class TestGCloudSessionDataStoreFactory extends GCloudSessionDataStoreFactory - { - Datastore _d; - - public TestGCloudSessionDataStoreFactory(Datastore d) - { - _d = d; - } - - @Override - public SessionDataStore getSessionDataStore(SessionManager manager) throws Exception - { - GCloudSessionDataStore ds = (GCloudSessionDataStore)super.getSessionDataStore(manager); - ds.setMaxRetries(GCloudSessionDataStore.DEFAULT_MAX_RETRIES); - ds.setDatastore(_d); - return ds; - } - } - - public static GCloudSessionDataStoreFactory newSessionDataStoreFactory(Datastore d) - { - return new TestGCloudSessionDataStoreFactory(d); - } - - public GCloudSessionTestSupport() - { - // no op - } - - public void setUp() - throws Exception - { - emulator.start(); - String host; - //work out if we're running locally or not: if not local, then the host passed to - //DatastoreOptions must be prefixed with a scheme - String endPoint = emulator.getEmulatorEndpoint(); - InetAddress hostAddr = InetAddress.getByName(new URL("http://" + endPoint).getHost()); - LOGGER.info("endPoint: {} ,hostAddr.isAnyLocalAddress(): {},hostAddr.isLoopbackAddress(): {}", - endPoint, - hostAddr.isAnyLocalAddress(), - hostAddr.isLoopbackAddress()); - if (hostAddr.isAnyLocalAddress() || hostAddr.isLoopbackAddress()) - host = endPoint; - else - host = "http://" + endPoint; - - DatastoreOptions options = DatastoreOptions.newBuilder() - .setHost(host) - .setCredentials(NoCredentials.getInstance()) - .setRetrySettings(ServiceOptions.getNoRetrySettings()) - .setProjectId("test-project") - .build(); - _ds = options.getService(); - _keyFactory = _ds.newKeyFactory().setKind(EntityDataModel.KIND); - } - - public Datastore getDatastore() - { - return _ds; - } - - public void tearDown() - throws Exception - { - emulator.stop(); - } - - public void reset() throws Exception - { - emulator.stop(); - this.setUp(); - } - - public void createSession(String id, String contextPath, String vhost, - String lastNode, long created, long accessed, - long lastAccessed, long maxIdle, long expiry, - long cookieset, long lastSaved, - Map attributes) - throws Exception - { - //serialize the attribute map - try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) - { - if (attributes != null) - { - SessionData tmp = new SessionData(id, contextPath, vhost, created, accessed, lastAccessed, maxIdle); - ObjectOutputStream oos = new ObjectOutputStream(baos); - SessionData.serializeAttributes(tmp, oos); - } - - //turn a session into an entity - Entity.Builder builder = Entity.newBuilder(_keyFactory.newKey(contextPath + "_" + vhost + "_" + id)) - .set(EntityDataModel.ID, id) - .set(EntityDataModel.CONTEXTPATH, contextPath) - .set(EntityDataModel.VHOST, vhost) - .set(EntityDataModel.ACCESSED, accessed) - .set(EntityDataModel.LASTACCESSED, lastAccessed) - .set(EntityDataModel.CREATETIME, created) - .set(EntityDataModel.COOKIESETTIME, cookieset) - .set(EntityDataModel.LASTNODE, lastNode) - .set(EntityDataModel.EXPIRY, expiry) - .set(EntityDataModel.MAXINACTIVE, maxIdle) - .set(EntityDataModel.LASTSAVED, lastSaved); - if (attributes != null) - builder.set(EntityDataModel.ATTRIBUTES, BlobValue.newBuilder(Blob.copyFrom(baos.toByteArray())).setExcludeFromIndexes(true).build()); - Entity entity = builder.build(); - - _ds.put(entity); - } - } - - public boolean checkSessionPersisted(SessionData data) - throws Exception - { - Entity entity = _ds.get(_keyFactory.newKey(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId())); - if (entity == null) - return false; - - //turn an Entity into a Session - assertEquals(data.getId(), entity.getString(EntityDataModel.ID)); - assertEquals(data.getContextPath(), entity.getString(EntityDataModel.CONTEXTPATH)); - assertEquals(data.getVhost(), entity.getString(EntityDataModel.VHOST)); - assertEquals(data.getAccessed(), entity.getLong(EntityDataModel.ACCESSED)); - assertEquals(data.getLastAccessed(), entity.getLong(EntityDataModel.LASTACCESSED)); - assertEquals(data.getCreated(), entity.getLong(EntityDataModel.CREATETIME)); - assertEquals(data.getCookieSet(), entity.getLong(EntityDataModel.COOKIESETTIME)); - assertEquals(data.getLastNode(), entity.getString(EntityDataModel.LASTNODE)); - assertEquals(data.getLastSaved(), entity.getLong(EntityDataModel.LASTSAVED)); - assertEquals(data.getExpiry(), entity.getLong(EntityDataModel.EXPIRY)); - assertEquals(data.getMaxInactiveMs(), entity.getLong(EntityDataModel.MAXINACTIVE)); - Blob blob = (Blob)entity.getBlob(EntityDataModel.ATTRIBUTES); - - SessionData tmp = new SessionData(data.getId(), entity.getString(EntityDataModel.CONTEXTPATH), - entity.getString(EntityDataModel.VHOST), - entity.getLong(EntityDataModel.CREATETIME), - entity.getLong(EntityDataModel.ACCESSED), - entity.getLong(EntityDataModel.LASTACCESSED), - entity.getLong(EntityDataModel.MAXINACTIVE)); - - try (ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(blob.asInputStream())) - { - SessionData.deserializeAttributes(tmp, ois); - } - - //same number of attributes - assertEquals(data.getAllAttributes().size(), tmp.getAllAttributes().size()); - //same keys - assertTrue(data.getKeys().equals(tmp.getAllAttributes().keySet())); - //same values - for (String name : data.getKeys()) - { - assertTrue(data.getAttribute(name).equals(tmp.getAttribute(name))); - } - - return true; - } - - public boolean checkSessionExists(String id) - throws Exception - { - Query query = Query.newEntityQueryBuilder() - .setKind(EntityDataModel.KIND) - .setFilter(PropertyFilter.eq(EntityDataModel.ID, id)) - .build(); - - QueryResults results = _ds.run(query); - - if (results.hasNext()) - { - return true; - } - - return false; - } - - public Set getSessionIds() throws Exception - { - HashSet ids = new HashSet(); - GqlQuery.Builder builder = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + GCloudSessionDataStore.EntityDataModel.KIND); - - Query query = builder.build(); - - QueryResults results = _ds.run(query); - assertNotNull(results); - while (results.hasNext()) - { - Entity e = results.next(); - ids.add(e.getString("id")); - } - - return ids; - } - - public void listSessions() throws Exception - { - - GqlQuery.Builder builder = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + GCloudSessionDataStore.EntityDataModel.KIND); - - Query query = builder.build(); - - QueryResults results = _ds.run(query); - assertNotNull(results); - System.err.println("SESSIONS::::::::"); - while (results.hasNext()) - { - - Entity e = results.next(); - System.err.println(e.getString("clusterId") + " expires at " + e.getLong("expiry")); - } - System.err.println("END OF SESSIONS::::::::"); - } - - public void assertSessions(int count) throws Exception - { - Query query = Query.newKeyQueryBuilder().setKind(GCloudSessionDataStore.EntityDataModel.KIND).build(); - QueryResults results = _ds.run(query); - assertNotNull(results); - int actual = 0; - List keys = new ArrayList<>(); - while (results.hasNext()) - { - Key key = results.next(); - keys.add(key); - ++actual; - } - assertEquals(count, actual, "keys found: " + keys); - } - - public void deleteSessions() throws Exception - { - Query query = Query.newKeyQueryBuilder().setKind(GCloudSessionDataStore.EntityDataModel.KIND).build(); - QueryResults results = _ds.run(query); - - Batch batch = _ds.newBatch(); - - if (results != null) - { - List keys = new ArrayList<>(); - - while (results.hasNext()) - { - keys.add(results.next()); - } - - batch.delete(keys.toArray(new Key[keys.size()])); - } - - batch.submit(); - assertSessions(0); - } -} diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/InvalidationSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/InvalidationSessionTest.java index 8b720eb9182..21c43aa2cae 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/InvalidationSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee9/session/gcloud/InvalidationSessionTest.java @@ -15,8 +15,7 @@ package org.eclipse.jetty.ee9.session.gcloud; import org.eclipse.jetty.ee9.session.AbstractClusteredInvalidationSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.GCloudSessionTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -25,25 +24,11 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class InvalidationSessionTest extends AbstractClusteredInvalidationSessionTest { - public static GCloudSessionTestSupport __testSupport; - - @BeforeAll - public static void setUp() throws Exception - { - __testSupport = new GCloudSessionTestSupport(); - __testSupport.setUp(); - } - - @AfterAll - public static void tearDown() throws Exception - { - __testSupport.deleteSessions(); - __testSupport.tearDown(); - } + public GCloudSessionTestSupport testSupport = new GCloudSessionTestSupport(getClass().getSimpleName()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore()); + return testSupport.newSessionDataStoreFactory(); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/pom.xml b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/pom.xml index 9b6fca5a3f4..df15a929222 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/pom.xml +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/pom.xml @@ -9,37 +9,10 @@ jetty-ee9-test-sessions-hazelcast EE9 :: Tests :: Sessions :: Hazelcast - false ${project.groupId}.sessions.hazelcast - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-test-resources - - unpack - - - - - org.eclipse.jetty.toolchain - jetty-test-policy - ${jetty-test-policy.version} - jar - true - **/*.keystore,**/*.pem - ${jetty.test.policy.loc} - - - - - - org.apache.maven.plugins maven-surefire-plugin @@ -121,6 +94,11 @@ jetty-slf4j-impl test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/ClusteredOrphanedSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/ClusteredOrphanedSessionTest.java index 1a4212dc3c4..aaf75af4b9d 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/ClusteredOrphanedSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/ClusteredOrphanedSessionTest.java @@ -16,8 +16,8 @@ package org.eclipse.jetty.ee9.session.hazelcast; import org.eclipse.jetty.ee9.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; /** * ClusteredOrphanedSessionTest @@ -27,13 +27,7 @@ public class ClusteredOrphanedSessionTest { HazelcastSessionDataStoreFactory factory; - HazelcastTestHelper _testHelper; - - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @AfterEach public void shutdown() diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/ClusteredSessionScavengingTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/ClusteredSessionScavengingTest.java index f5f0a46ee3b..27caefd7315 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/ClusteredSessionScavengingTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/ClusteredSessionScavengingTest.java @@ -16,8 +16,8 @@ package org.eclipse.jetty.ee9.session.hazelcast; import org.eclipse.jetty.ee9.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; /** * ClusteredSessionScavengingTest @@ -27,13 +27,7 @@ public class ClusteredSessionScavengingTest { HazelcastSessionDataStoreFactory factory; - HazelcastTestHelper _testHelper; - - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @AfterEach public void shutdown() diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastClusteredInvalidationSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastClusteredInvalidationSessionTest.java index e8b81e77f87..c76c6bd912d 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastClusteredInvalidationSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastClusteredInvalidationSessionTest.java @@ -16,21 +16,15 @@ package org.eclipse.jetty.ee9.session.hazelcast; import org.eclipse.jetty.ee9.session.AbstractClusteredInvalidationSessionTest; import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; public class HazelcastClusteredInvalidationSessionTest extends AbstractClusteredInvalidationSessionTest { HazelcastSessionDataStoreFactory factory; - HazelcastTestHelper _testHelper; - - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @AfterEach public void shutdown() diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastSessionDataStoreTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastSessionDataStoreTest.java index 431a4b2e6c3..f08199d6868 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastSessionDataStoreTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastSessionDataStoreTest.java @@ -24,8 +24,8 @@ import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.UnreadableSessionDataException; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.fail; @@ -40,7 +40,7 @@ public class HazelcastSessionDataStoreTest extends AbstractSessionDataStoreTest super(); } - HazelcastTestHelper _testHelper; + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() @@ -48,12 +48,6 @@ public class HazelcastSessionDataStoreTest extends AbstractSessionDataStoreTest return _testHelper.createSessionDataStoreFactory(false); } - @BeforeEach - public void configure() - { - _testHelper = new HazelcastTestHelper(); - } - @AfterEach public void shutdown() { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastTestHelper.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastTestHelper.java deleted file mode 100644 index 307af50af72..00000000000 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/HazelcastTestHelper.java +++ /dev/null @@ -1,139 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee9.session.hazelcast; - -import java.util.Collections; - -import com.hazelcast.client.HazelcastClient; -import com.hazelcast.client.config.ClientConfig; -import com.hazelcast.client.config.ClientNetworkConfig; -import com.hazelcast.config.Config; -import com.hazelcast.config.MapConfig; -import com.hazelcast.config.SerializerConfig; -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; -import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; -import org.eclipse.jetty.hazelcast.session.SessionDataSerializer; -import org.eclipse.jetty.session.SessionData; -import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.eclipse.jetty.util.NanoTime; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class HazelcastTestHelper -{ - static final String _name = Long.toString(NanoTime.now()); - - static final String _hazelcastInstanceName = "SESSION_TEST_" + _name; - - static SerializerConfig _serializerConfig; - - static HazelcastInstance _instance; - - static - { - // Wire up java.util.logging (used by hazelcast libs) to slf4j. - if (!org.slf4j.bridge.SLF4JBridgeHandler.isInstalled()) - { - org.slf4j.bridge.SLF4JBridgeHandler.install(); - } - - _serializerConfig = new SerializerConfig().setImplementation(new SessionDataSerializer()).setTypeClass(SessionData.class); - Config config = new Config(); - config.setInstanceName(_hazelcastInstanceName); - config.getNetworkConfig().getJoin().getAutoDetectionConfig().setEnabled(false); - config.addMapConfig(new MapConfig().setName(_name)).setClassLoader(null); - config.getSerializationConfig().addSerializerConfig(_serializerConfig); - _instance = Hazelcast.getOrCreateHazelcastInstance(config); - } - - public HazelcastTestHelper() - { - // noop - } - - public SessionDataStoreFactory createSessionDataStoreFactory(boolean onlyClient) - { - HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory(); - factory.setOnlyClient(onlyClient); - factory.setMapName(_name); - factory.setUseQueries(true); - if (onlyClient) - { - ClientNetworkConfig clientNetworkConfig = new ClientNetworkConfig() - .setAddresses(Collections.singletonList("localhost:" + _instance.getConfig().getNetworkConfig().getPort())); - ClientConfig clientConfig = new ClientConfig() - .setNetworkConfig(clientNetworkConfig); - - SerializerConfig sc = new SerializerConfig() - .setImplementation(new SessionDataSerializer()) - .setTypeClass(SessionData.class); - clientConfig.getSerializationConfig().addSerializerConfig(sc); - - factory.setHazelcastInstance(HazelcastClient.newHazelcastClient(clientConfig)); - } - else - { - factory.setHazelcastInstance(_instance); - } - return factory; - } - - public void tearDown() - { - _instance.getMap(_name).clear(); - } - - public void createSession(SessionData data) - { - Object o = _instance.getMap(_name).put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data); - } - - public boolean checkSessionExists(SessionData data) - { - return (_instance.getMap(_name).get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()) != null); - } - - public boolean checkSessionPersisted(SessionData data) - { - Object obj = _instance.getMap(_name).get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); - if (obj == null) - return false; - - SessionData saved = (SessionData)obj; - - assertEquals(data.getId(), saved.getId()); - assertEquals(data.getContextPath(), saved.getContextPath()); - assertEquals(data.getVhost(), saved.getVhost()); - assertEquals(data.getLastNode(), saved.getLastNode()); - assertEquals(data.getCreated(), saved.getCreated()); - assertEquals(data.getAccessed(), saved.getAccessed()); - assertEquals(data.getLastAccessed(), saved.getLastAccessed()); - assertEquals(data.getCookieSet(), saved.getCookieSet()); - assertEquals(data.getExpiry(), saved.getExpiry()); - assertEquals(data.getMaxInactiveMs(), saved.getMaxInactiveMs()); - - //same number of attributes - assertEquals(data.getAllAttributes().size(), saved.getAllAttributes().size()); - //same keys - assertTrue(data.getKeys().equals(saved.getKeys())); - //same values - for (String name : data.getKeys()) - { - assertTrue(data.getAttribute(name).equals(saved.getAttribute(name))); - } - return true; - } -} diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/ClientOrphanedSessionClientTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/ClientOrphanedSessionClientTest.java index 80fbac4853e..741b4d74db8 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/ClientOrphanedSessionClientTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/ClientOrphanedSessionClientTest.java @@ -14,15 +14,14 @@ package org.eclipse.jetty.ee9.session.hazelcast.client; import org.eclipse.jetty.ee9.session.AbstractClusteredOrphanedSessionTest; -import org.eclipse.jetty.ee9.session.hazelcast.HazelcastTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; public class ClientOrphanedSessionClientTest extends AbstractClusteredOrphanedSessionTest { - HazelcastTestHelper _testHelper; + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() @@ -30,12 +29,6 @@ public class ClientOrphanedSessionClientTest return _testHelper.createSessionDataStoreFactory(true); } - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } - @AfterEach public void shutdown() { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/ClientSessionScavengingClientTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/ClientSessionScavengingClientTest.java index 9097d53198e..95976a1dc91 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/ClientSessionScavengingClientTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/ClientSessionScavengingClientTest.java @@ -14,15 +14,14 @@ package org.eclipse.jetty.ee9.session.hazelcast.client; import org.eclipse.jetty.ee9.session.AbstractClusteredSessionScavengingTest; -import org.eclipse.jetty.ee9.session.hazelcast.HazelcastTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; public class ClientSessionScavengingClientTest extends AbstractClusteredSessionScavengingTest { - HazelcastTestHelper _testHelper; + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() @@ -30,12 +29,6 @@ public class ClientSessionScavengingClientTest return _testHelper.createSessionDataStoreFactory(true); } - @BeforeEach - public void setUp() - { - _testHelper = new HazelcastTestHelper(); - } - @AfterEach public void shutdown() { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/HazelcastSessionDataStoreClientTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/HazelcastSessionDataStoreClientTest.java index 7be7ff56e5c..6f732890589 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/HazelcastSessionDataStoreClientTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee9/session/hazelcast/client/HazelcastSessionDataStoreClientTest.java @@ -14,7 +14,6 @@ package org.eclipse.jetty.ee9.session.hazelcast.client; import org.eclipse.jetty.ee9.servlet.ServletContextHandler; -import org.eclipse.jetty.ee9.session.hazelcast.HazelcastTestHelper; import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStore; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; @@ -25,8 +24,8 @@ import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.UnreadableSessionDataException; +import org.eclipse.jetty.session.test.tools.HazelcastTestHelper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.fail; @@ -41,7 +40,7 @@ public class HazelcastSessionDataStoreClientTest extends AbstractSessionDataStor super(); } - HazelcastTestHelper _testHelper; + HazelcastTestHelper _testHelper = new HazelcastTestHelper(getClass().getSimpleName() + System.nanoTime()); @Override public SessionDataStoreFactory createSessionDataStoreFactory() @@ -49,12 +48,6 @@ public class HazelcastSessionDataStoreClientTest extends AbstractSessionDataStor return _testHelper.createSessionDataStoreFactory(true); } - @BeforeEach - public void configure() - { - _testHelper = new HazelcastTestHelper(); - } - @AfterEach public void shutdown() { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/pom.xml b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/pom.xml index 2335eb6a729..cfd952e0031 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/pom.xml +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/pom.xml @@ -10,10 +10,7 @@ jetty-ee9-test-sessions-infinispan EE9 :: Tests :: Sessions :: Infinispan - true ${project.groupId}.sessions.infinispan - - 11.0.9.Final infinispan/server @@ -114,10 +111,10 @@ infinispan-core test - - org.wildfly.common - wildfly-common - + + org.wildfly.common + wildfly-common + @@ -171,6 +168,11 @@ junit-jupiter test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredOrphanedSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredOrphanedSessionTest.java index ef29b11d26a..906d6510c0d 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredOrphanedSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredOrphanedSessionTest.java @@ -16,6 +16,7 @@ package org.eclipse.jetty.ee9.session.infinispan; import org.eclipse.jetty.ee9.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.AfterEach; @@ -29,19 +30,23 @@ import org.junit.jupiter.api.extension.ExtendWith; public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest { - public InfinispanTestSupport testSupport; + private final InfinispanTestSupport testSupport; + + public ClusteredOrphanedSessionTest() + { + testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + } @BeforeEach public void setup(WorkDir workDir) throws Exception { - testSupport = new InfinispanTestSupport(); testSupport.setup(workDir.getEmptyPathDir()); } @AfterEach public void teardown() throws Exception { - testSupport.teardown(); + testSupport.clearCache(); } @Override diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredSerializedSessionScavengingTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredSerializedSessionScavengingTest.java index 7e973f49723..64ef80a29cb 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredSerializedSessionScavengingTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredSerializedSessionScavengingTest.java @@ -16,6 +16,7 @@ package org.eclipse.jetty.ee9.session.infinispan; import org.eclipse.jetty.ee9.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.AfterEach; @@ -32,20 +33,23 @@ public class ClusteredSerializedSessionScavengingTest extends AbstractClusteredS public WorkDir workDir; public static InfinispanTestSupport testSupport; + public ClusteredSerializedSessionScavengingTest() + { + testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + testSupport.setUseFileStore(true); + testSupport.setSerializeSessionData(true); + } + @BeforeEach public void setup() throws Exception { - testSupport = new InfinispanTestSupport(); - testSupport.setUseFileStore(true); - testSupport.setSerializeSessionData(true); testSupport.setup(workDir.getEmptyPathDir()); } @AfterEach public void teardown() throws Exception { - if (testSupport != null) - testSupport.teardown(); + testSupport.clearCache(); } @Override @@ -56,9 +60,6 @@ public class ClusteredSerializedSessionScavengingTest extends AbstractClusteredS super.testClusteredScavenge(); } - /** - * @see org.eclipse.jetty.session.AbstractSessionTestBase#createSessionDataStoreFactory() - */ @Override public SessionDataStoreFactory createSessionDataStoreFactory() { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredSessionScavengingTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredSessionScavengingTest.java index ed0ef1bc7c6..5a337f54729 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredSessionScavengingTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/ClusteredSessionScavengingTest.java @@ -16,6 +16,7 @@ package org.eclipse.jetty.ee9.session.infinispan; import org.eclipse.jetty.ee9.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.AfterEach; @@ -33,19 +34,22 @@ public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScav public WorkDir workDir; public InfinispanTestSupport testSupport; + public ClusteredSessionScavengingTest() + { + testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + testSupport.setUseFileStore(true); + } + @BeforeEach public void setup() throws Exception { - testSupport = new InfinispanTestSupport(); - testSupport.setUseFileStore(true); testSupport.setup(workDir.getEmptyPathDir()); } @AfterEach public void teardown() throws Exception { - if (testSupport != null) - testSupport.teardown(); + testSupport.clearCache(); } @Override diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanFileSessionDataStoreTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanFileSessionDataStoreTest.java index 6b8efc9db90..ee5758a2a39 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanFileSessionDataStoreTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanFileSessionDataStoreTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.EmbeddedQueryManager; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.QueryManager; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.BeforeEach; @@ -33,13 +34,13 @@ public class InfinispanFileSessionDataStoreTest extends InfinispanSessionDataSto public InfinispanFileSessionDataStoreTest() throws Exception { super(); + _testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + _testSupport.setUseFileStore(true); } @BeforeEach public void configure() throws Exception { - _testSupport = new InfinispanTestSupport(); - _testSupport.setUseFileStore(true); _testSupport.setup(workDir.getEmptyPathDir()); } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanSessionDataStoreTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanSessionDataStoreTest.java index 4d4c1430ae9..1b62756e66f 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanSessionDataStoreTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanSessionDataStoreTest.java @@ -26,6 +26,7 @@ import org.eclipse.jetty.session.infinispan.InfinispanSessionData; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStore; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.QueryManager; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.infinispan.query.Search; @@ -54,19 +55,19 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest public InfinispanSessionDataStoreTest() throws Exception { super(); + _testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); } @BeforeEach public void configure() throws Exception { - _testSupport = new InfinispanTestSupport(); _testSupport.setup(workDir.getEmptyPathDir()); } @AfterEach public void teardown() throws Exception { - _testSupport.teardown(); + _testSupport.clearCache(); } @Override @@ -86,7 +87,7 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - _testSupport.createSession(data); + _testSupport.createSession((InfinispanSessionData)data); } finally { @@ -120,6 +121,7 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest * try and provoke an exception in the InfinispanSessionDataStore.load() method. */ @Override + @Test public void testLoadSessionFails() throws Exception { setUp(); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanTestSupport.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanTestSupport.java deleted file mode 100644 index 10145d5f0f7..00000000000 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/InfinispanTestSupport.java +++ /dev/null @@ -1,226 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee9.session.infinispan; - -import java.lang.annotation.ElementType; -import java.nio.file.Path; -import java.util.Properties; - -import org.eclipse.jetty.session.SessionData; -import org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer; -import org.eclipse.jetty.session.infinispan.InfinispanSessionData; -import org.eclipse.jetty.toolchain.test.FS; -import org.hibernate.search.cfg.Environment; -import org.hibernate.search.cfg.SearchMapping; -import org.infinispan.Cache; -import org.infinispan.configuration.cache.ConfigurationBuilder; -import org.infinispan.configuration.cache.ConfigurationChildBuilder; -import org.infinispan.configuration.cache.StorageType; -import org.infinispan.configuration.global.GlobalConfigurationBuilder; -import org.infinispan.eviction.EvictionStrategy; -import org.infinispan.manager.DefaultCacheManager; -import org.infinispan.manager.EmbeddedCacheManager; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * InfinispanTestSupport - */ -public class InfinispanTestSupport -{ - public static final String DEFAULT_CACHE_NAME = "session_test_cache"; - public Cache _cache; - - public ConfigurationBuilder _builder; - private Path _tmpdir; - private boolean _useFileStore; - private boolean _serializeSessionData; - private String _name; - public static EmbeddedCacheManager _manager; - - static - { - try - { - _manager = new DefaultCacheManager(new GlobalConfigurationBuilder().jmx() - .serialization() - .addContextInitializer(new InfinispanSerializationContextInitializer()) - .build()); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public InfinispanTestSupport() - { - this(null); - } - - public InfinispanTestSupport(String cacheName) - { - if (cacheName == null) - cacheName = DEFAULT_CACHE_NAME + System.nanoTime(); - - _name = cacheName; - _builder = new ConfigurationBuilder(); - } - - public void setUseFileStore(boolean useFileStore) - { - _useFileStore = useFileStore; - } - - public void setSerializeSessionData(boolean serializeSessionData) - { - _serializeSessionData = serializeSessionData; - } - - public Cache getCache() - { - return _cache; - } - - public void setup(Path root) throws Exception - { - Path indexesDir = root.resolve("indexes"); - this._tmpdir = root.resolve("tmp"); - FS.ensureDirExists(indexesDir); - - SearchMapping mapping = new SearchMapping(); - mapping.entity(SessionData.class).indexed().providedId().property("expiry", ElementType.FIELD).field(); - Properties properties = new Properties(); - properties.put(Environment.MODEL_MAPPING, mapping); - properties.put("hibernate.search.default.indexBase", indexesDir.toString()); - properties.put("hibernate.cache.infinispan.entity.eviction.strategy", "NONE"); - - if (_manager.cacheExists(_name)) - { - _manager.administration().removeCache(_name); - } - - if (_useFileStore) - { - ConfigurationChildBuilder b = _builder - .indexing() - .addIndexedEntity(SessionData.class) - .withProperties(properties) - .memory() - .whenFull(EvictionStrategy.NONE) - .persistence() - .addSingleFileStore() - .segmented(false) - .location(_tmpdir.toFile().getAbsolutePath()); - if (_serializeSessionData) - { - b = b.memory().storage(StorageType.HEAP) - .encoding() - .mediaType("application/x-protostream"); - } - _manager.defineConfiguration(_name, b.build()); - } - else - { - ConfigurationChildBuilder b = _builder.indexing() - .withProperties(properties) - .addIndexedEntity(SessionData.class); - - if (_serializeSessionData) - { - b = b.memory().storage(StorageType.HEAP) - .encoding() - .mediaType("application/x-protostream"); - } - - _manager.defineConfiguration(_name, b.build()); - } - _cache = _manager.getCache(_name); - } - - public void teardown() throws Exception - { - _cache.clear(); - _manager.administration().removeCache(_name); - } - - @SuppressWarnings("unchecked") - public void createSession(SessionData data) - throws Exception - { - ((InfinispanSessionData)data).serializeAttributes(); - _cache.put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data); - } - - public void createUnreadableSession(SessionData data) - { - - } - - public boolean checkSessionExists(SessionData data) - throws Exception - { - return (_cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()) != null); - } - - public boolean checkSessionPersisted(SessionData data) - throws Exception - { - //evicts the object from memory. Forces the cache to fetch the data from file - if (_useFileStore) - { - _cache.evict(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); - } - - Object obj = _cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); - if (obj == null) - return false; - - SessionData saved = (SessionData)obj; - - if (saved instanceof InfinispanSessionData) - { - InfinispanSessionData isd = (InfinispanSessionData)saved; - if (isd.getSerializedAttributes() != null) - isd.deserializeAttributes(); - } - - //turn an Entity into a Session - assertEquals(data.getId(), saved.getId()); - assertEquals(data.getContextPath(), saved.getContextPath()); - assertEquals(data.getVhost(), saved.getVhost()); - assertEquals(data.getAccessed(), saved.getAccessed()); - assertEquals(data.getLastAccessed(), saved.getLastAccessed()); - assertEquals(data.getCreated(), saved.getCreated()); - assertEquals(data.getCookieSet(), saved.getCookieSet()); - assertEquals(data.getLastNode(), saved.getLastNode()); - //don't test lastSaved, because that is set only on the SessionData after it returns from SessionDataStore.save() - assertEquals(data.getExpiry(), saved.getExpiry()); - assertEquals(data.getMaxInactiveMs(), saved.getMaxInactiveMs()); - - - //same number of attributes - assertEquals(data.getAllAttributes().size(), saved.getAllAttributes().size()); - //same keys - assertTrue(data.getKeys().equals(saved.getKeys())); - //same values - for (String name : data.getKeys()) - { - assertTrue(data.getAttribute(name).equals(saved.getAttribute(name))); - } - - return true; - } -} diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/SerializedInfinispanSessionDataStoreTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/SerializedInfinispanSessionDataStoreTest.java index 761c06454c2..b1c5a1f097f 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/SerializedInfinispanSessionDataStoreTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/SerializedInfinispanSessionDataStoreTest.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.session.infinispan.InfinispanSessionData; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStore; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.QueryManager; +import org.eclipse.jetty.session.test.tools.InfinispanTestSupport; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.infinispan.query.Search; @@ -55,20 +56,20 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat public SerializedInfinispanSessionDataStoreTest() throws Exception { super(); + _testSupport = new InfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + _testSupport.setSerializeSessionData(true); } @BeforeEach public void setup() throws Exception { - _testSupport = new InfinispanTestSupport(); - _testSupport.setSerializeSessionData(true); _testSupport.setup(workDir.getEmptyPathDir()); } @AfterEach public void teardown() throws Exception { - _testSupport.teardown(); + _testSupport.clearCache(); } @Override @@ -89,7 +90,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - _testSupport.createSession(data); + _testSupport.createSession((InfinispanSessionData)data); } finally { @@ -123,12 +124,14 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat * try and provoke an exception in the InfinispanSessionDataStore.load() method. */ @Override + @Test public void testLoadSessionFails() throws Exception { DefaultSessionIdManager idMgr = new DefaultSessionIdManager(new Server()); //create the SessionDataStore ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/test"); + idMgr.setWorkerName(""); context.getSessionHandler().getSessionManager().setSessionIdManager(idMgr); context.setClassLoader(_contextClassLoader); SessionDataStoreFactory factory = createSessionDataStoreFactory(); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteClusteredInvalidationSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteClusteredInvalidationSessionTest.java index c0ea0fafc83..1ccd376b50f 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteClusteredInvalidationSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteClusteredInvalidationSessionTest.java @@ -14,11 +14,10 @@ package org.eclipse.jetty.ee9.session.infinispan.remote; import org.eclipse.jetty.ee9.session.AbstractClusteredInvalidationSessionTest; -import org.eclipse.jetty.ee9.session.infinispan.LoggingUtil; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.LoggingUtil; +import org.eclipse.jetty.session.test.tools.RemoteInfinispanTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -32,27 +31,19 @@ public class RemoteClusteredInvalidationSessionTest extends AbstractClusteredInv LoggingUtil.init(); } - public static RemoteInfinispanTestSupport __testSupport; + public RemoteInfinispanTestSupport testSupport; - @BeforeAll - public static void setup() throws Exception + public RemoteClusteredInvalidationSessionTest() throws Exception { - __testSupport = new RemoteInfinispanTestSupport("remote-session-test"); - __testSupport.setup(); - } - - @AfterAll - public static void teardown() throws Exception - { - __testSupport.teardown(); - __testSupport.shutdown(); + testSupport = new RemoteInfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + testSupport.setup(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); - factory.setCache(__testSupport.getCache()); + factory.setCache(testSupport.getCache()); return factory; } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteClusteredSessionScavengingTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteClusteredSessionScavengingTest.java index 076b50cfed1..c332e249449 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteClusteredSessionScavengingTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteClusteredSessionScavengingTest.java @@ -14,11 +14,10 @@ package org.eclipse.jetty.ee9.session.infinispan.remote; import org.eclipse.jetty.ee9.session.AbstractClusteredSessionScavengingTest; -import org.eclipse.jetty.ee9.session.infinispan.LoggingUtil; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.eclipse.jetty.session.test.tools.LoggingUtil; +import org.eclipse.jetty.session.test.tools.RemoteInfinispanTestSupport; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -32,27 +31,19 @@ public class RemoteClusteredSessionScavengingTest extends AbstractClusteredSessi LoggingUtil.init(); } - public static RemoteInfinispanTestSupport __testSupport; + public RemoteInfinispanTestSupport testSupport; - @BeforeAll - public static void setup() throws Exception + public RemoteClusteredSessionScavengingTest() throws Exception { - __testSupport = new RemoteInfinispanTestSupport("remote-session-test"); - __testSupport.setup(); - } - - @AfterAll - public static void teardown() throws Exception - { - __testSupport.teardown(); - __testSupport.shutdown(); + testSupport = new RemoteInfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); + testSupport.setup(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); - factory.setCache(__testSupport.getCache()); + factory.setCache(testSupport.getCache()); return factory; } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteInfinispanSessionDataStoreTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteInfinispanSessionDataStoreTest.java index e9f602abd4c..b84084235aa 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteInfinispanSessionDataStoreTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteInfinispanSessionDataStoreTest.java @@ -14,7 +14,6 @@ package org.eclipse.jetty.ee9.session.infinispan.remote; import org.eclipse.jetty.ee9.servlet.ServletContextHandler; -import org.eclipse.jetty.ee9.session.infinispan.LoggingUtil; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.AbstractSessionDataStoreTest; @@ -28,13 +27,13 @@ import org.eclipse.jetty.session.infinispan.InfinispanSessionData; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStore; import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; import org.eclipse.jetty.session.infinispan.RemoteQueryManager; +import org.eclipse.jetty.session.test.tools.LoggingUtil; +import org.eclipse.jetty.session.test.tools.RemoteInfinispanTestSupport; import org.infinispan.client.hotrod.Search; import org.infinispan.query.dsl.Query; import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.dsl.QueryResult; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Testcontainers; @@ -53,43 +52,32 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto LoggingUtil.init(); } - public static RemoteInfinispanTestSupport __testSupport; + public RemoteInfinispanTestSupport testSupport; public RemoteInfinispanSessionDataStoreTest() throws Exception { super(); - } - - @BeforeAll - public static void initRemoteSupport() throws Exception - { - __testSupport = new RemoteInfinispanTestSupport("remote-session-test"); + testSupport = new RemoteInfinispanTestSupport(getClass().getSimpleName() + System.nanoTime()); } @BeforeEach public void configure() throws Exception { - __testSupport.setup(); + testSupport.setup(); } @AfterEach public void teardown() throws Exception { - __testSupport.teardown(); - } - - @AfterAll - public static void shutdown() throws Exception - { - __testSupport.shutdown(); + testSupport.clearCache(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); - factory.setCache(__testSupport.getCache()); - factory.setQueryManager(new RemoteQueryManager(__testSupport.getCache())); + factory.setCache(testSupport.getCache()); + factory.setQueryManager(new RemoteQueryManager(testSupport.getCache())); return factory; } @@ -100,7 +88,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - __testSupport.createSession((InfinispanSessionData)data); + testSupport.createSession((InfinispanSessionData)data); } finally { @@ -122,7 +110,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return __testSupport.checkSessionExists((InfinispanSessionData)data); + return testSupport.checkSessionExists((InfinispanSessionData)data); } finally { @@ -137,7 +125,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return __testSupport.checkSessionPersisted(data); + return testSupport.checkSessionPersisted(data); } finally { @@ -149,6 +137,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto * This test deliberately sets the infinispan cache to null to * try and provoke an exception in the InfinispanSessionDataStore.load() method. */ + @Test @Override public void testLoadSessionFails() throws Exception { @@ -156,6 +145,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto //create the SessionDataStore ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/test"); + idMgr.setWorkerName(""); context.getSessionHandler().getSessionManager().setSessionIdManager(idMgr); SessionDataStoreFactory factory = createSessionDataStoreFactory(); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); @@ -183,19 +173,19 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000); sd1.setLastNode("fred1"); sd1.serializeAttributes(); - __testSupport.getCache().put("session1", sd1); + testSupport.getCache().put("session1", sd1); InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000); sd2.setLastNode("fred2"); sd2.serializeAttributes(); - __testSupport.getCache().put("session2", sd2); + testSupport.getCache().put("session2", sd2); InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000); sd3.setLastNode("fred3"); sd3.serializeAttributes(); - __testSupport.getCache().put("session3", sd3); + testSupport.getCache().put("session3", sd3); - QueryFactory qf = Search.getQueryFactory(__testSupport.getCache()); + QueryFactory qf = Search.getQueryFactory(testSupport.getCache()); Query query = qf.create("from org_eclipse_jetty_session_infinispan.InfinispanSessionData where " + " expiry < :time"); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/pom.xml b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/pom.xml index 590eb7bc6db..3973d274cda 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/pom.xml +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/pom.xml @@ -9,7 +9,6 @@ jetty-ee9-test-sessions-jdbc EE9 :: Tests :: Sessions :: JDBC - false ${project.groupId}.sessions.jdbc diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredInvalidationSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredInvalidationSessionTest.java index 97c857cc0cd..2f8d949f8be 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredInvalidationSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredInvalidationSessionTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.ee9.session.AbstractClusteredInvalidationSessionTest; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -25,15 +26,24 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredInvalidationSessionTest extends AbstractClusteredInvalidationSessionTest { + + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + } + @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredOrphanedSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredOrphanedSessionTest.java index c0a8e9caeca..371b7d2dd7d 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredOrphanedSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredOrphanedSessionTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.ee9.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -25,15 +26,24 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest { + + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + } + @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredSessionMigrationTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredSessionMigrationTest.java index d5137711044..00e4289d7dc 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredSessionMigrationTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredSessionMigrationTest.java @@ -23,7 +23,6 @@ import jakarta.servlet.http.HttpSession; import org.eclipse.jetty.client.ContentResponse; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.Request; -import org.eclipse.jetty.ee9.session.AbstractSessionTestBase; import org.eclipse.jetty.ee9.session.SessionTestSupport; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; @@ -31,7 +30,9 @@ import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionCache; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.AbstractSessionTestBase; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Testcontainers; @@ -51,16 +52,25 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @Testcontainers(disabledWithoutDocker = true) public class ClusteredSessionMigrationTest extends AbstractSessionTestBase { + + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + } + @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } @Test diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredSessionScavengingTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredSessionScavengingTest.java index 6c1b446d7f1..7ae4fafa6f5 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredSessionScavengingTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ClusteredSessionScavengingTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.ee9.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -25,15 +26,23 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest { + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + } + @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/JDBCSessionDataStoreTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/JDBCSessionDataStoreTest.java index 355f3d5bd56..1e04699ccec 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/JDBCSessionDataStoreTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/JDBCSessionDataStoreTest.java @@ -33,29 +33,32 @@ public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest super(); } + private String sessionTableName; + @BeforeEach - public void configure() throws Exception + public void setupSessionTableName() throws Exception { - JdbcTestHelper.prepareTables(); + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + JdbcTestHelper.prepareTables(sessionTableName); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @Override public void persistSession(SessionData data) throws Exception { - JdbcTestHelper.insertSession(data); + JdbcTestHelper.insertSession(data, sessionTableName); } @Override @@ -64,7 +67,7 @@ public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest JdbcTestHelper.insertUnreadableSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), data.getCookieSet(), - data.getLastSaved()); + data.getLastSaved(), sessionTableName); } @Test @@ -76,7 +79,7 @@ public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest @Override public boolean checkSessionExists(SessionData data) throws Exception { - return JdbcTestHelper.existsInSessionTable(data.getId(), false); + return JdbcTestHelper.existsInSessionTable(data.getId(), false, sessionTableName); } @Override @@ -86,7 +89,7 @@ public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return JdbcTestHelper.checkSessionPersisted(data); + return JdbcTestHelper.checkSessionPersisted(data, sessionTableName); } finally { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ReloadedSessionMissingClassTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ReloadedSessionMissingClassTest.java index a86051bf9f5..8f46e856cda 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ReloadedSessionMissingClassTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/ReloadedSessionMissingClassTest.java @@ -34,6 +34,7 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.testcontainers.junit.jupiter.Testcontainers; @@ -51,6 +52,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class ReloadedSessionMissingClassTest { + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + } + @Test public void testSessionReloadWithMissingClass(WorkDir workDir) throws Exception { @@ -88,7 +97,7 @@ public class ReloadedSessionMissingClassTest DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT); - SessionDataStoreFactory storeFactory = JdbcTestHelper.newSessionDataStoreFactory(); + SessionDataStoreFactory storeFactory = JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); ((AbstractSessionDataStoreFactory)storeFactory).setGracePeriodSec(SessionTestSupport.DEFAULT_SCAVENGE_SEC); SessionTestSupport server1 = new SessionTestSupport(0, SessionTestSupport.DEFAULT_MAX_INACTIVE, SessionTestSupport.DEFAULT_SCAVENGE_SEC, cacheFactory, storeFactory); @@ -110,7 +119,7 @@ public class ReloadedSessionMissingClassTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); String sessionCookie = response.getHeaders().get("Set-Cookie"); - assertTrue(sessionCookie != null); + assertNotNull(sessionCookie); String sessionId = (String)webApp.getServletContext().getAttribute("foo"); assertNotNull(sessionId); @@ -146,6 +155,6 @@ public class ReloadedSessionMissingClassTest @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/SessionTableSchemaTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/SessionTableSchemaTest.java index 6e5f6f5a9a9..ede0505da30 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/SessionTableSchemaTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/SessionTableSchemaTest.java @@ -45,9 +45,12 @@ public class SessionTableSchemaTest DatabaseAdaptor _da; JDBCSessionDataStore.SessionTableSchema _tableSchema; + private String sessionTableName; + @BeforeEach public void setUp() throws Exception { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); //pretend to be an Oracle-like database that treats "" as NULL _da = new DatabaseAdaptor() { @@ -59,14 +62,14 @@ public class SessionTableSchemaTest } }; _da.setDriverInfo(JdbcTestHelper.DRIVER_CLASS, JdbcTestHelper.DEFAULT_CONNECTION_URL); - _tableSchema = JdbcTestHelper.newSessionTableSchema(); + _tableSchema = JdbcTestHelper.newSessionTableSchema(sessionTableName); JdbcTestHelper.setDatabaseAdaptor(_tableSchema, _da); } @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } /** @@ -79,12 +82,12 @@ public class SessionTableSchemaTest * @param vhost the virtual host of the session * @throws Exception */ - public static void insertSessionWithoutAttributes(String id, String contextPath, String vhost) + public void insertSessionWithoutAttributes(String id, String contextPath, String vhost) throws Exception { try (Connection con = JdbcTestHelper.getConnection()) { - PreparedStatement statement = con.prepareStatement("insert into " + JdbcTestHelper.TABLE + + PreparedStatement statement = con.prepareStatement("insert into " + sessionTableName + " (" + JdbcTestHelper.ID_COL + ", " + JdbcTestHelper.CONTEXT_COL + ", virtualHost, " + JdbcTestHelper.LAST_NODE_COL + ", " + JdbcTestHelper.ACCESS_COL + ", " + JdbcTestHelper.LAST_ACCESS_COL + ", " + JdbcTestHelper.CREATE_COL + ", " + JdbcTestHelper.COOKIE_COL + ", " + JdbcTestHelper.LAST_SAVE_COL + ", " + JdbcTestHelper.EXPIRY_COL + " " + ") " + @@ -186,7 +189,7 @@ public class SessionTableSchemaTest PreparedStatement s = _tableSchema.getDeleteStatement(con, id, sc); assertEquals(1, s.executeUpdate()); - assertFalse(JdbcTestHelper.existsInSessionTable(id, false)); + assertFalse(JdbcTestHelper.existsInSessionTable(id, false, sessionTableName)); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/WebAppObjectInSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/WebAppObjectInSessionTest.java index 9bfdc2880e7..3cbcd6f0663 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/WebAppObjectInSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-jdbc/src/test/java/org/eclipse/jetty/ee9/session/jdbc/WebAppObjectInSessionTest.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.ee9.session.AbstractWebAppObjectInSessionTest; import org.eclipse.jetty.session.JdbcTestHelper; import org.eclipse.jetty.session.SessionDataStoreFactory; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Testcontainers; @@ -26,10 +27,20 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class WebAppObjectInSessionTest extends AbstractWebAppObjectInSessionTest { + + private String sessionTableName; + + @BeforeEach + public void setupSessionTableName() throws Exception + { + this.sessionTableName = getClass().getSimpleName() + "_" + System.nanoTime(); + JdbcTestHelper.prepareTables(sessionTableName); + } + @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return JdbcTestHelper.newSessionDataStoreFactory(); + return JdbcTestHelper.newSessionDataStoreFactory(sessionTableName); } @Test @@ -41,6 +52,6 @@ public class WebAppObjectInSessionTest extends AbstractWebAppObjectInSessionTest @AfterEach public void tearDown() throws Exception { - JdbcTestHelper.shutdown(null); + JdbcTestHelper.shutdown(sessionTableName); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/pom.xml b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/pom.xml index 209ef383857..0a3f888ad0e 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/pom.xml +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/pom.xml @@ -57,5 +57,10 @@ junit-jupiter test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee9/session/memcached/CachingSessionDataStoreTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee9/session/memcached/CachingSessionDataStoreTest.java index 2fbd0ebdcbd..55e6fec0491 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee9/session/memcached/CachingSessionDataStoreTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee9/session/memcached/CachingSessionDataStoreTest.java @@ -25,13 +25,13 @@ import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.Request; import org.eclipse.jetty.ee9.servlet.ServletContextHandler; import org.eclipse.jetty.ee9.session.SessionTestSupport; -import org.eclipse.jetty.ee9.session.memcached.MemcachedTestHelper.MockDataStore; import org.eclipse.jetty.session.CachingSessionDataStore; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataMap; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MemcachedTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Testcontainers; @@ -93,11 +93,11 @@ public class CachingSessionDataStoreTest // //Update a session and check that is is NOT loaded via the persistent store // - ((MockDataStore)persistentStore).zeroLoadCount(); + ((MemcachedTestHelper.MockDataStore)persistentStore).zeroLoadCount(); Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=update"); response = request.send(); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); - assertEquals(0, ((MockDataStore)persistentStore).getLoadCount()); + assertEquals(0, ((MemcachedTestHelper.MockDataStore)persistentStore).getLoadCount()); //check it was updated in the persistent store SessionData sd = persistentStore.load(id); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/pom.xml b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/pom.xml index 676991a302f..45677998ab1 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/pom.xml +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/pom.xml @@ -9,9 +9,7 @@ jetty-ee9-test-sessions-mongodb EE9 :: Tests :: Sessions :: Mongo - false ${project.groupId}.sessions.mongo - localhost @@ -24,32 +22,6 @@ - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-test-resources - - unpack - - - - - org.eclipse.jetty.toolchain - jetty-test-policy - ${jetty-test-policy.version} - jar - true - **/*.keystore,**/*.pem - ${jetty.test.policy.loc} - - - - - - @@ -125,5 +97,10 @@ slf4j-simple test + + org.eclipse.jetty.tests + jetty-test-session-common + test + diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/AttributeNameTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/AttributeNameTest.java index 581d0c177b7..b58a2b56a37 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/AttributeNameTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/AttributeNameTest.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.nosql.mongodb.MongoSessionDataStoreFactory; import org.eclipse.jetty.session.DefaultSessionCacheFactory; import org.eclipse.jetty.session.SessionCache; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.eclipse.jetty.util.NanoTime; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -46,16 +47,21 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @Testcontainers(disabledWithoutDocker = true) public class AttributeNameTest { + + private static final String DB_NAME = "DB" + AttributeNameTest.class.getSimpleName() + System.nanoTime(); + + private static final String COLLECTION_NAME = "COLLECTION" + AttributeNameTest.class.getSimpleName() + System.nanoTime(); + @BeforeAll public static void beforeClass() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterAll public static void afterClass() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); MongoTestHelper.shutdown(); } @@ -70,7 +76,7 @@ public class AttributeNameTest DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT); - MongoSessionDataStoreFactory storeFactory = MongoTestHelper.newSessionDataStoreFactory(); + MongoSessionDataStoreFactory storeFactory = MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); storeFactory.setGracePeriodSec(scavengePeriod); SessionTestSupport server1 = new SessionTestSupport(0, maxInactivePeriod, scavengePeriod, cacheFactory, storeFactory); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredInvalidateSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredInvalidateSessionTest.java index afd0ade7617..75376f59de6 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredInvalidateSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredInvalidateSessionTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.ee9.session.nosql.mongodb; import org.eclipse.jetty.ee9.session.AbstractClusteredInvalidationSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.testcontainers.junit.jupiter.Testcontainers; @@ -22,22 +23,27 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredInvalidateSessionTest extends AbstractClusteredInvalidationSessionTest { + + private static final String DB_NAME = "DB" + ClusteredInvalidateSessionTest.class.getSimpleName() + System.nanoTime(); + + private static final String COLLECTION_NAME = "COLLECTION" + ClusteredInvalidateSessionTest.class.getSimpleName() + System.nanoTime(); + @BeforeAll public static void beforeClass() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterAll public static void afterClass() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); MongoTestHelper.shutdown(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return MongoTestHelper.newSessionDataStoreFactory(); + return MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredOrphanedSessionTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredOrphanedSessionTest.java index 1fca682bf41..5244d355d3f 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredOrphanedSessionTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredOrphanedSessionTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.ee9.session.nosql.mongodb; import org.eclipse.jetty.ee9.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -26,23 +27,28 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest { + + private static final String DB_NAME = "DB" + ClusteredOrphanedSessionTest.class.getSimpleName() + System.nanoTime(); + + private static final String COLLECTION_NAME = "COLLECTION" + ClusteredOrphanedSessionTest.class.getSimpleName() + System.nanoTime(); + @BeforeAll public static void beforeClass() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterAll public static void afterClass() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); MongoTestHelper.shutdown(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return MongoTestHelper.newSessionDataStoreFactory(); + return MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); } @Test diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredSessionScavengingTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredSessionScavengingTest.java index cffc541665f..c970a6186e9 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredSessionScavengingTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/ClusteredSessionScavengingTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.ee9.session.nosql.mongodb; import org.eclipse.jetty.ee9.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.testcontainers.junit.jupiter.Testcontainers; @@ -22,22 +23,27 @@ import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers(disabledWithoutDocker = true) public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest { + + private static final String DB_NAME = "DB" + ClusteredSessionScavengingTest.class.getSimpleName() + System.nanoTime(); + + private static final String COLLECTION_NAME = "COLLECTION" + ClusteredSessionScavengingTest.class.getSimpleName() + System.nanoTime(); + @BeforeAll public static void beforeClass() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterAll public static void afterClass() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); MongoTestHelper.shutdown(); } @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return MongoTestHelper.newSessionDataStoreFactory(); + return MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/MongoSessionDataStoreTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/MongoSessionDataStoreTest.java index a2fa5f63223..a8e2d86ff29 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/MongoSessionDataStoreTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/MongoSessionDataStoreTest.java @@ -27,6 +27,7 @@ import org.eclipse.jetty.session.SessionContext; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStore; import org.eclipse.jetty.session.SessionDataStoreFactory; +import org.eclipse.jetty.session.test.tools.MongoTestHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -42,6 +43,11 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @Testcontainers(disabledWithoutDocker = true) public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest { + + private static final String DB_NAME = "DB" + MongoSessionDataStoreTest.class.getSimpleName() + System.nanoTime(); + + private static final String COLLECTION_NAME = "COLLECTION" + MongoSessionDataStoreTest.class.getSimpleName() + System.nanoTime(); + public MongoSessionDataStoreTest() throws Exception { super(); @@ -50,13 +56,13 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest @BeforeEach public void beforeEach() throws Exception { - MongoTestHelper.createCollection(); + MongoTestHelper.createCollection(DB_NAME, COLLECTION_NAME); } @AfterEach public void afterEach() throws Exception { - MongoTestHelper.dropCollection(); + MongoTestHelper.dropCollection(DB_NAME, COLLECTION_NAME); } @AfterAll @@ -68,27 +74,29 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest @Override public SessionDataStoreFactory createSessionDataStoreFactory() { - return MongoTestHelper.newSessionDataStoreFactory(); + return MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); } @Override public void persistSession(SessionData data) throws Exception { MongoTestHelper.createSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), - data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), data.getAllAttributes()); + data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), data.getAllAttributes(), + DB_NAME, COLLECTION_NAME); } @Override public void persistUnreadableSession(SessionData data) throws Exception { MongoTestHelper.createUnreadableSession(data.getId(), data.getContextPath(), data.getVhost(), data.getLastNode(), data.getCreated(), - data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), null); + data.getAccessed(), data.getLastAccessed(), data.getMaxInactiveMs(), data.getExpiry(), null, + DB_NAME, COLLECTION_NAME); } @Override public boolean checkSessionExists(SessionData data) throws Exception { - return MongoTestHelper.checkSessionExists(data.getId()); + return MongoTestHelper.checkSessionExists(data.getId(), DB_NAME, COLLECTION_NAME); } @Override @@ -98,7 +106,7 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest Thread.currentThread().setContextClassLoader(_contextClassLoader); try { - return MongoTestHelper.checkSessionPersisted(data); + return MongoTestHelper.checkSessionPersisted(data, DB_NAME, COLLECTION_NAME); } finally { @@ -129,13 +137,13 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest Map attributes = new HashMap<>(); attributes.put("attribute1", "attribute1value"); - attributes.put("attribute2", new ArrayList(Arrays.asList("1", "2", "3"))); + attributes.put("attribute2", new ArrayList<>(Arrays.asList("1", "2", "3"))); MongoTestHelper.createLegacySession("1234", sessionContext.getCanonicalContextPath(), sessionContext.getVhost(), "foo", 1000L, System.currentTimeMillis() - 1000L, System.currentTimeMillis() - 2000L, -1, -1, - attributes); + attributes, DB_NAME, COLLECTION_NAME); store.start(); @@ -152,6 +160,6 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest store.store("1234", loaded); //and that it has now been written out with the new format - MongoTestHelper.checkSessionPersisted(loaded); + MongoTestHelper.checkSessionPersisted(loaded, DB_NAME, COLLECTION_NAME); } } diff --git a/jetty-integrations/jetty-infinispan/jetty-infinispan-remote-query/pom.xml b/jetty-integrations/jetty-infinispan/jetty-infinispan-remote-query/pom.xml index f3ab4d61821..dd338cde01c 100644 --- a/jetty-integrations/jetty-infinispan/jetty-infinispan-remote-query/pom.xml +++ b/jetty-integrations/jetty-infinispan/jetty-infinispan-remote-query/pom.xml @@ -9,7 +9,6 @@ Integrations :: Infinispan :: Remote with Querying ${project.groupId}.infinispan.remote.query - 11.0.9.Final diff --git a/jetty-p2/pom.xml b/jetty-p2/pom.xml deleted file mode 100644 index 2f64621b0fe..00000000000 --- a/jetty-p2/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - org.eclipse.jetty - jetty-project - 12.0.0-SNAPSHOT - - 4.0.0 - jetty-p2 - Jetty :: P2 - Generates a (maven based) P2 Updatesite - pom - - 3.0.4 - - - - - org.eclipse.tycho - tycho-p2-repository-plugin - ${tycho-version} - - - - Jetty Bundles - true - false - true - - maven-p2-site - prepare-package - - assemble-maven-repository - - - - - - - - - - org.eclipse.jetty - jetty-home - ${project.version} - pom - - - org.eclipse.jetty.osgi - jetty-osgi-alpn - - - org.eclipse.jetty.osgi - jetty-osgi-boot - - - org.eclipse.jetty.osgi - jetty-osgi-boot-jsp - - - org.eclipse.jetty.osgi - jetty-osgi-boot-warurl - - - org.eclipse.jetty.osgi - jetty-httpservice - - - diff --git a/pom.xml b/pom.xml index 10ab2bd8973..f5f7befec1a 100644 --- a/pom.xml +++ b/pom.xml @@ -197,6 +197,9 @@ 3.2.20 src/it/settings.xml 0 + + + 11.0.14.Final @@ -1462,6 +1465,11 @@ jetty-http-tools ${project.version} + + org.eclipse.jetty.tests + jetty-test-session-common + ${project.version} + org.eclipse.jetty.tests test-distribution-common diff --git a/tests/jetty-test-session-common/pom.xml b/tests/jetty-test-session-common/pom.xml new file mode 100644 index 00000000000..5f96fd3e016 --- /dev/null +++ b/tests/jetty-test-session-common/pom.xml @@ -0,0 +1,136 @@ + + + org.eclipse.jetty.tests + tests + 12.0.0-SNAPSHOT + + + 4.0.0 + jetty-test-session-common + Tests :: Session Test Tools + jar + + + ${project.groupId}.session.test.tools + + + + + org.slf4j + slf4j-api + + + org.junit.jupiter + junit-jupiter + compile + + + org.testcontainers + testcontainers + compile + + + org.testcontainers + junit-jupiter + compile + + + org.testcontainers + mongodb + true + compile + + + org.eclipse.jetty + jetty-nosql + true + compile + + + org.mongodb + mongo-java-driver + ${mongodb.version} + compile + + + org.eclipse.jetty.memcached + jetty-memcached-sessions + true + compile + + + org.eclipse.jetty.toolchain + jetty-test-helper + true + compile + + + org.hibernate + hibernate-search-engine + 5.10.7.Final + true + compile + + + org.slf4j + jul-to-slf4j + true + compile + + + org.eclipse.jetty + jetty-infinispan-common + true + compile + + + org.infinispan + infinispan-core + true + compile + + + org.wildfly.common + wildfly-common + + + + + org.infinispan + infinispan-client-hotrod + true + compile + + + org.eclipse.jetty + jetty-hazelcast + true + compile + + + com.hazelcast + hazelcast + + + + + com.hazelcast + hazelcast + true + compile + + + org.testcontainers + gcloud + true + compile + + + org.eclipse.jetty.gcloud + jetty-gcloud-session-manager + true + compile + + + + diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractSessionTestBase.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/AbstractSessionTestBase.java similarity index 95% rename from jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractSessionTestBase.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/AbstractSessionTestBase.java index 66ec18d87f1..41f9fd6f44c 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractSessionTestBase.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/AbstractSessionTestBase.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee10.session; +package org.eclipse.jetty.session.test; import org.eclipse.jetty.session.SessionDataStoreFactory; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/Foo.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/Foo.java similarity index 94% rename from jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/Foo.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/Foo.java index f701e020620..272658e8beb 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/Foo.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/Foo.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee10.session; +package org.eclipse.jetty.session.test; /** * Foo diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/FooInvocationHandler.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/FooInvocationHandler.java similarity index 96% rename from jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/FooInvocationHandler.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/FooInvocationHandler.java index 57cc9a29002..2afe941a0da 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/FooInvocationHandler.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/FooInvocationHandler.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.session; +package org.eclipse.jetty.session.test; import java.io.Serializable; import java.lang.reflect.InvocationHandler; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/TestFoo.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/TestFoo.java similarity index 96% rename from jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/TestFoo.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/TestFoo.java index e57261a58f3..80e42d6e373 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/TestFoo.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/TestFoo.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.session; +package org.eclipse.jetty.session.test; import java.io.Serializable; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/TestSessionDataStore.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/TestSessionDataStore.java similarity index 98% rename from jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/TestSessionDataStore.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/TestSessionDataStore.java index 88624a3da4c..6a9e49f5e67 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/TestSessionDataStore.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/TestSessionDataStore.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee10.session; +package org.eclipse.jetty.session.test; import java.util.HashSet; import java.util.Map; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/TestSessionDataStoreFactory.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/TestSessionDataStoreFactory.java similarity index 96% rename from jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/TestSessionDataStoreFactory.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/TestSessionDataStoreFactory.java index db1990938fa..3b3f378ae2c 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/TestSessionDataStoreFactory.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/TestSessionDataStoreFactory.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee10.session; +package org.eclipse.jetty.session.test; import org.eclipse.jetty.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.session.SessionDataStore; diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/GCloudSessionTestSupport.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/GCloudSessionTestSupport.java similarity index 75% rename from jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/GCloudSessionTestSupport.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/GCloudSessionTestSupport.java index 157d5b637b8..737f797aa5b 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-gcloud/src/test/java/org/eclipse/jetty/ee10/session/gcloud/GCloudSessionTestSupport.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/GCloudSessionTestSupport.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee10.session.gcloud; +package org.eclipse.jetty.session.test.tools; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; @@ -20,7 +20,9 @@ import java.net.URL; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; import com.google.cloud.NoCredentials; @@ -43,8 +45,10 @@ import org.eclipse.jetty.gcloud.session.GCloudSessionDataStore.EntityDataModel; import org.eclipse.jetty.gcloud.session.GCloudSessionDataStoreFactory; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStore; +import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; import org.eclipse.jetty.util.ClassLoadingObjectInputStream; +import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.containers.DatastoreEmulatorContainer; @@ -53,7 +57,6 @@ import org.testcontainers.utility.DockerImageName; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * GCloudSessionTestSupport @@ -66,11 +69,37 @@ public class GCloudSessionTestSupport private static final Logger LOGGER = LoggerFactory.getLogger(GCloudSessionTestSupport.class); private static final Logger GCLOUD_LOG = LoggerFactory.getLogger("org.eclipse.jetty.gcloud.session.gcloudLogs"); - public DatastoreEmulatorContainer emulator = new DatastoreEmulatorContainer( + public static DatastoreEmulatorContainer emulator = new DatastoreEmulatorContainer( DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:316.0.0-emulators") ).withLogConsumer(new Slf4jLogConsumer(GCLOUD_LOG)) .withFlags("--consistency=1.0"); + private static final String host; + + static + { + try + { + emulator.start(); + //work out if we're running locally or not: if not local, then the host passed to + //DatastoreOptions must be prefixed with a scheme + String endPoint = emulator.getEmulatorEndpoint(); + InetAddress hostAddr = InetAddress.getByName(new URL("http://" + endPoint).getHost()); + LOGGER.info("endPoint: {} ,hostAddr.isAnyLocalAddress(): {},hostAddr.isLoopbackAddress(): {}", + endPoint, + hostAddr.isAnyLocalAddress(), + hostAddr.isLoopbackAddress()); + if (hostAddr.isAnyLocalAddress() || hostAddr.isLoopbackAddress()) + host = endPoint; + else + host = "http://" + endPoint; + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + public static class TestGCloudSessionDataStoreFactory extends GCloudSessionDataStoreFactory { Datastore _d; @@ -90,42 +119,28 @@ public class GCloudSessionTestSupport } } - public static GCloudSessionDataStoreFactory newSessionDataStoreFactory(Datastore d) + public SessionDataStoreFactory newSessionDataStoreFactory() { - return new TestGCloudSessionDataStoreFactory(d); + return new TestGCloudSessionDataStoreFactory(getDatastore()); } - public GCloudSessionTestSupport() + public GCloudSessionTestSupport(String projectId) { - // no op + Objects.requireNonNull(projectId, "projectId cannot be null"); + DatastoreOptions options = DatastoreOptions.newBuilder() + .setHost(host) + .setCredentials(NoCredentials.getInstance()) + .setRetrySettings(ServiceOptions.getNoRetrySettings()) + .setProjectId(projectId.toLowerCase(Locale.ROOT) + "-project") + .build(); + _ds = options.getService(); + _keyFactory = _ds.newKeyFactory().setKind(EntityDataModel.KIND); } public void setUp() throws Exception { - emulator.start(); - String host; - //work out if we're running locally or not: if not local, then the host passed to - //DatastoreOptions must be prefixed with a scheme - String endPoint = emulator.getEmulatorEndpoint(); - InetAddress hostAddr = InetAddress.getByName(new URL("http://" + endPoint).getHost()); - LOGGER.info("endPoint: {} ,hostAddr.isAnyLocalAddress(): {},hostAddr.isLoopbackAddress(): {}", - endPoint, - hostAddr.isAnyLocalAddress(), - hostAddr.isLoopbackAddress()); - if (hostAddr.isAnyLocalAddress() || hostAddr.isLoopbackAddress()) - host = endPoint; - else - host = "http://" + endPoint; - - DatastoreOptions options = DatastoreOptions.newBuilder() - .setHost(host) - .setCredentials(NoCredentials.getInstance()) - .setRetrySettings(ServiceOptions.getNoRetrySettings()) - .setProjectId("test-project") - .build(); - _ds = options.getService(); - _keyFactory = _ds.newKeyFactory().setKind(EntityDataModel.KIND); + // no op } public Datastore getDatastore() @@ -136,13 +151,7 @@ public class GCloudSessionTestSupport public void tearDown() throws Exception { - emulator.stop(); - } - - public void reset() throws Exception - { - emulator.stop(); - this.setUp(); + // no op } public void createSession(String id, String contextPath, String vhost, @@ -191,18 +200,18 @@ public class GCloudSessionTestSupport return false; //turn an Entity into a Session - assertEquals(data.getId(), entity.getString(EntityDataModel.ID)); - assertEquals(data.getContextPath(), entity.getString(EntityDataModel.CONTEXTPATH)); - assertEquals(data.getVhost(), entity.getString(EntityDataModel.VHOST)); - assertEquals(data.getAccessed(), entity.getLong(EntityDataModel.ACCESSED)); - assertEquals(data.getLastAccessed(), entity.getLong(EntityDataModel.LASTACCESSED)); - assertEquals(data.getCreated(), entity.getLong(EntityDataModel.CREATETIME)); - assertEquals(data.getCookieSet(), entity.getLong(EntityDataModel.COOKIESETTIME)); - assertEquals(data.getLastNode(), entity.getString(EntityDataModel.LASTNODE)); - assertEquals(data.getLastSaved(), entity.getLong(EntityDataModel.LASTSAVED)); - assertEquals(data.getExpiry(), entity.getLong(EntityDataModel.EXPIRY)); - assertEquals(data.getMaxInactiveMs(), entity.getLong(EntityDataModel.MAXINACTIVE)); - Blob blob = (Blob)entity.getBlob(EntityDataModel.ATTRIBUTES); + Assertions.assertEquals(data.getId(), entity.getString(EntityDataModel.ID)); + Assertions.assertEquals(data.getContextPath(), entity.getString(EntityDataModel.CONTEXTPATH)); + Assertions.assertEquals(data.getVhost(), entity.getString(EntityDataModel.VHOST)); + Assertions.assertEquals(data.getAccessed(), entity.getLong(EntityDataModel.ACCESSED)); + Assertions.assertEquals(data.getLastAccessed(), entity.getLong(EntityDataModel.LASTACCESSED)); + Assertions.assertEquals(data.getCreated(), entity.getLong(EntityDataModel.CREATETIME)); + Assertions.assertEquals(data.getCookieSet(), entity.getLong(EntityDataModel.COOKIESETTIME)); + Assertions.assertEquals(data.getLastNode(), entity.getString(EntityDataModel.LASTNODE)); + Assertions.assertEquals(data.getLastSaved(), entity.getLong(EntityDataModel.LASTSAVED)); + Assertions.assertEquals(data.getExpiry(), entity.getLong(EntityDataModel.EXPIRY)); + Assertions.assertEquals(data.getMaxInactiveMs(), entity.getLong(EntityDataModel.MAXINACTIVE)); + Blob blob = entity.getBlob(EntityDataModel.ATTRIBUTES); SessionData tmp = new SessionData(data.getId(), entity.getString(EntityDataModel.CONTEXTPATH), entity.getString(EntityDataModel.VHOST), @@ -219,11 +228,11 @@ public class GCloudSessionTestSupport //same number of attributes assertEquals(data.getAllAttributes().size(), tmp.getAllAttributes().size()); //same keys - assertTrue(data.getKeys().equals(tmp.getAllAttributes().keySet())); + assertEquals(data.getKeys(), tmp.getAllAttributes().keySet()); //same values for (String name : data.getKeys()) { - assertTrue(data.getAttribute(name).equals(tmp.getAttribute(name))); + assertEquals(data.getAttribute(name), tmp.getAttribute(name)); } return true; @@ -249,8 +258,8 @@ public class GCloudSessionTestSupport public Set getSessionIds() throws Exception { - HashSet ids = new HashSet(); - GqlQuery.Builder builder = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + GCloudSessionDataStore.EntityDataModel.KIND); + HashSet ids = new HashSet<>(); + GqlQuery.Builder builder = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + GCloudSessionDataStore.EntityDataModel.KIND); Query query = builder.build(); @@ -316,7 +325,7 @@ public class GCloudSessionTestSupport keys.add(results.next()); } - batch.delete(keys.toArray(new Key[keys.size()])); + batch.delete(keys.toArray(new Key[0])); } batch.submit(); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastTestHelper.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/HazelcastTestHelper.java similarity index 82% rename from jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastTestHelper.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/HazelcastTestHelper.java index 2cdea78ef30..42880dc07e3 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-hazelcast/src/test/java/org/eclipse/jetty/ee10/session/hazelcast/HazelcastTestHelper.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/HazelcastTestHelper.java @@ -11,9 +11,10 @@ // ======================================================================== // -package org.eclipse.jetty.ee10.session.hazelcast; +package org.eclipse.jetty.session.test.tools; import java.util.Collections; +import java.util.Objects; import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; @@ -27,19 +28,17 @@ import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.hazelcast.session.SessionDataSerializer; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.SessionDataStoreFactory; -import org.eclipse.jetty.util.NanoTime; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * HazelcastTestHelper */ public class HazelcastTestHelper { - static final String _name = Long.toString(NanoTime.now()); + private final String mapName; - static final String _hazelcastInstanceName = "SESSION_TEST_" + _name; + static final String _hazelcastInstanceName = "SESSION_TEST_" + System.nanoTime(); static SerializerConfig _serializerConfig; @@ -60,21 +59,22 @@ public class HazelcastTestHelper Config config = new Config(); config.setInstanceName(_hazelcastInstanceName); config.getNetworkConfig().getJoin().getAutoDetectionConfig().setEnabled(false); - config.addMapConfig(new MapConfig().setName(_name)).setClassLoader(null); config.getSerializationConfig().addSerializerConfig(_serializerConfig); _instance = Hazelcast.getOrCreateHazelcastInstance(config); } - public HazelcastTestHelper() + public HazelcastTestHelper(String mapName) { - // noop + Objects.requireNonNull(mapName, "Hazelcast mapName cannot be null"); + this.mapName = mapName; + _instance.getConfig().addMapConfig(new MapConfig().setName(this.mapName)).setClassLoader(null); } public SessionDataStoreFactory createSessionDataStoreFactory(boolean onlyClient) { HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory(); factory.setOnlyClient(onlyClient); - factory.setMapName(_name); + factory.setMapName(this.mapName); factory.setUseQueries(true); if (onlyClient) { @@ -99,22 +99,22 @@ public class HazelcastTestHelper public void tearDown() { - _instance.getMap(_name).clear(); + _instance.getMap(this.mapName).clear(); } public void createSession(SessionData data) { - Object o = _instance.getMap(_name).put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data); + _instance.getMap(this.mapName).put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data); } public boolean checkSessionExists(SessionData data) { - return (_instance.getMap(_name).get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()) != null); + return (_instance.getMap(this.mapName).get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()) != null); } public boolean checkSessionPersisted(SessionData data) { - Object obj = _instance.getMap(_name).get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); + Object obj = _instance.getMap(this.mapName).get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); if (obj == null) return false; @@ -134,11 +134,11 @@ public class HazelcastTestHelper //same number of attributes assertEquals(data.getAllAttributes().size(), saved.getAllAttributes().size()); //same keys - assertTrue(data.getKeys().equals(saved.getKeys())); + assertEquals(data.getKeys(), saved.getKeys()); //same values for (String name : data.getKeys()) { - assertTrue(data.getAttribute(name).equals(saved.getAttribute(name))); + assertEquals(data.getAttribute(name), saved.getAttribute(name)); } return true; } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanTestSupport.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/InfinispanTestSupport.java similarity index 76% rename from jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanTestSupport.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/InfinispanTestSupport.java index 99e41958ec6..90ea50abde6 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee10/session/infinispan/InfinispanTestSupport.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/InfinispanTestSupport.java @@ -11,10 +11,11 @@ // ======================================================================== // -package org.eclipse.jetty.ee10.session.infinispan; +package org.eclipse.jetty.session.test.tools; import java.lang.annotation.ElementType; import java.nio.file.Path; +import java.util.Objects; import java.util.Properties; import org.eclipse.jetty.session.SessionData; @@ -33,21 +34,18 @@ import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.EmbeddedCacheManager; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * InfinispanTestSupport */ public class InfinispanTestSupport { - public static final String DEFAULT_CACHE_NAME = "session_test_cache"; - public Cache _cache; + public Cache _cache; public ConfigurationBuilder _builder; - private Path _tmpdir; private boolean _useFileStore; private boolean _serializeSessionData; - private String _name; + private final String _name; public static EmbeddedCacheManager _manager; static @@ -65,15 +63,9 @@ public class InfinispanTestSupport } } - public InfinispanTestSupport() - { - this(null); - } - public InfinispanTestSupport(String cacheName) { - if (cacheName == null) - cacheName = DEFAULT_CACHE_NAME + System.nanoTime(); + Objects.requireNonNull(cacheName, "cacheName cannot be null"); _name = cacheName; _builder = new ConfigurationBuilder(); @@ -89,7 +81,7 @@ public class InfinispanTestSupport _serializeSessionData = serializeSessionData; } - public Cache getCache() + public Cache getCache() { return _cache; } @@ -97,7 +89,7 @@ public class InfinispanTestSupport public void setup(Path root) throws Exception { Path indexesDir = root.resolve("indexes"); - this._tmpdir = root.resolve("tmp"); + Path tmpdir = root.resolve("tmp"); FS.ensureDirExists(indexesDir); SearchMapping mapping = new SearchMapping(); @@ -123,7 +115,7 @@ public class InfinispanTestSupport .persistence() .addSingleFileStore() .segmented(false) - .location(_tmpdir.toFile().getAbsolutePath()); + .location(tmpdir.toFile().getAbsolutePath()); if (_serializeSessionData) { b = b.memory().storage(StorageType.HEAP) @@ -150,14 +142,13 @@ public class InfinispanTestSupport _cache = _manager.getCache(_name); } - public void teardown() throws Exception + public void clearCache() throws Exception { _cache.clear(); _manager.administration().removeCache(_name); } - @SuppressWarnings("unchecked") - public void createSession(SessionData data) + public void createSession(InfinispanSessionData data) throws Exception { ((InfinispanSessionData)data).serializeAttributes(); @@ -184,41 +175,38 @@ public class InfinispanTestSupport _cache.evict(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); } - Object obj = _cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); + SessionData obj = _cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); if (obj == null) return false; - - SessionData saved = (SessionData)obj; - if (saved instanceof InfinispanSessionData) + if (obj instanceof InfinispanSessionData isd) { - InfinispanSessionData isd = (InfinispanSessionData)saved; if (isd.getSerializedAttributes() != null) isd.deserializeAttributes(); } //turn an Entity into a Session - assertEquals(data.getId(), saved.getId()); - assertEquals(data.getContextPath(), saved.getContextPath()); - assertEquals(data.getVhost(), saved.getVhost()); - assertEquals(data.getAccessed(), saved.getAccessed()); - assertEquals(data.getLastAccessed(), saved.getLastAccessed()); - assertEquals(data.getCreated(), saved.getCreated()); - assertEquals(data.getCookieSet(), saved.getCookieSet()); - assertEquals(data.getLastNode(), saved.getLastNode()); + assertEquals(data.getId(), obj.getId()); + assertEquals(data.getContextPath(), obj.getContextPath()); + assertEquals(data.getVhost(), obj.getVhost()); + assertEquals(data.getAccessed(), obj.getAccessed()); + assertEquals(data.getLastAccessed(), obj.getLastAccessed()); + assertEquals(data.getCreated(), obj.getCreated()); + assertEquals(data.getCookieSet(), obj.getCookieSet()); + assertEquals(data.getLastNode(), obj.getLastNode()); //don't test lastSaved, because that is set only on the SessionData after it returns from SessionDataStore.save() - assertEquals(data.getExpiry(), saved.getExpiry()); - assertEquals(data.getMaxInactiveMs(), saved.getMaxInactiveMs()); + assertEquals(data.getExpiry(), obj.getExpiry()); + assertEquals(data.getMaxInactiveMs(), obj.getMaxInactiveMs()); //same number of attributes - assertEquals(data.getAllAttributes().size(), saved.getAllAttributes().size()); + assertEquals(data.getAllAttributes().size(), obj.getAllAttributes().size()); //same keys - assertTrue(data.getKeys().equals(saved.getKeys())); + assertEquals(data.getKeys(), obj.getKeys()); //same values for (String name : data.getKeys()) { - assertTrue(data.getAttribute(name).equals(saved.getAttribute(name))); + assertEquals(data.getAttribute(name), obj.getAttribute(name)); } return true; diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/LoggingUtil.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/LoggingUtil.java similarity index 96% rename from jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/LoggingUtil.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/LoggingUtil.java index 39f738f9463..b6bdef1de86 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/LoggingUtil.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/LoggingUtil.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.session.infinispan; +package org.eclipse.jetty.session.test.tools; public final class LoggingUtil { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee9/session/memcached/MemcachedTestHelper.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/MemcachedTestHelper.java similarity index 96% rename from jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee9/session/memcached/MemcachedTestHelper.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/MemcachedTestHelper.java index 7ad23112e8b..a8500f8c5ff 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-memcached/src/test/java/org/eclipse/jetty/ee9/session/memcached/MemcachedTestHelper.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/MemcachedTestHelper.java @@ -11,13 +11,13 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.session.memcached; +package org.eclipse.jetty.session.test.tools; import java.net.InetSocketAddress; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -154,7 +154,7 @@ public class MemcachedTestHelper public static void shutdown() throws Exception { - memcached.stop(); + //memcached.stop(); } public static SessionDataStoreFactory newSessionDataStoreFactory() @@ -176,14 +176,14 @@ public class MemcachedTestHelper } MockDataStoreFactory storeFactory = new MockDataStoreFactory(); MemcachedSessionDataMapFactory mapFactory = new MemcachedSessionDataMapFactory(); - String host = memcached.getContainerIpAddress(); + String host = memcached.getHost(); int port = memcached.getMappedPort(11211); InetSocketAddress inetSocketAddress = new InetSocketAddress(host, port); mapFactory.setAddresses(inetSocketAddress); try { - XMemcachedClientBuilder builder = new XMemcachedClientBuilder(Arrays.asList(inetSocketAddress)); + XMemcachedClientBuilder builder = new XMemcachedClientBuilder(List.of(inetSocketAddress)); builder.build().flushAll(); } catch (Exception e) diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/MongoTestHelper.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/MongoTestHelper.java similarity index 85% rename from jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/MongoTestHelper.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/MongoTestHelper.java index b4337832dd9..525859be766 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee9/session/nosql/mongodb/MongoTestHelper.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/MongoTestHelper.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.session.nosql.mongodb; +package org.eclipse.jetty.session.test.tools; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -48,20 +48,26 @@ public class MongoTestHelper private static final Logger LOG = LoggerFactory.getLogger(MongoTestHelper.class); private static final Logger MONGO_LOG = LoggerFactory.getLogger("org.eclipse.jetty.nosql.mongodb.MongoLogs"); - public static final String DB_NAME = "HttpSessions"; - public static final String COLLECTION_NAME = "testsessions"; - private static final int MONGO_PORT = 27017; - static MongoDBContainer mongo = - new MongoDBContainer(DockerImageName.parse("mongo:" + System.getProperty("mongo.docker.version", "3.2.20"))) - .withLogConsumer(new Slf4jLogConsumer(MONGO_LOG)); - + static MongoDBContainer mongo; static MongoClient mongoClient; - static String mongoHost; static int mongoPort; + static + { + mongo = new MongoDBContainer(DockerImageName.parse("mongo:" + System.getProperty("mongo.docker.version", "3.2.20"))) + .withLogConsumer(new Slf4jLogConsumer(MONGO_LOG)); + long start = System.currentTimeMillis(); + mongo.start(); + mongoHost = mongo.getHost(); + mongoPort = mongo.getMappedPort(MONGO_PORT); + LOG.info("Mongo container started for {}:{} - {}ms", mongoHost, mongoPort, + System.currentTimeMillis() - start); + mongoClient = new MongoClient(mongoHost, mongoPort); + } + public static MongoClient getMongoClient() throws UnknownHostException { if (mongoClient == null) @@ -71,59 +77,40 @@ public class MongoTestHelper return mongoClient; } - public static void dropCollection() throws Exception + public static void dropCollection(String dbName, String collectionName) throws Exception { - getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME).drop(); + getMongoClient().getDB(dbName).getCollection(collectionName).drop(); } public static void shutdown() throws Exception { - mongo.stop(); + //mongo.stop(); } - public static void createCollection() throws UnknownHostException, MongoException + public static void createCollection(String dbName, String collectionName) throws UnknownHostException, MongoException { - getMongoClient().getDB(DB_NAME).createCollection(COLLECTION_NAME, null); + getMongoClient().getDB(dbName).createCollection(collectionName, null); } - public static DBCollection getCollection() throws UnknownHostException, MongoException + public static DBCollection getCollection(String dbName, String collectionName) throws UnknownHostException, MongoException { - return getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); + return getMongoClient().getDB(dbName).getCollection(collectionName); } - public static MongoSessionDataStoreFactory newSessionDataStoreFactory() + public static MongoSessionDataStoreFactory newSessionDataStoreFactory(String dbName, String collectionName) { - if (!mongo.isRunning()) - { - try - { - long start = System.currentTimeMillis(); - mongo.start(); - mongoHost = mongo.getHost(); - mongoPort = mongo.getMappedPort(MONGO_PORT); - LOG.info("Mongo container started for {}:{} - {}ms", mongoHost, mongoPort, - System.currentTimeMillis() - start); - mongoClient = new MongoClient(mongoHost, mongoPort); - } - catch (Exception e) - { - LOG.error(e.getMessage(), e); - throw new RuntimeException(e); - } - } - MongoSessionDataStoreFactory storeFactory = new MongoSessionDataStoreFactory(); storeFactory.setHost(mongoHost); storeFactory.setPort(mongoPort); - storeFactory.setCollectionName(COLLECTION_NAME); - storeFactory.setDbName(DB_NAME); + storeFactory.setCollectionName(collectionName); + storeFactory.setDbName(dbName); return storeFactory; } - public static boolean checkSessionExists(String id) + public static boolean checkSessionExists(String id, String dbName, String collectionName) throws Exception { - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(dbName).getCollection(collectionName); DBObject fields = new BasicDBObject(); fields.put(MongoSessionDataStore.__EXPIRY, 1); @@ -137,10 +124,10 @@ public class MongoTestHelper return true; } - public static boolean checkSessionPersisted(SessionData data) + public static boolean checkSessionPersisted(SessionData data, String dbName, String collectionName) throws Exception { - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(dbName).getCollection(collectionName); DBObject fields = new BasicDBObject(); @@ -211,10 +198,11 @@ public class MongoTestHelper public static void createUnreadableSession(String id, String contextPath, String vhost, String lastNode, long created, long accessed, long lastAccessed, long maxIdle, long expiry, - Map attributes) + Map attributes, String dbName, + String collectionName) throws Exception { - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(dbName).getCollection(collectionName); // Form query for upsert BasicDBObject key = new BasicDBObject(MongoSessionDataStore.__ID, id); @@ -259,11 +247,12 @@ public class MongoTestHelper public static void createSession(String id, String contextPath, String vhost, String lastNode, long created, long accessed, long lastAccessed, long maxIdle, long expiry, - Map attributes) + Map attributes, String dbName, + String collectionName) throws Exception { - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(dbName).getCollection(collectionName); // Form query for upsert BasicDBObject key = new BasicDBObject(MongoSessionDataStore.__ID, id); @@ -291,7 +280,7 @@ public class MongoTestHelper { SessionData tmp = new SessionData(id, contextPath, vhost, created, accessed, lastAccessed, maxIdle, attributes); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos);) + ObjectOutputStream oos = new ObjectOutputStream(baos)) { SessionData.serializeAttributes(tmp, oos); sets.put(MongoSessionDataStore.__CONTEXT + "." + vhost.replace('.', '_') + ":" + contextPath + "." + MongoSessionDataStore.__ATTRIBUTES, baos.toByteArray()); @@ -305,11 +294,12 @@ public class MongoTestHelper public static void createLegacySession(String id, String contextPath, String vhost, String lastNode, long created, long accessed, long lastAccessed, long maxIdle, long expiry, - Map attributes) + Map attributes, String dbName, + String collectionName) throws Exception { //make old-style session to test if we can retrieve it - DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(dbName).getCollection(collectionName); // Form query for upsert BasicDBObject key = new BasicDBObject(MongoSessionDataStore.__ID, id); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteInfinispanTestSupport.java b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/RemoteInfinispanTestSupport.java similarity index 71% rename from jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteInfinispanTestSupport.java rename to tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/RemoteInfinispanTestSupport.java index 39c7e9980de..7455c221924 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-infinispan/src/test/java/org/eclipse/jetty/ee9/session/infinispan/remote/RemoteInfinispanTestSupport.java +++ b/tests/jetty-test-session-common/src/main/java/org/eclipse/jetty/session/test/tools/RemoteInfinispanTestSupport.java @@ -11,17 +11,20 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.session.infinispan.remote; +package org.eclipse.jetty.session.test.tools; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InputStream; import java.lang.annotation.ElementType; import java.nio.charset.StandardCharsets; +import java.util.Objects; import java.util.Properties; import org.eclipse.jetty.session.SessionData; import org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer; import org.eclipse.jetty.session.infinispan.InfinispanSessionData; +import org.eclipse.jetty.session.infinispan.SessionDataMarshaller; import org.eclipse.jetty.util.IO; import org.hibernate.search.cfg.Environment; import org.hibernate.search.cfg.SearchMapping; @@ -40,7 +43,6 @@ import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * RemoteInfinispanTestSupport @@ -48,62 +50,34 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class RemoteInfinispanTestSupport { private static final Logger LOG = LoggerFactory.getLogger(RemoteInfinispanTestSupport.class); - public static final String DEFAULT_CACHE_NAME = "session_test_cache"; public RemoteCache _cache; private final String _name; - public RemoteCacheManager _manager; + public static RemoteCacheManager _manager; private static final Logger INFINISPAN_LOG = LoggerFactory.getLogger("org.eclipse.jetty.server.session.remote.infinispanLogs"); + private static final String INFINISPAN_VERSION = System.getProperty("infinispan.docker.image.version", "11.0.14.Final"); private static final String IMAGE_NAME = System.getProperty("infinispan.docker.image.name", "infinispan/server") + - ":" + System.getProperty("infinispan.docker.image.version", "11.0.9.Final"); + ":" + INFINISPAN_VERSION; - private final GenericContainer infinispan = new GenericContainer(IMAGE_NAME) - .withEnv("USER", "theuser") - .withEnv("PASS", "foobar") - .withEnv("MGMT_USER", "admin") - .withEnv("MGMT_PASS", "admin") - .withEnv("CONFIG_PATH", "/user-config/config.yaml") - .waitingFor(Wait.forLogMessage(".*Infinispan Server.*started in.*\\s", 1)) - .withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224) - .withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG)) - .withClasspathResourceMapping("/config.yaml", "/user-config/config.yaml", BindMode.READ_ONLY); - private static final String INFINISPAN_VERSION = System.getProperty("infinispan.docker.image.version", "11.0.9.Final"); + private static final GenericContainer infinispan = new GenericContainer<>(IMAGE_NAME); - public RemoteInfinispanTestSupport() + static { - this(null); - } + infinispan.withEnv("USER", "theuser") + .withEnv("PASS", "foobar") + .withEnv("MGMT_USER", "admin") + .withEnv("MGMT_PASS", "admin") + .withEnv("CONFIG_PATH", "/user-config/config.yaml") + .waitingFor(Wait.forLogMessage(".*Infinispan Server.*started in.*\\s", 1)) + .withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224) + .withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG)) + .withClasspathResourceMapping("/config.yaml", "/user-config/config.yaml", BindMode.READ_ONLY) + .start(); - public RemoteInfinispanTestSupport(String cacheName) - { - if (cacheName == null) - cacheName = DEFAULT_CACHE_NAME + System.nanoTime(); - - _name = cacheName; - - if (!infinispan.isRunning()) + // setup instance { - try - { - long start = System.currentTimeMillis(); - infinispan.start(); - System.setProperty("hotrod.host", infinispan.getContainerIpAddress()); - - LOG.info("Infinispan container started for {}:{} - {}ms", - infinispan.getContainerIpAddress(), - infinispan.getMappedPort(11222), - System.currentTimeMillis() - start); - } - catch (Exception e) - { - LOG.error(e.getMessage(), e); - throw new RuntimeException(e); - } - } - try - { SearchMapping mapping = new SearchMapping(); mapping.entity(InfinispanSessionData.class).indexed().providedId() .property("expiry", ElementType.METHOD).field(); @@ -113,7 +87,7 @@ public class RemoteInfinispanTestSupport ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().withProperties(properties) .addServer() - .host(infinispan.getContainerIpAddress()) + .host(infinispan.getHost()) .port(infinispan.getMappedPort(11222)) // we just want to limit connectivity to list of host:port we knows at start // as infinispan create new host:port dynamically but due to how docker expose host/port we cannot do that @@ -134,7 +108,7 @@ public class RemoteInfinispanTestSupport //upload the session.proto file to the remote cache ByteArrayOutputStream baos; - try (InputStream is = RemoteInfinispanSessionDataStoreTest.class.getClassLoader().getResourceAsStream("session.proto")) + try (InputStream is = SessionDataMarshaller.class.getClassLoader().getResourceAsStream("session.proto")) { if (is == null) throw new IllegalStateException("inputstream is null"); @@ -142,25 +116,22 @@ public class RemoteInfinispanTestSupport baos = new ByteArrayOutputStream(); IO.copy(is, baos); } + catch (IOException e) + { + throw new RuntimeException(e.getMessage(), e); + } String content = baos.toString(StandardCharsets.UTF_8); _manager.administration().getOrCreateCache("___protobuf_metadata", (String)null).put("session.proto", content); - } - catch (Exception e) - { - LOG.error(e.getMessage(), e); - throw new RuntimeException(e); + } } - public RemoteCache getCache() - { - return _cache; - } - - public void setup() throws Exception + public RemoteInfinispanTestSupport(String cacheName) { + Objects.requireNonNull(cacheName, "cacheName cannot be null"); + _name = cacheName; String xml = String.format("" + "" + "" + "" + @@ -172,18 +143,23 @@ public class RemoteInfinispanTestSupport _cache = _manager.administration().getOrCreateCache(_name, xmlConfig); } - public void teardown() throws Exception + public RemoteCache getCache() + { + return _cache; + } + + public void setup() throws Exception + { + // noop + } + + public void clearCache() throws Exception { _cache.clear(); } - public void shutdown() throws Exception - { - infinispan.stop(); - } - public void createSession(InfinispanSessionData data) - throws Exception + throws Exception { data.serializeAttributes(); _cache.put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data); @@ -195,19 +171,19 @@ public class RemoteInfinispanTestSupport } public boolean checkSessionExists(InfinispanSessionData data) - throws Exception + throws Exception { return (_cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()) != null); } public boolean checkSessionPersisted(SessionData data) - throws Exception + throws Exception { - Object obj = _cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); + InfinispanSessionData obj = _cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); if (obj == null) return false; - InfinispanSessionData saved = (InfinispanSessionData)obj; + InfinispanSessionData saved = obj; if (saved.getSerializedAttributes() != null) saved.deserializeAttributes(); @@ -226,11 +202,11 @@ public class RemoteInfinispanTestSupport //same number of attributes assertEquals(data.getAllAttributes().size(), saved.getAllAttributes().size()); //same keys - assertTrue(data.getKeys().equals(saved.getKeys())); + assertEquals(data.getKeys(), saved.getKeys()); //same values for (String name : data.getKeys()) { - assertTrue(data.getAttribute(name).equals(saved.getAttribute(name))); + assertEquals(data.getAttribute(name), saved.getAttribute(name)); } return true; diff --git a/tests/pom.xml b/tests/pom.xml index 2a188054d58..170fe36b7bb 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -21,6 +21,7 @@ jetty-jmh test-distribution test-integration + jetty-test-session-common diff --git a/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/session/InfinispanSessionDistributionTests.java b/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/session/InfinispanSessionDistributionTests.java index 2a03a408851..45949b87bbc 100644 --- a/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/session/InfinispanSessionDistributionTests.java +++ b/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/session/InfinispanSessionDistributionTests.java @@ -57,7 +57,7 @@ public class InfinispanSessionDistributionTests extends AbstractSessionDistribut @Override public void startExternalSessionStorage() throws Exception { - String infinispanVersion = System.getProperty("infinispan.docker.image.version", "11.0.9.Final"); + String infinispanVersion = System.getProperty("infinispan.docker.image.version", "11.0.14.Final"); infinispan = new GenericContainer(System.getProperty("infinispan.docker.image.name", "infinispan/server") + ":" + infinispanVersion)