Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x
Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
commit
b8c7a9509a
28
VERSION.txt
28
VERSION.txt
|
@ -1,5 +1,31 @@
|
|||
jetty-10.0.0-SNAPSHOT
|
||||
|
||||
jetty-9.4.29.v20200521 - 21 May 2020
|
||||
+ 2188 Lock contention creating HTTP/2 streams
|
||||
+ 4235 communicate the reason of failure to the OpenID error page
|
||||
+ 4695 HttpChannel recycling in h2
|
||||
+ 4764 HTTP2 Jetty Server does not send back content-length
|
||||
+ 4778 Enforcing SNI when there are only non-wildcards certificates
|
||||
+ 4787 Make org.eclipse.jetty.client.HttpRequest's host name writable
|
||||
+ 4789 org.eclipse.jetty.util.thread.ShutdownThread should use an appropriate
|
||||
name to identify itself in Thread dump
|
||||
+ 4798 Better handling of fatal Selector failures
|
||||
+ 4814 Allow a ConnectionFactory (eg SslConnectionFactory) to automatically
|
||||
add a Customizer
|
||||
+ 4820 Jetty OSGi DefaultJettyAtJettyHomeHelper refers to non-existent
|
||||
config file
|
||||
+ 4824 WebSocket server outgoing message queue memory growth
|
||||
+ 4828 NIO ByteBuffer corruption in embedded Jetty server
|
||||
+ 4835 GzipHandler and GzipHttpOutputInterceptor do not flush response when
|
||||
body is empty
|
||||
+ 4860 org.eclipse.jetty.server.HttpChannel busyloop on HttpFields
|
||||
NullPointerException
|
||||
+ 4861 Combine `AttributesMap` and `Attributes.Wrapper`
|
||||
+ 4868 Update to asm 7.3.1
|
||||
+ 4892 Non-blocking JSON parser
|
||||
+ 4895 AbstractSessionCache.setFlushOnResponseCommit(true) can write an
|
||||
invalid session to the backing store
|
||||
|
||||
jetty-10.0.0.alpha1 - 26 November 2019
|
||||
+ 97 Permanent UnavailableException thrown during servlet request handling
|
||||
should cause servlet destroy
|
||||
|
@ -363,7 +389,7 @@ jetty-9.4.28.v20200408 - 08 April 2020
|
|||
+ 4529 ErrorHandler showing servlet info, can not be disabled unless
|
||||
overriding most of its functionality
|
||||
+ 4542 servlet context root mapping incorrect
|
||||
+ 4619 Inconsistent library versions notice.
|
||||
+ 4619 Inconsistent library versions notice
|
||||
+ 4620 Using console-capture with StdErrLog results in empty log file
|
||||
+ 4621 jetty-jaspi in jetty-all uber aggregate artifact requires
|
||||
javax.security.auth.message.AuthException which cannot be included
|
||||
|
|
|
@ -173,11 +173,23 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Handlers handlers = _handlers.get();
|
||||
if (handlers == null)
|
||||
Mapping mapping = (Mapping)_handlers.get();
|
||||
|
||||
// Handle no contexts
|
||||
if (mapping == null)
|
||||
return;
|
||||
Handler[] handlers = mapping.getHandlers();
|
||||
if (handlers == null || handlers.length == 0)
|
||||
return;
|
||||
|
||||
Mapping mapping = (Mapping)handlers;
|
||||
// handle only a single context.
|
||||
if (handlers.length == 1)
|
||||
{
|
||||
handlers[0].handle(target, baseRequest, request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
// handle async dispatch to specific context
|
||||
HttpChannelState async = baseRequest.getHttpChannelState();
|
||||
if (async.isAsync())
|
||||
{
|
||||
|
@ -194,6 +206,7 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
}
|
||||
}
|
||||
|
||||
// handle many contexts
|
||||
if (target.startsWith("/"))
|
||||
{
|
||||
Trie<Map.Entry<String, Branch[]>> pathBranches = mapping._pathBranches;
|
||||
|
@ -226,11 +239,9 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
}
|
||||
else
|
||||
{
|
||||
if (mapping.getHandlers() == null)
|
||||
return;
|
||||
for (int i = 0; i < mapping.getHandlers().length; i++)
|
||||
for (Handler handler : handlers)
|
||||
{
|
||||
mapping.getHandlers()[i].handle(target, baseRequest, request, response);
|
||||
handler.handle(target, baseRequest, request, response);
|
||||
if (baseRequest.isHandled())
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.util.thread;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.eclipse.jetty.util.ProcessorUtils;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
|
@ -26,6 +30,8 @@ import org.junit.jupiter.api.BeforeAll;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public abstract class AbstractThreadPoolTest
|
||||
|
@ -87,4 +93,26 @@ public abstract class AbstractThreadPoolTest
|
|||
|
||||
assertThat(pool.getMaxThreads(), Matchers.is(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinWithStopTimeout()
|
||||
{
|
||||
// ThreadPool must be an implement ContainerLifeCycle for this test to be valid.
|
||||
SizedThreadPool threadPool = newPool(3);
|
||||
if (!(threadPool instanceof ContainerLifeCycle))
|
||||
return;
|
||||
|
||||
final long stopTimeout = 100;
|
||||
((ContainerLifeCycle)threadPool).setStopTimeout(100);
|
||||
LifeCycle.start(threadPool);
|
||||
|
||||
// Verify that join does not timeout after waiting twice the stopTimeout.
|
||||
assertThrows(Throwable.class, () ->
|
||||
assertTimeoutPreemptively(Duration.ofMillis(stopTimeout * 2), threadPool::join)
|
||||
);
|
||||
|
||||
// After stopping the ThreadPool join should unblock.
|
||||
LifeCycle.stop(threadPool);
|
||||
assertTimeoutPreemptively(Duration.ofMillis(stopTimeout), threadPool::join);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
</parent>
|
||||
<artifactId>test-jdbc-sessions</artifactId>
|
||||
<name>Jetty Tests :: Sessions :: JDBC</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.sessions.jdbc</bundle-symbolic-name>
|
||||
<mariadb.docker.version>10.3.6</mariadb.docker.version>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -22,6 +22,15 @@
|
|||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<mariadb.docker.version>${mariadb.docker.version}</mariadb.docker.version>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
|
@ -55,13 +64,13 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
<artifactId>derby</artifactId>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
<artifactId>derbytools</artifactId>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -74,5 +83,21 @@
|
|||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mariadb</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<version>2.6.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
/**
|
||||
* ClusteredInvalidationSessionTest
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class ClusteredInvalidationSessionTest extends AbstractClusteredInvalidationSessionTest
|
||||
{
|
||||
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
/**
|
||||
* ClusteredOrphanedSessionTest
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.jetty.client.api.Request;
|
|||
import org.eclipse.jetty.http.HttpField;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
@ -45,6 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||
* Rather, it tests all of the machinery above the SessionDataStore. Thus,
|
||||
* to reduce test time, we only apply it to the JDBCSessionDataStore.
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class ClusteredSessionMigrationTest extends AbstractTestBase
|
||||
{
|
||||
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
/**
|
||||
* ClusteredSessionScavengingTest
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -20,10 +20,12 @@ package org.eclipse.jetty.server.session;
|
|||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
/**
|
||||
* JDBCSessionDataStoreTest
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest
|
||||
{
|
||||
|
||||
|
|
|
@ -33,6 +33,11 @@ import java.util.Set;
|
|||
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.MariaDBContainer;
|
||||
import org.testcontainers.containers.output.Slf4jLogConsumer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
@ -42,9 +47,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
*/
|
||||
public class JdbcTestHelper
|
||||
{
|
||||
public static final String DRIVER_CLASS = "org.apache.derby.jdbc.EmbeddedDriver";
|
||||
public static final String DEFAULT_CONNECTION_URL = "jdbc:derby:memory:sessions;create=true";
|
||||
public static final String DEFAULT_SHUTDOWN_URL = "jdbc:derby:memory:sessions;drop=true";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JdbcTestHelper.class);
|
||||
private static final Logger MARIADB_LOG = LoggerFactory.getLogger("org.eclipse.jetty.server.session.MariaDbLogs");
|
||||
|
||||
public static String DRIVER_CLASS;
|
||||
public static String DEFAULT_CONNECTION_URL;
|
||||
|
||||
public static final int STALE_INTERVAL = 1;
|
||||
|
||||
public static final String EXPIRY_COL = "extime";
|
||||
|
@ -60,28 +68,60 @@ public class JdbcTestHelper
|
|||
public static final String COOKIE_COL = "cooktime";
|
||||
public static final String CREATE_COL = "ctime";
|
||||
|
||||
static MariaDBContainer MARIAD_DB;
|
||||
|
||||
static final String MARIA_DB_USER = "beer";
|
||||
static final String MARIA_DB_PASSWORD = "pacific_ale";
|
||||
|
||||
static
|
||||
{
|
||||
System.setProperty("derby.system.home", MavenTestingUtils.getTargetFile("test-derby").getAbsolutePath());
|
||||
try
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
MARIAD_DB =
|
||||
new MariaDBContainer("mariadb:" + System.getProperty("mariadb.docker.version", "10.3.6"))
|
||||
.withUsername(MARIA_DB_USER)
|
||||
.withPassword(MARIA_DB_PASSWORD)
|
||||
.withDatabaseName("sessions");
|
||||
MARIAD_DB.withLogConsumer(new Slf4jLogConsumer(MARIADB_LOG)).start();
|
||||
String containerIpAddress = MARIAD_DB.getContainerIpAddress();
|
||||
int mariadbPort = MARIAD_DB.getMappedPort(3306);
|
||||
DEFAULT_CONNECTION_URL = MARIAD_DB.getJdbcUrl();
|
||||
DRIVER_CLASS = MARIAD_DB.getDriverClassName();
|
||||
LOG.info("Mariadb container started for {}:{} - {}ms", containerIpAddress, mariadbPort,
|
||||
System.currentTimeMillis() - start);
|
||||
DEFAULT_CONNECTION_URL = DEFAULT_CONNECTION_URL + "?user=" + MARIA_DB_USER +
|
||||
"&password=" + MARIA_DB_PASSWORD;
|
||||
LOG.info("DEFAULT_CONNECTION_URL: {}", DEFAULT_CONNECTION_URL);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void shutdown(String connectionUrl)
|
||||
throws Exception
|
||||
{
|
||||
if (connectionUrl == null)
|
||||
connectionUrl = DEFAULT_SHUTDOWN_URL;
|
||||
try (Connection connection = getConnection())
|
||||
{
|
||||
connection.prepareStatement("truncate table " + TABLE).executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DriverManager.getConnection(connectionUrl);
|
||||
}
|
||||
catch (SQLException expected)
|
||||
{
|
||||
if (!"08006".equals(expected.getSQLState()))
|
||||
{
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
public static DatabaseAdaptor buildDatabaseAdaptor()
|
||||
{
|
||||
DatabaseAdaptor da = new DatabaseAdaptor();
|
||||
da.setDriverInfo(DRIVER_CLASS, DEFAULT_CONNECTION_URL);
|
||||
return da;
|
||||
}
|
||||
|
||||
public static Connection getConnection()
|
||||
throws Exception
|
||||
{
|
||||
Class.forName(DRIVER_CLASS);
|
||||
return DriverManager.getConnection(DEFAULT_CONNECTION_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,9 +129,7 @@ public class JdbcTestHelper
|
|||
*/
|
||||
public static SessionDataStoreFactory newSessionDataStoreFactory()
|
||||
{
|
||||
DatabaseAdaptor da = new DatabaseAdaptor();
|
||||
da.setDriverInfo(DRIVER_CLASS, DEFAULT_CONNECTION_URL);
|
||||
return newSessionDataStoreFactory(da);
|
||||
return newSessionDataStoreFactory(buildDatabaseAdaptor());
|
||||
}
|
||||
|
||||
public static SessionDataStoreFactory newSessionDataStoreFactory(DatabaseAdaptor da)
|
||||
|
@ -123,8 +161,7 @@ public class JdbcTestHelper
|
|||
|
||||
public static void prepareTables() throws SQLException
|
||||
{
|
||||
DatabaseAdaptor da = new DatabaseAdaptor();
|
||||
da.setDriverInfo(DRIVER_CLASS, DEFAULT_CONNECTION_URL);
|
||||
DatabaseAdaptor da = buildDatabaseAdaptor();
|
||||
JDBCSessionDataStore.SessionTableSchema sessionTableSchema = newSessionTableSchema();
|
||||
sessionTableSchema.setDatabaseAdaptor(da);
|
||||
|
||||
|
@ -163,11 +200,8 @@ public class JdbcTestHelper
|
|||
public static boolean existsInSessionTable(String id, boolean verbose)
|
||||
throws Exception
|
||||
{
|
||||
Class.forName(DRIVER_CLASS);
|
||||
Connection con = null;
|
||||
try
|
||||
try (Connection con = getConnection())
|
||||
{
|
||||
con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);
|
||||
PreparedStatement statement = con.prepareStatement("select * from " +
|
||||
TABLE +
|
||||
" where " + ID_COL + " = ?");
|
||||
|
@ -186,21 +220,15 @@ public class JdbcTestHelper
|
|||
else
|
||||
return result.next();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (con != null)
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean checkSessionPersisted(SessionData data)
|
||||
throws Exception
|
||||
{
|
||||
Class.forName(DRIVER_CLASS);
|
||||
PreparedStatement statement = null;
|
||||
ResultSet result = null;
|
||||
try (Connection con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);)
|
||||
try (Connection con = getConnection())
|
||||
{
|
||||
statement = con.prepareStatement(
|
||||
"select * from " + TABLE +
|
||||
|
@ -265,9 +293,7 @@ public class JdbcTestHelper
|
|||
|
||||
public static void insertSession(SessionData data) throws Exception
|
||||
{
|
||||
|
||||
Class.forName(DRIVER_CLASS);
|
||||
try (Connection con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);)
|
||||
try (Connection con = getConnection())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("insert into " + TABLE +
|
||||
" (" + ID_COL + ", " + CONTEXT_COL + ", virtualHost, " + LAST_NODE_COL +
|
||||
|
@ -311,8 +337,7 @@ public class JdbcTestHelper
|
|||
long cookieSet, long lastSaved)
|
||||
throws Exception
|
||||
{
|
||||
Class.forName(DRIVER_CLASS);
|
||||
try (Connection con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);)
|
||||
try (Connection con = getConnection())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("insert into " + TABLE +
|
||||
" (" + ID_COL + ", " + CONTEXT_COL + ", virtualHost, " + LAST_NODE_COL +
|
||||
|
@ -344,12 +369,9 @@ public class JdbcTestHelper
|
|||
public static Set<String> getSessionIds()
|
||||
throws Exception
|
||||
{
|
||||
HashSet<String> ids = new HashSet<String>();
|
||||
Class.forName(DRIVER_CLASS);
|
||||
Connection con = null;
|
||||
try
|
||||
HashSet<String> ids = new HashSet<>();
|
||||
try (Connection con = getConnection())
|
||||
{
|
||||
con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);
|
||||
PreparedStatement statement = con.prepareStatement("select " + ID_COL + " from " + TABLE);
|
||||
ResultSet result = statement.executeQuery();
|
||||
while (result.next())
|
||||
|
@ -358,10 +380,5 @@ public class JdbcTestHelper
|
|||
}
|
||||
return ids;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (con != null)
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.eclipse.jetty.webapp.WebAppContext;
|
|||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
@ -46,6 +47,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
* ReloadedSessionMissingClassTest
|
||||
*/
|
||||
@ExtendWith(WorkDirExtension.class)
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class ReloadedSessionMissingClassTest
|
||||
{
|
||||
public WorkDir testdir;
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.eclipse.jetty.server.session;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
|
@ -28,6 +27,7 @@ import org.eclipse.jetty.server.handler.ContextHandler;
|
|||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
@ -39,6 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
* Test the SessionTableSchema behaviour when the database treats "" as a NULL,
|
||||
* like Oracle does.
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class SessionTableSchemaTest
|
||||
{
|
||||
DatabaseAdaptor _da;
|
||||
|
@ -81,8 +82,7 @@ public class SessionTableSchemaTest
|
|||
public static void insertSessionWithoutAttributes(String id, String contextPath, String vhost)
|
||||
throws Exception
|
||||
{
|
||||
Class.forName(JdbcTestHelper.DRIVER_CLASS);
|
||||
try (Connection con = DriverManager.getConnection(JdbcTestHelper.DEFAULT_CONNECTION_URL);)
|
||||
try (Connection con = JdbcTestHelper.getConnection())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("insert into " + JdbcTestHelper.TABLE +
|
||||
" (" + JdbcTestHelper.ID_COL + ", " + JdbcTestHelper.CONTEXT_COL + ", virtualHost, " + JdbcTestHelper.LAST_NODE_COL +
|
||||
|
@ -116,8 +116,10 @@ public class SessionTableSchemaTest
|
|||
_da.initialize();
|
||||
_tableSchema.prepareTables();
|
||||
|
||||
String id = Long.toString(System.nanoTime());
|
||||
|
||||
//insert a fake session at the root context
|
||||
insertSessionWithoutAttributes("1234", "/", "0.0.0.0");
|
||||
insertSessionWithoutAttributes(id, "/", "0.0.0.0");
|
||||
|
||||
//test if it can be seen
|
||||
try (Connection con = _da.getConnection())
|
||||
|
@ -127,7 +129,7 @@ public class SessionTableSchemaTest
|
|||
handler.setContextPath("/");
|
||||
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
||||
//test the load statement
|
||||
PreparedStatement s = _tableSchema.getLoadStatement(con, "1234", sc);
|
||||
PreparedStatement s = _tableSchema.getLoadStatement(con, id, sc);
|
||||
ResultSet rs = s.executeQuery();
|
||||
assertTrue(rs.next());
|
||||
}
|
||||
|
@ -141,8 +143,10 @@ public class SessionTableSchemaTest
|
|||
_da.initialize();
|
||||
_tableSchema.prepareTables();
|
||||
|
||||
String id = Long.toString(System.nanoTime());
|
||||
|
||||
//insert a fake session at the root context
|
||||
insertSessionWithoutAttributes("1234", "/", "0.0.0.0");
|
||||
insertSessionWithoutAttributes(id, "/", "0.0.0.0");
|
||||
|
||||
//test if it can be seen
|
||||
try (Connection con = _da.getConnection())
|
||||
|
@ -151,7 +155,7 @@ public class SessionTableSchemaTest
|
|||
handler.setContextPath("/");
|
||||
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
||||
PreparedStatement s = _tableSchema.getCheckSessionExistsStatement(con, sc);
|
||||
s.setString(1, "1234");
|
||||
s.setString(1, id);
|
||||
ResultSet rs = s.executeQuery();
|
||||
assertTrue(rs.next());
|
||||
}
|
||||
|
@ -165,8 +169,10 @@ public class SessionTableSchemaTest
|
|||
_da.initialize();
|
||||
_tableSchema.prepareTables();
|
||||
|
||||
String id = Long.toString(System.nanoTime());
|
||||
|
||||
//insert a fake session at the root context
|
||||
insertSessionWithoutAttributes("1234", "/", "0.0.0.0");
|
||||
insertSessionWithoutAttributes(id, "/", "0.0.0.0");
|
||||
|
||||
//test if it can be deleted
|
||||
try (Connection con = _da.getConnection())
|
||||
|
@ -174,10 +180,10 @@ public class SessionTableSchemaTest
|
|||
ContextHandler handler = new ContextHandler();
|
||||
handler.setContextPath("/");
|
||||
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
||||
PreparedStatement s = _tableSchema.getDeleteStatement(con, "1234", sc);
|
||||
PreparedStatement s = _tableSchema.getDeleteStatement(con, id, sc);
|
||||
assertEquals(1, s.executeUpdate());
|
||||
|
||||
assertFalse(JdbcTestHelper.existsInSessionTable("1234", false));
|
||||
assertFalse(JdbcTestHelper.existsInSessionTable(id, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,8 +195,10 @@ public class SessionTableSchemaTest
|
|||
_da.initialize();
|
||||
_tableSchema.prepareTables();
|
||||
|
||||
String id = Long.toString(System.nanoTime());
|
||||
|
||||
//insert a fake session at the root context
|
||||
insertSessionWithoutAttributes("1234", "/", "0.0.0.0");
|
||||
insertSessionWithoutAttributes(id, "/", "0.0.0.0");
|
||||
|
||||
try (Connection con = _da.getConnection())
|
||||
{
|
||||
|
@ -203,7 +211,7 @@ public class SessionTableSchemaTest
|
|||
(System.currentTimeMillis() + 100L));
|
||||
ResultSet rs = s.executeQuery();
|
||||
assertTrue(rs.next());
|
||||
assertEquals("1234", rs.getString(1));
|
||||
assertEquals(id, rs.getString(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,8 +223,10 @@ public class SessionTableSchemaTest
|
|||
_da.initialize();
|
||||
_tableSchema.prepareTables();
|
||||
|
||||
String id = Long.toString(System.nanoTime());
|
||||
|
||||
//insert a fake session at the root context
|
||||
insertSessionWithoutAttributes("1234", "/", "0.0.0.0");
|
||||
insertSessionWithoutAttributes(id, "/", "0.0.0.0");
|
||||
|
||||
try (Connection con = _da.getConnection())
|
||||
{
|
||||
|
@ -228,7 +238,7 @@ public class SessionTableSchemaTest
|
|||
(System.currentTimeMillis() + 100L));
|
||||
ResultSet rs = s.executeQuery();
|
||||
assertTrue(rs.next());
|
||||
assertEquals("1234", rs.getString(1));
|
||||
assertEquals(id, rs.getString(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,8 +250,10 @@ public class SessionTableSchemaTest
|
|||
_da.initialize();
|
||||
_tableSchema.prepareTables();
|
||||
|
||||
String id = Long.toString(System.nanoTime());
|
||||
|
||||
//insert a fake session at the root context
|
||||
insertSessionWithoutAttributes("1234", "/", "0.0.0.0");
|
||||
insertSessionWithoutAttributes(id, "/", "0.0.0.0");
|
||||
|
||||
try (Connection con = _da.getConnection())
|
||||
{
|
||||
|
@ -249,7 +261,7 @@ public class SessionTableSchemaTest
|
|||
handler.setContextPath("/");
|
||||
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
||||
PreparedStatement s = _tableSchema.getUpdateStatement(con,
|
||||
"1234",
|
||||
id,
|
||||
sc);
|
||||
|
||||
s.setString(1, "0");//should be my node id
|
||||
|
|
|
@ -21,10 +21,12 @@ package org.eclipse.jetty.server.session;
|
|||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
/**
|
||||
* WebAppObjectInSessionTest
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class WebAppObjectInSessionTest extends AbstractWebAppObjectInSessionTest
|
||||
{
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
org.slf4j.simpleLogger.defaultLogLevel=info
|
||||
org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.MariaDbLogs=error
|
||||
org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.JdbcTestHelper=info
|
Loading…
Reference in New Issue