bye bye Derby tests, only use mariadb via container

Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
olivier lamy 2020-05-26 18:32:14 +10:00 committed by Olivier Lamy
parent 1249763aad
commit 389f46c826
3 changed files with 29 additions and 66 deletions

View File

@ -26,9 +26,7 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<systemPropertyVariables> <skip>true</skip>
<mariadb.enabled>false</mariadb.enabled>
</systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
@ -54,16 +52,6 @@
<artifactId>test-sessions-common</artifactId> <artifactId>test-sessions-common</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId> <artifactId>jetty-test-helper</artifactId>
@ -112,9 +100,9 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<skip>false</skip>
<systemPropertyVariables> <systemPropertyVariables>
<mariadb.docker.version>${mariadb.docker.version}</mariadb.docker.version> <mariadb.docker.version>${mariadb.docker.version}</mariadb.docker.version>
<mariadb.enabled>true</mariadb.enabled>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -47,14 +47,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/ */
public class JdbcTestHelper 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 LOG = LoggerFactory.getLogger(JdbcTestHelper.class);
private static final Logger MARIADB_LOG = LoggerFactory.getLogger("org.eclipse.jetty.server.session.MariaDbLogs"); 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 DRIVER_CLASS;
public static String DEFAULT_CONNECTION_URL = "jdbc:derby:memory:sessions;create=true"; public static String DEFAULT_CONNECTION_URL;
public static String DEFAULT_SHUTDOWN_URL = "jdbc:derby:memory:sessions;drop=true";
public static final int STALE_INTERVAL = 1; public static final int STALE_INTERVAL = 1;
public static final String EXPIRY_COL = "extime"; public static final String EXPIRY_COL = "extime";
@ -77,32 +75,29 @@ public class JdbcTestHelper
static static
{ {
if (USE_MARIADB) try
{ {
try long start = System.currentTimeMillis();
{ MARIAD_DB =
long start = System.currentTimeMillis(); new MariaDBContainer("mariadb:" + System.getProperty("mariadb.docker.version", "10.3.6"))
MARIAD_DB = .withUsername(MARIA_DB_USER)
new MariaDBContainer("mariadb:" + System.getProperty("mariadb.docker.version", "10.3.6")) .withPassword(MARIA_DB_PASSWORD)
.withUsername(MARIA_DB_USER) .withDatabaseName("sessions");
.withPassword(MARIA_DB_PASSWORD) MARIAD_DB.withLogConsumer(new Slf4jLogConsumer(MARIADB_LOG)).start();
.withDatabaseName("sessions"); String containerIpAddress = MARIAD_DB.getContainerIpAddress();
MARIAD_DB.withLogConsumer(new Slf4jLogConsumer(MARIADB_LOG)).start(); int mariadbPort = MARIAD_DB.getMappedPort(3306);
String containerIpAddress = MARIAD_DB.getContainerIpAddress(); DEFAULT_CONNECTION_URL = MARIAD_DB.getJdbcUrl();
int mariadbPort = MARIAD_DB.getMappedPort(3306); DRIVER_CLASS = MARIAD_DB.getDriverClassName();
DEFAULT_CONNECTION_URL = MARIAD_DB.getJdbcUrl(); LOG.info("Mariadb container started for {}:{} - {}ms", containerIpAddress, mariadbPort,
DRIVER_CLASS = MARIAD_DB.getDriverClassName(); System.currentTimeMillis() - start);
LOG.info("Mariadb container started for {}:{} - {}ms", containerIpAddress, mariadbPort, DEFAULT_CONNECTION_URL = DEFAULT_CONNECTION_URL + "?user=" + MARIA_DB_USER +
System.currentTimeMillis() - start); "&password=" + MARIA_DB_PASSWORD;
DEFAULT_CONNECTION_URL = DEFAULT_CONNECTION_URL + "?user=" + MARIA_DB_USER + LOG.info("DEFAULT_CONNECTION_URL: {}", DEFAULT_CONNECTION_URL);
"&password=" + MARIA_DB_PASSWORD; }
LOG.info("DEFAULT_CONNECTION_URL: {}", DEFAULT_CONNECTION_URL); catch (Exception e)
} {
catch (Exception e) LOG.error(e.getMessage(), e);
{ throw new RuntimeException(e.getMessage(), 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) public static void shutdown(String connectionUrl)
throws Exception throws Exception
{ {
if (USE_MARIADB) try (Connection connection = getConnection())
{ {
try (Connection connection = getConnection()) connection.prepareStatement("truncate table " + TABLE).executeUpdate();
{
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;
}
} }
} }

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.server.session;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; 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.BeforeEach;
import org.junit.jupiter.api.Test; 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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;