Remove duplicated classes from test session, fix some to be able to run in parallel and not restarting 3rd party for each tests (#9782)
--------- Signed-off-by: Olivier Lamy <olamy@apache.org>
This commit is contained in:
parent
c2dc87c039
commit
a617784e8e
|
@ -109,6 +109,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
|
||||
//create the SessionDataStore
|
||||
_sessionIdManager = new DefaultSessionIdManager(_server);
|
||||
_sessionIdManager.setWorkerName("");
|
||||
_server.addBean(_sessionIdManager, true);
|
||||
|
||||
_sessionManager = new TestableSessionManager();
|
||||
|
|
|
@ -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<String> getSessionIds()
|
||||
public static Set<String> getSessionIds(String sessionTableName)
|
||||
throws Exception
|
||||
{
|
||||
HashSet<String> 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())
|
||||
{
|
||||
|
|
|
@ -63,5 +63,9 @@
|
|||
<artifactId>awaitility</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -68,5 +68,10 @@
|
|||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,36 +10,9 @@
|
|||
<name>EE10 :: Tests :: Sessions :: Hazelcast</name>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.sessions.hazelcast</bundle-symbolic-name>
|
||||
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>unpack</id>
|
||||
<phase>generate-test-resources</phase>
|
||||
<goals>
|
||||
<goal>unpack</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-policy</artifactId>
|
||||
<version>${jetty-test-policy.version}</version>
|
||||
<type>jar</type>
|
||||
<overWrite>true</overWrite>
|
||||
<includes>**/*.keystore,**/*.pem</includes>
|
||||
<outputDirectory>${jetty.test.policy.loc}</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
|
@ -120,6 +93,11 @@
|
|||
<artifactId>jetty-slf4j-impl</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -9,10 +9,7 @@
|
|||
<artifactId>jetty-ee10-test-sessions-infinispan</artifactId>
|
||||
<name>EE10 :: Tests :: Sessions :: Infinispan</name>
|
||||
<properties>
|
||||
<junit.jupiter.execution.parallel.enabled>true</junit.jupiter.execution.parallel.enabled>
|
||||
<bundle-symbolic-name>${project.groupId}.sessions.infinispan</bundle-symbolic-name>
|
||||
<!-- if changing this version please update default in RemoteInfinispanTestSupport you will get thanks from Eclipse IDE users -->
|
||||
<infinispan.docker.image.version>11.0.9.Final</infinispan.docker.image.version>
|
||||
<!-- from 10.xx it has changed to jboss/infinispan -->
|
||||
<infinispan.docker.image.name>infinispan/server</infinispan.docker.image.name>
|
||||
</properties>
|
||||
|
@ -32,32 +29,6 @@
|
|||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>unpack</id>
|
||||
<phase>generate-test-resources</phase>
|
||||
<goals>
|
||||
<goal>unpack</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-policy</artifactId>
|
||||
<version>${jetty-test-policy.version}</version>
|
||||
<type>jar</type>
|
||||
<overWrite>true</overWrite>
|
||||
<includes>**/*.keystore,**/*.pem</includes>
|
||||
<outputDirectory>${jetty.test.policy.loc}</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
|
@ -113,10 +84,10 @@
|
|||
<artifactId>infinispan-core</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.wildfly.common</groupId>
|
||||
<artifactId>wildfly-common</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.wildfly.common</groupId>
|
||||
<artifactId>wildfly-common</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -170,6 +141,11 @@
|
|||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<profiles>
|
||||
<profile>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<InfinispanSessionData> query = qf.create("from org_eclipse_jetty_session_infinispan.InfinispanSessionData where " +
|
||||
" expiry < :time");
|
||||
|
||||
|
|
|
@ -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<String, InfinispanSessionData> _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<String, InfinispanSessionData> getCache()
|
||||
{
|
||||
return _cache;
|
||||
}
|
||||
|
||||
public void setup() throws Exception
|
||||
{
|
||||
String xml = String.format("<infinispan>" +
|
||||
"<cache-container>" + "<distributed-cache name=\"%s\" mode=\"SYNC\">" +
|
||||
"<encoding media-type=\"application/x-protostream\"/>" +
|
||||
"</distributed-cache>" +
|
||||
"</cache-container>" +
|
||||
"</infinispan>", _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;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,6 @@
|
|||
<artifactId>jetty-ee10-test-sessions-jdbc</artifactId>
|
||||
<name>EE10 :: Tests :: Sessions :: JDBC</name>
|
||||
<properties>
|
||||
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
|
||||
<bundle-symbolic-name>${project.groupId}.sessions.jdbc</bundle-symbolic-name>
|
||||
</properties>
|
||||
<build>
|
||||
|
@ -92,5 +91,10 @@
|
|||
<artifactId>mariadb-java-client</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,5 +57,10 @@
|
|||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<String, SessionData> _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<String> doCheckExpired(Set<String> candidates, long time)
|
||||
{
|
||||
Set<String> 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<String> 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;
|
||||
}
|
||||
}
|
|
@ -9,9 +9,7 @@
|
|||
<artifactId>jetty-ee10-test-sessions-mongodb</artifactId>
|
||||
<name>EE10 :: Tests :: Sessions :: Mongo</name>
|
||||
<properties>
|
||||
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
|
||||
<bundle-symbolic-name>${project.groupId}.sessions.mongo</bundle-symbolic-name>
|
||||
<embedmongo.host>localhost</embedmongo.host>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -24,32 +22,6 @@
|
|||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>unpack</id>
|
||||
<phase>generate-test-resources</phase>
|
||||
<goals>
|
||||
<goal>unpack</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-policy</artifactId>
|
||||
<version>${jetty-test-policy.version}</version>
|
||||
<type>jar</type>
|
||||
<overWrite>true</overWrite>
|
||||
<includes>**/*.keystore,**/*.pem</includes>
|
||||
<outputDirectory>${jetty.test.policy.loc}</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
|
@ -125,5 +97,10 @@
|
|||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, Object> 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<String, Object> 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<String, Object> 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);
|
||||
}
|
||||
}
|
|
@ -63,5 +63,9 @@
|
|||
<artifactId>awaitility</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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<String, SessionData> _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<String> doCheckExpired(Set<String> candidates, long time)
|
||||
{
|
||||
HashSet<String> 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<String> doGetExpired(long timeLimit)
|
||||
{
|
||||
Set<String> 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
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -68,5 +68,10 @@
|
|||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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<String, Object> 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<Entity> query = Query.newEntityQueryBuilder()
|
||||
.setKind(EntityDataModel.KIND)
|
||||
.setFilter(PropertyFilter.eq(EntityDataModel.ID, id))
|
||||
.build();
|
||||
|
||||
QueryResults<Entity> results = _ds.run(query);
|
||||
|
||||
if (results.hasNext())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<String> getSessionIds() throws Exception
|
||||
{
|
||||
HashSet<String> ids = new HashSet<String>();
|
||||
GqlQuery.Builder builder = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + GCloudSessionDataStore.EntityDataModel.KIND);
|
||||
|
||||
Query<Entity> query = builder.build();
|
||||
|
||||
QueryResults<Entity> 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<Entity> query = builder.build();
|
||||
|
||||
QueryResults<Entity> 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<Key> query = Query.newKeyQueryBuilder().setKind(GCloudSessionDataStore.EntityDataModel.KIND).build();
|
||||
QueryResults<Key> results = _ds.run(query);
|
||||
assertNotNull(results);
|
||||
int actual = 0;
|
||||
List<Key> 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<Key> query = Query.newKeyQueryBuilder().setKind(GCloudSessionDataStore.EntityDataModel.KIND).build();
|
||||
QueryResults<Key> results = _ds.run(query);
|
||||
|
||||
Batch batch = _ds.newBatch();
|
||||
|
||||
if (results != null)
|
||||
{
|
||||
List<Key> keys = new ArrayList<>();
|
||||
|
||||
while (results.hasNext())
|
||||
{
|
||||
keys.add(results.next());
|
||||
}
|
||||
|
||||
batch.delete(keys.toArray(new Key[keys.size()]));
|
||||
}
|
||||
|
||||
batch.submit();
|
||||
assertSessions(0);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,37 +9,10 @@
|
|||
<artifactId>jetty-ee9-test-sessions-hazelcast</artifactId>
|
||||
<name>EE9 :: Tests :: Sessions :: Hazelcast</name>
|
||||
<properties>
|
||||
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
|
||||
<bundle-symbolic-name>${project.groupId}.sessions.hazelcast</bundle-symbolic-name>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>unpack</id>
|
||||
<phase>generate-test-resources</phase>
|
||||
<goals>
|
||||
<goal>unpack</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-policy</artifactId>
|
||||
<version>${jetty-test-policy.version}</version>
|
||||
<type>jar</type>
|
||||
<overWrite>true</overWrite>
|
||||
<includes>**/*.keystore,**/*.pem</includes>
|
||||
<outputDirectory>${jetty.test.policy.loc}</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
|
@ -121,6 +94,11 @@
|
|||
<artifactId>jetty-slf4j-impl</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-test-session-common</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue