From 1249763aadaea73e64cfefad123ef6237000b936 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Tue, 26 May 2020 15:58:38 +1000 Subject: [PATCH] remove changes to DatabaseAdaptor with new fields username/password, use our own username/password in maria_db tests Signed-off-by: olivier lamy --- .../jetty/server/session/DatabaseAdaptor.java | 25 +------------------ .../jetty/server/session/JdbcTestHelper.java | 25 ++++++++++--------- .../session/SessionTableSchemaTest.java | 5 ---- 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java index 4bcf2217530..82f39cf081c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java @@ -60,8 +60,6 @@ public class DatabaseAdaptor private String _connectionUrl; private Driver _driver; private DataSource _datasource; - private String _username; - private String _password; private String _jndiName; @@ -259,26 +257,6 @@ public class DatabaseAdaptor 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() throws Exception { @@ -324,8 +302,7 @@ public class DatabaseAdaptor if (_datasource != null) return _datasource.getConnection(); else - return _username == null ? DriverManager.getConnection(_connectionUrl) - : DriverManager.getConnection(_connectionUrl, _username, _password); + return DriverManager.getConnection(_connectionUrl); } /** 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 0affc485e3f..f4172c24c39 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 @@ -70,9 +70,10 @@ public class JdbcTestHelper public static final String COOKIE_COL = "cooktime"; 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 MariaDBContainer MARIAD_DB; + + static final String MARIA_DB_USER = "beer"; + static final String MARIA_DB_PASSWORD = "pacific_ale"; static { @@ -81,6 +82,11 @@ public class JdbcTestHelper 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); @@ -88,6 +94,9 @@ public class JdbcTestHelper 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) { @@ -132,11 +141,6 @@ 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; } @@ -145,10 +149,7 @@ public class JdbcTestHelper 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 DriverManager.getConnection(DEFAULT_CONNECTION_URL); } /** 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 09f8e728c8d..4bbd29561b4 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 @@ -61,11 +61,6 @@ public class SessionTableSchemaTest 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); _tableSchema = JdbcTestHelper.newSessionTableSchema(); _tableSchema.setDatabaseAdaptor(_da);