diff --git a/tests/test-sessions/test-jdbc-sessions/pom.xml b/tests/test-sessions/test-jdbc-sessions/pom.xml index 3bec9345b71..d6fe28174ab 100644 --- a/tests/test-sessions/test-jdbc-sessions/pom.xml +++ b/tests/test-sessions/test-jdbc-sessions/pom.xml @@ -26,9 +26,7 @@ org.apache.maven.plugins maven-surefire-plugin - - false - + true @@ -54,16 +52,6 @@ test-sessions-common ${project.version} - - org.apache.derby - derby - test - - - org.apache.derby - derbytools - test - org.eclipse.jetty.toolchain jetty-test-helper @@ -112,9 +100,9 @@ org.apache.maven.plugins maven-surefire-plugin + false ${mariadb.docker.version} - true diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestHelper.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestHelper.java index f4172c24c39..541f43c69c4 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestHelper.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestHelper.java @@ -47,14 +47,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ public class JdbcTestHelper { - public static final boolean USE_MARIADB = Boolean.getBoolean("mariadb.enabled"); - 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 = "org.apache.derby.jdbc.EmbeddedDriver"; - public static String DEFAULT_CONNECTION_URL = "jdbc:derby:memory:sessions;create=true"; - public static String DEFAULT_SHUTDOWN_URL = "jdbc:derby:memory:sessions;drop=true"; + 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"; @@ -77,32 +75,29 @@ public class JdbcTestHelper static { - if (USE_MARIADB) + try { - 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); - } + 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); } } @@ -114,27 +109,9 @@ public class JdbcTestHelper public static void shutdown(String connectionUrl) throws Exception { - if (USE_MARIADB) + try (Connection connection = getConnection()) { - try (Connection connection = getConnection()) - { - connection.prepareStatement("truncate table " + TABLE).executeUpdate(); - } - return; - } - if (connectionUrl == null) - connectionUrl = DEFAULT_SHUTDOWN_URL; - - try - { - DriverManager.getConnection(connectionUrl); - } - catch (SQLException expected) - { - if (!"08006".equals(expected.getSQLState())) - { - throw expected; - } + connection.prepareStatement("truncate table " + TABLE).executeUpdate(); } } diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionTableSchemaTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionTableSchemaTest.java index 4bbd29561b4..224d93cde7d 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionTableSchemaTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionTableSchemaTest.java @@ -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; @@ -29,7 +28,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.eclipse.jetty.server.session.JdbcTestHelper.USE_MARIADB; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue;