use testcontainers/docker to run jdbc sessions tests with Mariadb remote
Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
parent
0b8306976a
commit
c05bd6c26d
|
@ -60,6 +60,8 @@ public class DatabaseAdaptor
|
||||||
private String _connectionUrl;
|
private String _connectionUrl;
|
||||||
private Driver _driver;
|
private Driver _driver;
|
||||||
private DataSource _datasource;
|
private DataSource _datasource;
|
||||||
|
private String _username;
|
||||||
|
private String _password;
|
||||||
|
|
||||||
private String _jndiName;
|
private String _jndiName;
|
||||||
|
|
||||||
|
@ -257,6 +259,26 @@ public class DatabaseAdaptor
|
||||||
return _connectionUrl;
|
return _connectionUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUsername()
|
||||||
|
{
|
||||||
|
return _username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username)
|
||||||
|
{
|
||||||
|
this._username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword()
|
||||||
|
{
|
||||||
|
return _password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password)
|
||||||
|
{
|
||||||
|
this._password = password;
|
||||||
|
}
|
||||||
|
|
||||||
public void initialize()
|
public void initialize()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -302,7 +324,8 @@ public class DatabaseAdaptor
|
||||||
if (_datasource != null)
|
if (_datasource != null)
|
||||||
return _datasource.getConnection();
|
return _datasource.getConnection();
|
||||||
else
|
else
|
||||||
return DriverManager.getConnection(_connectionUrl);
|
return _username == null ? DriverManager.getConnection(_connectionUrl)
|
||||||
|
: DriverManager.getConnection(_connectionUrl, _username, _password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
5
pom.xml
5
pom.xml
|
@ -63,6 +63,7 @@
|
||||||
<localRepoPath>${project.build.directory}/local-repo</localRepoPath>
|
<localRepoPath>${project.build.directory}/local-repo</localRepoPath>
|
||||||
<settingsPath>src/it/settings.xml</settingsPath>
|
<settingsPath>src/it/settings.xml</settingsPath>
|
||||||
<surefire.rerunFailingTestsCount>0</surefire.rerunFailingTestsCount>
|
<surefire.rerunFailingTestsCount>0</surefire.rerunFailingTestsCount>
|
||||||
|
<testcontainers.version>1.14.2</testcontainers.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
|
@ -1083,12 +1084,12 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testcontainers</groupId>
|
<groupId>org.testcontainers</groupId>
|
||||||
<artifactId>testcontainers</artifactId>
|
<artifactId>testcontainers</artifactId>
|
||||||
<version>1.14.1</version>
|
<version>${testcontainers.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testcontainers</groupId>
|
<groupId>org.testcontainers</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>1.14.1</version>
|
<version>${testcontainers.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Old Deps -->
|
<!-- Old Deps -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>test-jdbc-sessions</artifactId>
|
<artifactId>test-jdbc-sessions</artifactId>
|
||||||
<name>Jetty Tests :: Sessions :: JDBC</name>
|
<name>Jetty Tests :: Sessions :: JDBC</name>
|
||||||
<url>http://www.eclipse.org/jetty</url>
|
|
||||||
<properties>
|
<properties>
|
||||||
<bundle-symbolic-name>${project.groupId}.sessions.jdbc</bundle-symbolic-name>
|
<bundle-symbolic-name>${project.groupId}.sessions.jdbc</bundle-symbolic-name>
|
||||||
|
<mariadb.docker.version>10.3.6</mariadb.docker.version>
|
||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -22,6 +22,15 @@
|
||||||
<skip>true</skip>
|
<skip>true</skip>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<mariadb.enabled>false</mariadb.enabled>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -60,5 +69,57 @@
|
||||||
<artifactId>jetty-test-helper</artifactId>
|
<artifactId>jetty-test-helper</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testcontainers</groupId>
|
||||||
|
<artifactId>testcontainers</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.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mariadb.jdbc</groupId>
|
||||||
|
<artifactId>mariadb-java-client</artifactId>
|
||||||
|
<version>2.6.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>remote-session-tests</id>
|
||||||
|
<activation>
|
||||||
|
<property>
|
||||||
|
<name>mariadb.enabled</name>
|
||||||
|
<value>true</value>
|
||||||
|
</property>
|
||||||
|
</activation>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<mariadb.docker.version>${mariadb.docker.version}</mariadb.docker.version>
|
||||||
|
<mariadb.enabled>true</mariadb.enabled>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -33,6 +33,11 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
@ -42,9 +47,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
*/
|
*/
|
||||||
public class JdbcTestHelper
|
public class JdbcTestHelper
|
||||||
{
|
{
|
||||||
public static final String DRIVER_CLASS = "org.apache.derby.jdbc.EmbeddedDriver";
|
public static final boolean USE_MARIADB = Boolean.getBoolean("mariadb.enabled");
|
||||||
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 = "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 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";
|
||||||
|
@ -60,6 +70,33 @@ public class JdbcTestHelper
|
||||||
public static final String COOKIE_COL = "cooktime";
|
public static final String COOKIE_COL = "cooktime";
|
||||||
public static final String CREATE_COL = "ctime";
|
public static final String CREATE_COL = "ctime";
|
||||||
|
|
||||||
|
static MariaDBContainer MARIAD_DB =
|
||||||
|
new MariaDBContainer("mariadb:" + System.getProperty("mariadb.docker.version", "10.3.6"))
|
||||||
|
.withDatabaseName("sessions");
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
if (USE_MARIADB)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LOG.error(e.getMessage(), e);
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
System.setProperty("derby.system.home", MavenTestingUtils.getTargetFile("test-derby").getAbsolutePath());
|
System.setProperty("derby.system.home", MavenTestingUtils.getTargetFile("test-derby").getAbsolutePath());
|
||||||
|
@ -68,6 +105,14 @@ 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())
|
||||||
|
{
|
||||||
|
connection.prepareStatement("truncate table " + TABLE).executeUpdate();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (connectionUrl == null)
|
if (connectionUrl == null)
|
||||||
connectionUrl = DEFAULT_SHUTDOWN_URL;
|
connectionUrl = DEFAULT_SHUTDOWN_URL;
|
||||||
|
|
||||||
|
@ -84,14 +129,34 @@ public class JdbcTestHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DatabaseAdaptor buildDatabaseAdaptor()
|
||||||
|
{
|
||||||
|
DatabaseAdaptor da = new DatabaseAdaptor();
|
||||||
|
if (USE_MARIADB)
|
||||||
|
{
|
||||||
|
da.setUsername(MARIAD_DB.getUsername());
|
||||||
|
da.setPassword(MARIAD_DB.getPassword());
|
||||||
|
}
|
||||||
|
da.setDriverInfo(DRIVER_CLASS, DEFAULT_CONNECTION_URL);
|
||||||
|
return da;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection getConnection()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Class.forName(DRIVER_CLASS);
|
||||||
|
return USE_MARIADB ? DriverManager.getConnection(DEFAULT_CONNECTION_URL,
|
||||||
|
MARIAD_DB.getUsername(),
|
||||||
|
MARIAD_DB.getPassword())
|
||||||
|
: DriverManager.getConnection(DEFAULT_CONNECTION_URL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a fresh JDBCSessionDataStoreFactory
|
* @return a fresh JDBCSessionDataStoreFactory
|
||||||
*/
|
*/
|
||||||
public static SessionDataStoreFactory newSessionDataStoreFactory()
|
public static SessionDataStoreFactory newSessionDataStoreFactory()
|
||||||
{
|
{
|
||||||
DatabaseAdaptor da = new DatabaseAdaptor();
|
return newSessionDataStoreFactory(buildDatabaseAdaptor());
|
||||||
da.setDriverInfo(DRIVER_CLASS, DEFAULT_CONNECTION_URL);
|
|
||||||
return newSessionDataStoreFactory(da);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SessionDataStoreFactory newSessionDataStoreFactory(DatabaseAdaptor da)
|
public static SessionDataStoreFactory newSessionDataStoreFactory(DatabaseAdaptor da)
|
||||||
|
@ -123,8 +188,7 @@ public class JdbcTestHelper
|
||||||
|
|
||||||
public static void prepareTables() throws SQLException
|
public static void prepareTables() throws SQLException
|
||||||
{
|
{
|
||||||
DatabaseAdaptor da = new DatabaseAdaptor();
|
DatabaseAdaptor da = buildDatabaseAdaptor();
|
||||||
da.setDriverInfo(DRIVER_CLASS, DEFAULT_CONNECTION_URL);
|
|
||||||
JDBCSessionDataStore.SessionTableSchema sessionTableSchema = newSessionTableSchema();
|
JDBCSessionDataStore.SessionTableSchema sessionTableSchema = newSessionTableSchema();
|
||||||
sessionTableSchema.setDatabaseAdaptor(da);
|
sessionTableSchema.setDatabaseAdaptor(da);
|
||||||
|
|
||||||
|
@ -163,11 +227,8 @@ public class JdbcTestHelper
|
||||||
public static boolean existsInSessionTable(String id, boolean verbose)
|
public static boolean existsInSessionTable(String id, boolean verbose)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
Class.forName(DRIVER_CLASS);
|
try (Connection con = getConnection())
|
||||||
Connection con = null;
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);
|
|
||||||
PreparedStatement statement = con.prepareStatement("select * from " +
|
PreparedStatement statement = con.prepareStatement("select * from " +
|
||||||
TABLE +
|
TABLE +
|
||||||
" where " + ID_COL + " = ?");
|
" where " + ID_COL + " = ?");
|
||||||
|
@ -186,21 +247,15 @@ public class JdbcTestHelper
|
||||||
else
|
else
|
||||||
return result.next();
|
return result.next();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (con != null)
|
|
||||||
con.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static boolean checkSessionPersisted(SessionData data)
|
public static boolean checkSessionPersisted(SessionData data)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
Class.forName(DRIVER_CLASS);
|
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
ResultSet result = null;
|
ResultSet result = null;
|
||||||
try (Connection con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);)
|
try (Connection con = getConnection())
|
||||||
{
|
{
|
||||||
statement = con.prepareStatement("select * from " + TABLE +
|
statement = con.prepareStatement("select * from " + TABLE +
|
||||||
" where " + ID_COL + " = ? and " + CONTEXT_COL +
|
" where " + ID_COL + " = ? and " + CONTEXT_COL +
|
||||||
|
@ -264,9 +319,7 @@ public class JdbcTestHelper
|
||||||
|
|
||||||
public static void insertSession(SessionData data) throws Exception
|
public static void insertSession(SessionData data) throws Exception
|
||||||
{
|
{
|
||||||
|
try (Connection con = getConnection())
|
||||||
Class.forName(DRIVER_CLASS);
|
|
||||||
try (Connection con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);)
|
|
||||||
{
|
{
|
||||||
PreparedStatement statement = con.prepareStatement("insert into " + TABLE +
|
PreparedStatement statement = con.prepareStatement("insert into " + TABLE +
|
||||||
" (" + ID_COL + ", " + CONTEXT_COL + ", virtualHost, " + LAST_NODE_COL +
|
" (" + ID_COL + ", " + CONTEXT_COL + ", virtualHost, " + LAST_NODE_COL +
|
||||||
|
@ -310,8 +363,7 @@ public class JdbcTestHelper
|
||||||
long cookieSet, long lastSaved)
|
long cookieSet, long lastSaved)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
Class.forName(DRIVER_CLASS);
|
try (Connection con = getConnection())
|
||||||
try (Connection con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);)
|
|
||||||
{
|
{
|
||||||
PreparedStatement statement = con.prepareStatement("insert into " + TABLE +
|
PreparedStatement statement = con.prepareStatement("insert into " + TABLE +
|
||||||
" (" + ID_COL + ", " + CONTEXT_COL + ", virtualHost, " + LAST_NODE_COL +
|
" (" + ID_COL + ", " + CONTEXT_COL + ", virtualHost, " + LAST_NODE_COL +
|
||||||
|
@ -343,12 +395,9 @@ public class JdbcTestHelper
|
||||||
public static Set<String> getSessionIds()
|
public static Set<String> getSessionIds()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
HashSet<String> ids = new HashSet<String>();
|
HashSet<String> ids = new HashSet<>();
|
||||||
Class.forName(DRIVER_CLASS);
|
try (Connection con = getConnection())
|
||||||
Connection con = null;
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);
|
|
||||||
PreparedStatement statement = con.prepareStatement("select " + ID_COL + " from " + TABLE);
|
PreparedStatement statement = con.prepareStatement("select " + ID_COL + " from " + TABLE);
|
||||||
ResultSet result = statement.executeQuery();
|
ResultSet result = statement.executeQuery();
|
||||||
while (result.next())
|
while (result.next())
|
||||||
|
@ -357,10 +406,5 @@ public class JdbcTestHelper
|
||||||
}
|
}
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (con != null)
|
|
||||||
con.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ 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;
|
||||||
|
@ -60,6 +61,11 @@ public class SessionTableSchemaTest
|
||||||
return true; //test special handling for oracle
|
return true; //test special handling for oracle
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (USE_MARIADB)
|
||||||
|
{
|
||||||
|
_da.setUsername(JdbcTestHelper.MARIAD_DB.getUsername());
|
||||||
|
_da.setPassword(JdbcTestHelper.MARIAD_DB.getPassword());
|
||||||
|
}
|
||||||
_da.setDriverInfo(JdbcTestHelper.DRIVER_CLASS, JdbcTestHelper.DEFAULT_CONNECTION_URL);
|
_da.setDriverInfo(JdbcTestHelper.DRIVER_CLASS, JdbcTestHelper.DEFAULT_CONNECTION_URL);
|
||||||
_tableSchema = JdbcTestHelper.newSessionTableSchema();
|
_tableSchema = JdbcTestHelper.newSessionTableSchema();
|
||||||
_tableSchema.setDatabaseAdaptor(_da);
|
_tableSchema.setDatabaseAdaptor(_da);
|
||||||
|
@ -84,8 +90,7 @@ public class SessionTableSchemaTest
|
||||||
public static void insertSessionWithoutAttributes(String id, String contextPath, String vhost)
|
public static void insertSessionWithoutAttributes(String id, String contextPath, String vhost)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
Class.forName(JdbcTestHelper.DRIVER_CLASS);
|
try (Connection con = JdbcTestHelper.getConnection())
|
||||||
try (Connection con = DriverManager.getConnection(JdbcTestHelper.DEFAULT_CONNECTION_URL);)
|
|
||||||
{
|
{
|
||||||
PreparedStatement statement = con.prepareStatement("insert into " + JdbcTestHelper.TABLE +
|
PreparedStatement statement = con.prepareStatement("insert into " + JdbcTestHelper.TABLE +
|
||||||
" (" + JdbcTestHelper.ID_COL + ", " + JdbcTestHelper.CONTEXT_COL + ", virtualHost, " + JdbcTestHelper.LAST_NODE_COL +
|
" (" + JdbcTestHelper.ID_COL + ", " + JdbcTestHelper.CONTEXT_COL + ", virtualHost, " + JdbcTestHelper.LAST_NODE_COL +
|
||||||
|
@ -119,8 +124,10 @@ public class SessionTableSchemaTest
|
||||||
_da.initialize();
|
_da.initialize();
|
||||||
_tableSchema.prepareTables();
|
_tableSchema.prepareTables();
|
||||||
|
|
||||||
|
String id = Long.toString(System.nanoTime());
|
||||||
|
|
||||||
//insert a fake session at the root context
|
//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
|
//test if it can be seen
|
||||||
try (Connection con = _da.getConnection())
|
try (Connection con = _da.getConnection())
|
||||||
|
@ -130,7 +137,7 @@ public class SessionTableSchemaTest
|
||||||
handler.setContextPath("/");
|
handler.setContextPath("/");
|
||||||
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
||||||
//test the load statement
|
//test the load statement
|
||||||
PreparedStatement s = _tableSchema.getLoadStatement(con, "1234", sc);
|
PreparedStatement s = _tableSchema.getLoadStatement(con, id, sc);
|
||||||
ResultSet rs = s.executeQuery();
|
ResultSet rs = s.executeQuery();
|
||||||
assertTrue(rs.next());
|
assertTrue(rs.next());
|
||||||
}
|
}
|
||||||
|
@ -144,8 +151,10 @@ public class SessionTableSchemaTest
|
||||||
_da.initialize();
|
_da.initialize();
|
||||||
_tableSchema.prepareTables();
|
_tableSchema.prepareTables();
|
||||||
|
|
||||||
|
String id = Long.toString(System.nanoTime());
|
||||||
|
|
||||||
//insert a fake session at the root context
|
//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
|
//test if it can be seen
|
||||||
try (Connection con = _da.getConnection())
|
try (Connection con = _da.getConnection())
|
||||||
|
@ -154,7 +163,7 @@ public class SessionTableSchemaTest
|
||||||
handler.setContextPath("/");
|
handler.setContextPath("/");
|
||||||
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
||||||
PreparedStatement s = _tableSchema.getCheckSessionExistsStatement(con, sc);
|
PreparedStatement s = _tableSchema.getCheckSessionExistsStatement(con, sc);
|
||||||
s.setString(1, "1234");
|
s.setString(1, id);
|
||||||
ResultSet rs = s.executeQuery();
|
ResultSet rs = s.executeQuery();
|
||||||
assertTrue(rs.next());
|
assertTrue(rs.next());
|
||||||
}
|
}
|
||||||
|
@ -168,8 +177,10 @@ public class SessionTableSchemaTest
|
||||||
_da.initialize();
|
_da.initialize();
|
||||||
_tableSchema.prepareTables();
|
_tableSchema.prepareTables();
|
||||||
|
|
||||||
|
String id = Long.toString(System.nanoTime());
|
||||||
|
|
||||||
//insert a fake session at the root context
|
//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
|
//test if it can be deleted
|
||||||
try (Connection con = _da.getConnection())
|
try (Connection con = _da.getConnection())
|
||||||
|
@ -177,10 +188,10 @@ public class SessionTableSchemaTest
|
||||||
ContextHandler handler = new ContextHandler();
|
ContextHandler handler = new ContextHandler();
|
||||||
handler.setContextPath("/");
|
handler.setContextPath("/");
|
||||||
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
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());
|
assertEquals(1, s.executeUpdate());
|
||||||
|
|
||||||
assertFalse(JdbcTestHelper.existsInSessionTable("1234", false));
|
assertFalse(JdbcTestHelper.existsInSessionTable(id, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,8 +203,10 @@ public class SessionTableSchemaTest
|
||||||
_da.initialize();
|
_da.initialize();
|
||||||
_tableSchema.prepareTables();
|
_tableSchema.prepareTables();
|
||||||
|
|
||||||
|
String id = Long.toString(System.nanoTime());
|
||||||
|
|
||||||
//insert a fake session at the root context
|
//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())
|
try (Connection con = _da.getConnection())
|
||||||
{
|
{
|
||||||
|
@ -206,7 +219,7 @@ public class SessionTableSchemaTest
|
||||||
(System.currentTimeMillis() + 100L));
|
(System.currentTimeMillis() + 100L));
|
||||||
ResultSet rs = s.executeQuery();
|
ResultSet rs = s.executeQuery();
|
||||||
assertTrue(rs.next());
|
assertTrue(rs.next());
|
||||||
assertEquals("1234", rs.getString(1));
|
assertEquals(id, rs.getString(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,8 +231,10 @@ public class SessionTableSchemaTest
|
||||||
_da.initialize();
|
_da.initialize();
|
||||||
_tableSchema.prepareTables();
|
_tableSchema.prepareTables();
|
||||||
|
|
||||||
|
String id = Long.toString(System.nanoTime());
|
||||||
|
|
||||||
//insert a fake session at the root context
|
//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())
|
try (Connection con = _da.getConnection())
|
||||||
{
|
{
|
||||||
|
@ -231,7 +246,7 @@ public class SessionTableSchemaTest
|
||||||
(System.currentTimeMillis() + 100L));
|
(System.currentTimeMillis() + 100L));
|
||||||
ResultSet rs = s.executeQuery();
|
ResultSet rs = s.executeQuery();
|
||||||
assertTrue(rs.next());
|
assertTrue(rs.next());
|
||||||
assertEquals("1234", rs.getString(1));
|
assertEquals(id, rs.getString(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,8 +258,10 @@ public class SessionTableSchemaTest
|
||||||
_da.initialize();
|
_da.initialize();
|
||||||
_tableSchema.prepareTables();
|
_tableSchema.prepareTables();
|
||||||
|
|
||||||
|
String id = Long.toString(System.nanoTime());
|
||||||
|
|
||||||
//insert a fake session at the root context
|
//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())
|
try (Connection con = _da.getConnection())
|
||||||
{
|
{
|
||||||
|
@ -252,7 +269,7 @@ public class SessionTableSchemaTest
|
||||||
handler.setContextPath("/");
|
handler.setContextPath("/");
|
||||||
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
SessionContext sc = new SessionContext("0", handler.getServletContext());
|
||||||
PreparedStatement s = _tableSchema.getUpdateStatement(con,
|
PreparedStatement s = _tableSchema.getUpdateStatement(con,
|
||||||
"1234",
|
id,
|
||||||
sc);
|
sc);
|
||||||
|
|
||||||
s.setString(1, "0");//should be my node id
|
s.setString(1, "0");//should be my node id
|
||||||
|
|
|
@ -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