WIP moving session tests to ee9

This commit is contained in:
Jan Bartel 2022-05-04 18:41:12 +02:00
parent c9a9a1a775
commit 34809d7cf7
20 changed files with 118 additions and 27 deletions

View File

@ -277,6 +277,17 @@
<artifactId>jetty-server</artifactId>
<version>12.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-session</artifactId>
<version>12.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-session</artifactId>
<version>12.0.0-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>

View File

@ -12,9 +12,9 @@
<packaging>pom</packaging>
<modules>
<module>test-ee9-sessions-common</module>
<!-- module>test-ee9-file-sessions</module -->
<!-- module>test-ee9-jdbc-sessions</module -->
<!-- module>test-ee9-mongodb-sessions</module -->
<module>test-ee9-file-sessions</module>
<module>test-ee9-jdbc-sessions</module>
<module>test-ee9-mongodb-sessions</module>
<!-- module>test-ee9-infinispan-sessions</module -->
<!-- module>test-ee9-gcloud-sessions</module -->
<!-- module>test-ee9-memcached-sessions</module -->

View File

@ -3,8 +3,9 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9</artifactId>
<artifactId>test-ee9-sessions</artifactId>
<version>12.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>test-ee9-file-sessions</artifactId>
<name>Jetty EE9 Tests :: Sessions :: File</name>
@ -29,6 +30,12 @@
<artifactId>jetty-session</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-session</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>

View File

@ -17,9 +17,11 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import org.eclipse.jetty.ee9.session.AbstractClusteredOrphanedSessionTest;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -28,6 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* ClusteredOrphanedSessionTest
*/
//TODO
@Disabled
@ExtendWith(WorkDirExtension.class)
public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest
{

View File

@ -5,6 +5,7 @@
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>test-ee9-sessions</artifactId>
<version>12.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>test-ee9-jdbc-sessions</artifactId>
<name>Jetty EE9 Tests :: Sessions :: JDBC</name>
@ -38,6 +39,17 @@
<artifactId>jetty-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-session</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-session</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>

View File

@ -13,12 +13,16 @@
package org.eclipse.jetty.session;
import org.eclipse.jetty.ee9.session.AbstractClusteredInvalidationSessionTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.testcontainers.junit.jupiter.Testcontainers;
/**
* ClusteredInvalidationSessionTest
*/
//TODO
@Disabled
@Testcontainers(disabledWithoutDocker = true)
public class ClusteredInvalidationSessionTest extends AbstractClusteredInvalidationSessionTest
{

View File

@ -13,12 +13,16 @@
package org.eclipse.jetty.session;
import org.eclipse.jetty.ee9.session.AbstractClusteredOrphanedSessionTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.testcontainers.junit.jupiter.Testcontainers;
/**
* ClusteredOrphanedSessionTest
*/
//TODO
@Disabled
@Testcontainers(disabledWithoutDocker = true)
public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest
{

View File

@ -23,7 +23,10 @@ import jakarta.servlet.http.HttpSession;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.ee9.session.AbstractSessionTestBase;
import org.eclipse.jetty.ee9.session.SessionTestSupport;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.session.DefaultSessionCacheFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;

View File

@ -13,12 +13,16 @@
package org.eclipse.jetty.session;
import org.eclipse.jetty.ee9.session.AbstractClusteredSessionScavengingTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.testcontainers.junit.jupiter.Testcontainers;
/**
* ClusteredSessionScavengingTest
*/
//TODO
@Disabled
@Testcontainers(disabledWithoutDocker = true)
public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest
{

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.session;
import org.eclipse.jetty.session.AbstractSessionDataStoreTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -30,7 +31,7 @@ public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest
}
@BeforeEach
public void setUp() throws Exception
public void configure() throws Exception
{
JdbcTestHelper.prepareTables();
}

View File

@ -26,6 +26,8 @@ import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jetty.session.SessionData;
import org.eclipse.jetty.session.SessionDataStoreFactory;
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -22,6 +22,7 @@ import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.ee9.session.SessionTestSupport;
import org.eclipse.jetty.ee9.webapp.WebAppContext;
import org.eclipse.jetty.logging.StacklessLogging;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
@ -29,6 +30,7 @@ import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.resource.Resource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testcontainers.junit.jupiter.Testcontainers;
@ -38,9 +40,12 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* ReloadedSessionMissingClassTest
*/
//TODO
@Disabled
@ExtendWith(WorkDirExtension.class)
@Testcontainers(disabledWithoutDocker = true)
public class ReloadedSessionMissingClassTest

View File

@ -18,7 +18,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.ee9.servlet.ServletContextHandler;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -120,9 +121,10 @@ public class SessionTableSchemaTest
try (Connection con = _da.getConnection())
{
//make a root context
ContextHandler handler = new ContextHandler();
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.getSessionHandler().getSessionManager().setSessionIdManager(new DefaultSessionIdManager(new Server()));
handler.setContextPath("/");
SessionContext sc = new SessionContext("0", handler.getServletContext());
SessionContext sc = new SessionContext(handler.getSessionHandler().getSessionManager());
//test the load statement
PreparedStatement s = _tableSchema.getLoadStatement(con, id, sc);
ResultSet rs = s.executeQuery();
@ -146,9 +148,10 @@ public class SessionTableSchemaTest
//test if it can be seen
try (Connection con = _da.getConnection())
{
ContextHandler handler = new ContextHandler();
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.getSessionHandler().getSessionManager().setSessionIdManager(new DefaultSessionIdManager(new Server()));
handler.setContextPath("/");
SessionContext sc = new SessionContext("0", handler.getServletContext());
SessionContext sc = new SessionContext(handler.getSessionHandler().getSessionManager());
PreparedStatement s = _tableSchema.getCheckSessionExistsStatement(con, sc);
s.setString(1, id);
ResultSet rs = s.executeQuery();
@ -172,9 +175,10 @@ public class SessionTableSchemaTest
//test if it can be deleted
try (Connection con = _da.getConnection())
{
ContextHandler handler = new ContextHandler();
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.getSessionHandler().getSessionManager().setSessionIdManager(new DefaultSessionIdManager(new Server()));
handler.setContextPath("/");
SessionContext sc = new SessionContext("0", handler.getServletContext());
SessionContext sc = new SessionContext(handler.getSessionHandler().getSessionManager());
PreparedStatement s = _tableSchema.getDeleteStatement(con, id, sc);
assertEquals(1, s.executeUpdate());
@ -197,9 +201,10 @@ public class SessionTableSchemaTest
try (Connection con = _da.getConnection())
{
ContextHandler handler = new ContextHandler();
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.getSessionHandler().getSessionManager().setSessionIdManager(new DefaultSessionIdManager(new Server()));
handler.setContextPath("/");
SessionContext sc = new SessionContext("0", handler.getServletContext());
SessionContext sc = new SessionContext(handler.getSessionHandler().getSessionManager());
PreparedStatement s = _tableSchema.getExpiredSessionsStatement(con,
sc.getCanonicalContextPath(),
sc.getVhost(),
@ -225,9 +230,12 @@ public class SessionTableSchemaTest
try (Connection con = _da.getConnection())
{
ContextHandler handler = new ContextHandler();
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
DefaultSessionIdManager idMgr = new DefaultSessionIdManager(new Server());
idMgr.setWorkerName("0");
handler.getSessionHandler().getSessionManager().setSessionIdManager(idMgr);
handler.setContextPath("/");
SessionContext sc = new SessionContext("0", handler.getServletContext());
SessionContext sc = new SessionContext(handler.getSessionHandler().getSessionManager());
PreparedStatement s = _tableSchema.getMyExpiredSessionsStatement(con,
sc,
(System.currentTimeMillis() + 100L));
@ -252,9 +260,10 @@ public class SessionTableSchemaTest
try (Connection con = _da.getConnection())
{
ContextHandler handler = new ContextHandler();
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.getSessionHandler().getSessionManager().setSessionIdManager(new DefaultSessionIdManager(new Server()));
handler.setContextPath("/");
SessionContext sc = new SessionContext("0", handler.getServletContext());
SessionContext sc = new SessionContext(handler.getSessionHandler().getSessionManager());
PreparedStatement s = _tableSchema.getUpdateStatement(con,
id,
sc);

View File

@ -13,14 +13,18 @@
package org.eclipse.jetty.session;
import org.eclipse.jetty.ee9.session.AbstractWebAppObjectInSessionTest;
import org.eclipse.jetty.util.resource.Resource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;
/**
* WebAppObjectInSessionTest
*/
//TODO
@Disabled
@Testcontainers(disabledWithoutDocker = true)
public class WebAppObjectInSessionTest extends AbstractWebAppObjectInSessionTest
{

View File

@ -66,6 +66,12 @@
<artifactId>jetty-session</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-session</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>

View File

@ -20,15 +20,16 @@ import java.util.concurrent.TimeUnit;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.ee9.session.SessionTestSupport;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.session.DefaultSessionCacheFactory;
import org.eclipse.jetty.session.Session;
import org.eclipse.jetty.session.SessionCache;
import org.eclipse.jetty.session.SessionTestSupport;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -136,20 +137,20 @@ public class AttributeNameTest
String action = request.getParameter("action");
if ("init".equals(action))
{
Session session = (Session)request.getSession(true);
HttpSession session = request.getSession(true);
session.setAttribute("a.b.c", TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
sendResult(session, httpServletResponse.getWriter());
}
else
{
Session session = (Session)request.getSession(false);
HttpSession session = request.getSession(false);
assertNotNull(session);
assertNotNull(session.getAttribute("a.b.c"));
sendResult(session, httpServletResponse.getWriter());
}
}
private void sendResult(Session session, PrintWriter writer)
private void sendResult(HttpSession session, PrintWriter writer)
{
if (session != null)
{

View File

@ -13,12 +13,15 @@
package org.eclipse.jetty.nosql.mongodb;
import org.eclipse.jetty.session.AbstractClusteredInvalidationSessionTest;
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.junit.jupiter.api.Disabled;
import org.testcontainers.junit.jupiter.Testcontainers;
//TODO
@Disabled
@Testcontainers(disabledWithoutDocker = true)
public class ClusteredInvalidateSessionTest extends AbstractClusteredInvalidationSessionTest
{

View File

@ -13,16 +13,19 @@
package org.eclipse.jetty.nosql.mongodb;
import org.eclipse.jetty.session.AbstractClusteredOrphanedSessionTest;
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.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;
/**
* ClusteredOrphanedSessionTest
*/
//TODO
@Disabled
@Testcontainers(disabledWithoutDocker = true)
public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest
{

View File

@ -13,12 +13,15 @@
package org.eclipse.jetty.nosql.mongodb;
import org.eclipse.jetty.session.AbstractClusteredSessionScavengingTest;
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.junit.jupiter.api.Disabled;
import org.testcontainers.junit.jupiter.Testcontainers;
//TODO
@Disabled
@Testcontainers(disabledWithoutDocker = true)
public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest
{

View File

@ -19,8 +19,10 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.jetty.ee9.servlet.ServletContextHandler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.session.AbstractSessionDataStoreFactory;
import org.eclipse.jetty.session.AbstractSessionDataStoreTest;
import org.eclipse.jetty.session.DefaultSessionIdManager;
import org.eclipse.jetty.session.SessionContext;
import org.eclipse.jetty.session.SessionData;
import org.eclipse.jetty.session.SessionDataStore;
@ -111,13 +113,16 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest
@Test
public void testReadLegacySession() throws Exception
{
DefaultSessionIdManager idMgr = new DefaultSessionIdManager(new Server());
//create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/legacy");
context.getSessionHandler().getSessionManager().setSessionIdManager(idMgr);
SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
SessionContext sessionContext = new SessionContext("foo", context.getServletContext());
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler().getSessionManager());
SessionContext sessionContext = new SessionContext(context.getSessionHandler().getSessionManager());
store.initialize(sessionContext);
//persist an old-style session