diff --git a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastaxITBase.java b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastaxITBase.java index ace914690659..7befad338949 100644 --- a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastaxITBase.java +++ b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastaxITBase.java @@ -27,17 +27,17 @@ import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder; import com.navercorp.pinpoint.common.profiler.sql.DefaultSqlParser; import com.navercorp.pinpoint.common.profiler.sql.SqlParser; -import com.navercorp.pinpoint.test.plugin.shared.AfterSharedClass; - +import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.AfterClass; -import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.testcontainers.DockerClientFactory; import org.testcontainers.containers.CassandraContainer; import java.lang.reflect.Method; +import java.util.Properties; import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.event; import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.sql; @@ -46,13 +46,13 @@ * @author HyunGil Jeong */ public abstract class CassandraDatastaxITBase { - + private static final Logger logger = LogManager.getLogger(CassandraDatastaxITBase.class); // com.navercorp.pinpoint.plugin.cassandra.CassandraConstants private static final String CASSANDRA = "CASSANDRA"; private static final String CASSANDRA_EXECUTE_QUERY = "CASSANDRA_EXECUTE_QUERY"; - private static final String TEST_KEYSPACE = "mykeyspace"; - private static final String TEST_TABLE = "mytable"; + private static final String TEST_KEYSPACE = CassandraITConstants.TEST_KEYSPACE; + private static final String TEST_TABLE = CassandraITConstants.TEST_TABLE; private static final String TEST_COL_ID = "id"; private static final String TEST_COL_VALUE = "value"; @@ -66,71 +66,35 @@ public abstract class CassandraDatastaxITBase { private static String CASSANDRA_ADDRESS = HOST + ":" + CassandraContainer.CQL_PORT; - public static CassandraContainer cassandra; - + private static int PORT; private static Cluster cluster; - public static int getPORT() { - return PORT; - } - public static void setPORT(int port) { - CassandraDatastaxITBase.PORT = port; + @SharedTestBeforeAllResult + public static void setBeforeAllResult(Properties beforeAllResult) { + logger.info("CassandraServer result {}", beforeAllResult); + PORT = Integer.parseInt(beforeAllResult.getProperty("PORT")); } - private static int PORT; - - public static void startCassandra(String dockerImageVersion) { - Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); - - cassandra = new CassandraContainer(dockerImageVersion); - cassandra.start(); - -// String containerIpAddress = cassandra.getContainerIpAddress(); - final int port = cassandra.getMappedPort(CassandraContainer.CQL_PORT); - setPORT(port); - - cluster = newCluster(HOST, getPORT()); - init(cluster); + public static int getPort() { + return PORT; } - @AfterSharedClass - public static void sharedTearDown() { - if (cassandra != null) { - cassandra.stop(); - } - } @BeforeClass public static void setup() { - CASSANDRA_ADDRESS = HOST + ":" + getPORT(); - cluster = newCluster(HOST, getPORT()); + CASSANDRA_ADDRESS = HOST + ":" + getPort(); + cluster = CassandraServer.newCluster(HOST, getPort()); + logger.info("setup cluster {}", CASSANDRA_ADDRESS); } @AfterClass public static void tearDown() { - if (cluster == null) { + if (cluster != null) { cluster.close(); } } - private static Cluster newCluster(String host, int port) { - Cluster.Builder builder = Cluster.builder(); - builder.addContactPoint(host); - builder.withPort(port); - builder.withoutMetrics(); - return builder.build(); - } - - public static void init(Cluster cluster) { - try (Session systemSession = cluster.connect()) { - String createKeyspace = String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = " + - "{'class':'SimpleStrategy','replication_factor':'1'};", TEST_KEYSPACE); - systemSession.execute(createKeyspace); - String createTable = String.format("CREATE TABLE %s.%s (id text, value text, PRIMARY KEY(id))", TEST_KEYSPACE, TEST_TABLE); - systemSession.execute(createTable); - } - } private static Session openSession(Cluster cluster) { return cluster.connect(TEST_KEYSPACE); @@ -260,4 +224,5 @@ public void testBatchStatement_and_StatementWrapper() throws Exception { } } + } diff --git a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_0_x_IT.java b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_0_x_IT.java index 46e73ac564ad..69a415d960e1 100644 --- a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_0_x_IT.java +++ b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_0_x_IT.java @@ -22,9 +22,7 @@ import com.navercorp.pinpoint.test.plugin.ImportPlugin; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; - -import org.junit.BeforeClass; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.runner.RunWith; /** @@ -39,11 +37,7 @@ @Dependency({ "com.datastax.cassandra:cassandra-driver-core:[2.0.10,2.0.max]", PluginITConstants.VERSION, CassandraITConstants.COMMONS_PROFILER, CassandraITConstants.CASSANDRA_TESTCONTAINER}) +@SharedTestLifeCycleClass(CassandraServer2X.class) public class CassandraDatastax_2_0_x_IT extends CassandraDatastaxITBase { - @BeforeSharedClass - public static void sharedSetup() { - startCassandra(CassandraITConstants.CASSANDRA_2_X_IMAGE); - } - } diff --git a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_1_x_IT.java b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_1_x_IT.java index 9acf087c0518..40463bc1cad1 100644 --- a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_1_x_IT.java +++ b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_1_x_IT.java @@ -22,9 +22,7 @@ import com.navercorp.pinpoint.test.plugin.ImportPlugin; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; - -import org.junit.BeforeClass; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.runner.RunWith; /** @@ -39,9 +37,7 @@ @Dependency({ "com.datastax.cassandra:cassandra-driver-core:[2.1.6,2.1.max]", PluginITConstants.VERSION, CassandraITConstants.COMMONS_PROFILER, CassandraITConstants.CASSANDRA_TESTCONTAINER}) +@SharedTestLifeCycleClass(CassandraServer2X.class) public class CassandraDatastax_2_1_x_IT extends CassandraDatastaxITBase { - @BeforeSharedClass - public static void sharedSetup() { - startCassandra(CassandraITConstants.CASSANDRA_2_X_IMAGE); - } + } diff --git a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_2_x_IT.java b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_2_x_IT.java index e8822945c5dc..5e69bdc2495f 100644 --- a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_2_x_IT.java +++ b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_2_2_x_IT.java @@ -22,8 +22,7 @@ import com.navercorp.pinpoint.test.plugin.ImportPlugin; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; - +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.runner.RunWith; /** @@ -35,9 +34,7 @@ @Dependency({ "com.datastax.cassandra:cassandra-driver-core:[2.2.min,2.2.max]", PluginITConstants.VERSION, CassandraITConstants.COMMONS_PROFILER, CassandraITConstants.CASSANDRA_TESTCONTAINER}) +@SharedTestLifeCycleClass(CassandraServer2X.class) public class CassandraDatastax_2_2_x_IT extends CassandraDatastaxITBase { - @BeforeSharedClass - public static void sharedSetup() { - startCassandra(CassandraITConstants.CASSANDRA_2_X_IMAGE); - } + } diff --git a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_3_0_x_IT.java b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_3_0_x_IT.java index fb8c32ab7eef..45c03c63d9d9 100644 --- a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_3_0_x_IT.java +++ b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraDatastax_3_0_x_IT.java @@ -22,8 +22,7 @@ import com.navercorp.pinpoint.test.plugin.ImportPlugin; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; - +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.runner.RunWith; /** @@ -37,10 +36,7 @@ // cassandra 4.x not supported "com.datastax.cassandra:cassandra-driver-core:[3.0.0,3.max)", PluginITConstants.VERSION, CassandraITConstants.COMMONS_PROFILER, CassandraITConstants.CASSANDRA_TESTCONTAINER}) +@SharedTestLifeCycleClass(CassandraServer3X.class) public class CassandraDatastax_3_0_x_IT extends CassandraDatastaxITBase { - @BeforeSharedClass - public static void sharedSetup() { - startCassandra(CassandraITConstants.CASSANDRA_3_X_IMAGE); - } } diff --git a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraITConstants.java b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraITConstants.java index 6c9b09170c6b..00535dee3d42 100644 --- a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraITConstants.java +++ b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraITConstants.java @@ -11,4 +11,7 @@ public final class CassandraITConstants { // https://hub.docker.com/_/cassandra public static final String CASSANDRA_2_X_IMAGE = CassandraContainer.IMAGE + ":2.2.16"; public static final String CASSANDRA_3_X_IMAGE = CassandraContainer.IMAGE + ":3.11.6"; + + public static final String TEST_KEYSPACE = "mykeyspace"; + public static final String TEST_TABLE = "mytable"; } diff --git a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer.java b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer.java new file mode 100644 index 000000000000..4e2e4be21efa --- /dev/null +++ b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer.java @@ -0,0 +1,70 @@ +package com.navercorp.pinpoint.plugin.cassandra; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.Assume; +import org.testcontainers.DockerClientFactory; +import org.testcontainers.containers.CassandraContainer; + +import java.util.Objects; +import java.util.Properties; + +public class CassandraServer implements SharedTestLifeCycle { + private final Logger logger = LogManager.getLogger(getClass()); + + private final String dockerImageVersion; + + public CassandraContainer cassandra; + private Cluster cluster; + + public CassandraServer(String dockerImageVersion) { + this.dockerImageVersion = Objects.requireNonNull(dockerImageVersion, "dockerImageVersion"); + } + + @Override + public Properties beforeAll() { + Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); + + cassandra = new CassandraContainer(dockerImageVersion); + cassandra.start(); + + final Integer port = cassandra.getMappedPort(CassandraContainer.CQL_PORT); + + this.cluster = newCluster("127.0.0.1", port); + init(cluster); + cluster.close(); + + Properties properties = new Properties(); + properties.setProperty("PORT", port.toString()); + return properties; + } + + public void init(Cluster cluster) { + try (Session systemSession = cluster.connect()) { + String createKeyspace = String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = " + + "{'class':'SimpleStrategy','replication_factor':'1'};", CassandraITConstants.TEST_KEYSPACE); + systemSession.execute(createKeyspace); + String createTable = String.format("CREATE TABLE %s.%s (id text, value text, PRIMARY KEY(id))", + CassandraITConstants.TEST_KEYSPACE, CassandraITConstants.TEST_TABLE); + systemSession.execute(createTable); + } + } + + public static Cluster newCluster(String host, int port) { + Cluster.Builder builder = Cluster.builder(); + builder.addContactPoint(host); + builder.withPort(port); + builder.withoutMetrics(); + return builder.build(); + } + + @Override + public void afterAll() { + if (cassandra != null) { + cassandra.stop(); + } + } +} diff --git a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer2X.java b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer2X.java new file mode 100644 index 000000000000..3a7e54974788 --- /dev/null +++ b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer2X.java @@ -0,0 +1,9 @@ +package com.navercorp.pinpoint.plugin.cassandra; + +public class CassandraServer2X extends CassandraServer { + + public CassandraServer2X() { + super(CassandraITConstants.CASSANDRA_2_X_IMAGE); + } + +} diff --git a/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer3X.java b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer3X.java new file mode 100644 index 000000000000..692a61a7d5f9 --- /dev/null +++ b/plugins-it/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer3X.java @@ -0,0 +1,9 @@ +package com.navercorp.pinpoint.plugin.cassandra; + +public class CassandraServer3X extends CassandraServer { + + public CassandraServer3X() { + super(CassandraITConstants.CASSANDRA_3_X_IMAGE); + } + +} diff --git a/plugins-it/cxf-it/src/test/java/com/navercorp/pinpoint/plugin/cxf/CxfClientIT.java b/plugins-it/cxf-it/src/test/java/com/navercorp/pinpoint/plugin/cxf/CxfClientIT.java index 37e197a8f842..bb4879113ad7 100644 --- a/plugins-it/cxf-it/src/test/java/com/navercorp/pinpoint/plugin/cxf/CxfClientIT.java +++ b/plugins-it/cxf-it/src/test/java/com/navercorp/pinpoint/plugin/cxf/CxfClientIT.java @@ -54,15 +54,15 @@ @SharedTestLifeCycleClass(HttpWebServer.class) public class CxfClientIT { - private static String ADDRESS; + private static String HOST_PORT; @SharedTestBeforeAllResult public static void setBeforeAllResult(Properties beforeAllResult) { - ADDRESS = beforeAllResult.getProperty("ADDRESS"); + HOST_PORT = beforeAllResult.getProperty("HOST_PORT"); } public String getAddress() { - return ADDRESS; + return "http://" + HOST_PORT; } @Test diff --git a/plugins-it/cxf-it/src/test/java/com/navercorp/pinpoint/plugin/cxf/HttpWebServer.java b/plugins-it/cxf-it/src/test/java/com/navercorp/pinpoint/plugin/cxf/HttpWebServer.java index 82f09d5ae61a..a04b7a1351b7 100644 --- a/plugins-it/cxf-it/src/test/java/com/navercorp/pinpoint/plugin/cxf/HttpWebServer.java +++ b/plugins-it/cxf-it/src/test/java/com/navercorp/pinpoint/plugin/cxf/HttpWebServer.java @@ -14,7 +14,6 @@ public Properties beforeAll() { webServer = WebServer.newTestWebServer(); Properties properties = new Properties(); - properties.setProperty("ADDRESS", webServer.getCallHttpUrl()); properties.setProperty("HOST_PORT", webServer.getHostAndPort()); return properties; } catch (Exception e) { diff --git a/plugins-it/httpclient3-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClientIT.java b/plugins-it/httpclient3-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClientIT.java index 81d662aac1ae..28191c18e442 100644 --- a/plugins-it/httpclient3-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClientIT.java +++ b/plugins-it/httpclient3-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClientIT.java @@ -47,15 +47,15 @@ @SharedTestLifeCycleClass(HttpWebServer.class) public class HttpClientIT { - private static String ADDRESS; + private static String HOST_PORT; @SharedTestBeforeAllResult public static void setBeforeAllResult(Properties beforeAllResult) { - ADDRESS = beforeAllResult.getProperty("ADDRESS"); + HOST_PORT = beforeAllResult.getProperty("HOST_PORT"); } public String getAddress() { - return ADDRESS; + return "http://" + HOST_PORT; } diff --git a/plugins-it/httpclient3-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient3/HttpWebServer.java b/plugins-it/httpclient3-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient3/HttpWebServer.java index ef6e07b79851..9fe7bf19b1fd 100644 --- a/plugins-it/httpclient3-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient3/HttpWebServer.java +++ b/plugins-it/httpclient3-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient3/HttpWebServer.java @@ -14,7 +14,6 @@ public Properties beforeAll() { webServer = WebServer.newTestWebServer(); Properties properties = new Properties(); - properties.setProperty("ADDRESS", webServer.getCallHttpUrl()); properties.setProperty("HOST_PORT", webServer.getHostAndPort()); return properties; } catch (Exception e) { diff --git a/plugins-it/httpclient4-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient4/HttpClientITBase.java b/plugins-it/httpclient4-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient4/HttpClientITBase.java index b628582af6cf..84c175ceaff9 100644 --- a/plugins-it/httpclient4-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient4/HttpClientITBase.java +++ b/plugins-it/httpclient4-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient4/HttpClientITBase.java @@ -27,13 +27,12 @@ public abstract class HttpClientITBase { @SharedTestBeforeAllResult public static void setBeforeAllResult(Properties beforeAllResult) { - ADDRESS = beforeAllResult.getProperty("ADDRESS"); HOST_PORT = beforeAllResult.getProperty("HOST_PORT"); } public String getAddress() { - return ADDRESS; + return "http://" + HOST_PORT; } public static String getHostPort() { diff --git a/plugins-it/httpclient4-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient4/HttpWebServer.java b/plugins-it/httpclient4-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient4/HttpWebServer.java index 09085f60ed4f..0e9cd58130a3 100644 --- a/plugins-it/httpclient4-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient4/HttpWebServer.java +++ b/plugins-it/httpclient4-it/src/test/java/com/navercorp/pinpoint/plugin/httpclient4/HttpWebServer.java @@ -14,7 +14,6 @@ public Properties beforeAll() { webServer = WebServer.newTestWebServer(); Properties properties = new Properties(); - properties.setProperty("ADDRESS", webServer.getCallHttpUrl()); properties.setProperty("HOST_PORT", webServer.getHostAndPort()); return properties; } catch (Exception e) { diff --git a/plugins-it/jtds-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/jtds/JtdsIT.java b/plugins-it/jtds-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/jtds/JtdsIT.java index e1c9a0802692..2826967d7899 100644 --- a/plugins-it/jtds-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/jtds/JtdsIT.java +++ b/plugins-it/jtds-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/jtds/JtdsIT.java @@ -29,21 +29,13 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; import com.navercorp.pinpoint.test.plugin.Repository; -import com.navercorp.pinpoint.test.plugin.shared.AfterSharedClass; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; - +import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.JdbcDatabaseContainer; -import org.testcontainers.containers.MSSQLServerContainer; -import org.testcontainers.containers.output.OutputFrame; -import java.io.IOException; import java.util.Properties; -import java.util.function.Consumer; /** * @author Jongho Moon @@ -55,56 +47,32 @@ @Dependency({"net.sourceforge.jtds:jtds:[1.2.8],[1.3.1,)", "com.microsoft.sqlserver:mssql-jdbc:[6.1.0.jre8]", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.7.5", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MSSQL}) +@SharedTestLifeCycleClass(MsSqlServer.class) public class JtdsIT extends DataBaseTestCase { private static final String MSSQL = "MSSQL"; private static final String MSSQL_EXECUTE_QUERY = "MSSQL_EXECUTE_QUERY"; - private static final Logger logger = LoggerFactory.getLogger(JtdsIT.class); - - - public static final JdbcDatabaseContainer mssqlserver = newMSSQLServerContainer(logger.getName()); - - public static JdbcDatabaseContainer newMSSQLServerContainer(String loggerName) { - final MSSQLServerContainer mssqlServerContainer = new MSSQLServerContainer("mcr.microsoft.com/mssql/server:2019-latest"); - mssqlServerContainer.addEnv("ACCEPT_EULA", "y"); - mssqlServerContainer.withInitScript("sql/init_mssql.sql"); - mssqlServerContainer.withPassword(JtdsITConstants.PASSWORD); - - - mssqlServerContainer.withLogConsumer(new Consumer() { - @Override - public void accept(OutputFrame outputFrame) { - logger.info(outputFrame.getUtf8String()); - } - }); - return mssqlServerContainer; - } - private static DriverProperties driverProperties; private static JDBCDriverClass driverClass; private static JDBCApi jdbcApi; private static JdbcUrlParserV2 jdbcUrlParser; - private static String address; - - @BeforeSharedClass - public static void sharedSetUp() throws Exception { - mssqlserver.start(); - setAddress(mssqlserver.getJdbcUrl()); + protected static String JDBC_URL; + public static String getJdbcUrl() { + return JDBC_URL; } - @AfterSharedClass - public static void sharedTearDown() { - if (mssqlserver != null) { - mssqlserver.stop(); - } + @SharedTestBeforeAllResult + public static void setBeforeAllResult(Properties beforeAllResult) { + JDBC_URL = beforeAllResult.getProperty("JDBC_URL"); } + @BeforeClass - public static void beforeClass() throws IOException, InterruptedException { - String serverJdbcUrl = getAddress(); + public static void beforeClass() { + String serverJdbcUrl = getJdbcUrl(); String address = serverJdbcUrl.substring(JtdsITConstants.JDBC_URL_PREFIX.length()); String jdbcUrl = JtdsITConstants.JTDS_URL_PREFIX + address; @@ -128,12 +96,4 @@ public void before() { setup(MSSQL, MSSQL_EXECUTE_QUERY, driverProperties, jdbcUrlParser, jdbcApi); } - public static String getAddress() { - return address; - } - - public static void setAddress(String address) { - JtdsIT.address = address; - } - } diff --git a/plugins-it/jtds-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/jtds/MsSqlServer.java b/plugins-it/jtds-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/jtds/MsSqlServer.java new file mode 100644 index 000000000000..19fba5c0f675 --- /dev/null +++ b/plugins-it/jtds-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/jtds/MsSqlServer.java @@ -0,0 +1,47 @@ +package com.navercorp.pinpoint.plugin.jdbc.jtds; + +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle; +import org.junit.Assume; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.DockerClientFactory; +import org.testcontainers.containers.MSSQLServerContainer; +import org.testcontainers.containers.output.OutputFrame; + +import java.util.Properties; +import java.util.function.Consumer; + +public class MsSqlServer implements SharedTestLifeCycle { + private final Logger logger = LoggerFactory.getLogger(getClass()); + + private MSSQLServerContainer mssqlserver; + @Override + public Properties beforeAll() { + Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); + + mssqlserver = new MSSQLServerContainer("mcr.microsoft.com/mssql/server:2019-latest"); + mssqlserver.addEnv("ACCEPT_EULA", "y"); + mssqlserver.withInitScript("sql/init_mssql.sql"); + mssqlserver.withPassword(JtdsITConstants.PASSWORD); + + + mssqlserver.withLogConsumer(new Consumer() { + @Override + public void accept(OutputFrame outputFrame) { + logger.info(outputFrame.getUtf8String()); + } + }); + mssqlserver.start(); + + Properties properties = new Properties(); + properties.setProperty("JDBC_URL", mssqlserver.getJdbcUrl()); + return properties; + } + + @Override + public void afterAll() { + if (mssqlserver != null) { + mssqlserver.stop(); + } + } +} diff --git a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDBServer.java b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDBServer.java new file mode 100644 index 000000000000..ffbb970bb4db --- /dev/null +++ b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDBServer.java @@ -0,0 +1,54 @@ +package com.navercorp.pinpoint.plugin.jdbc; + +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.Assume; +import org.testcontainers.DockerClientFactory; +import org.testcontainers.containers.MariaDBContainer; +import org.testcontainers.containers.output.OutputFrame; + +import java.util.Properties; +import java.util.function.Consumer; + +public class MariaDBServer implements SharedTestLifeCycle { + private final Logger logger = LogManager.getLogger(getClass()); + private MariaDBContainer mariaDB; + + public static final String DATABASE_NAME = "test"; + public static final String USERNAME = "root"; + public static final String PASSWORD = ""; + + @Override + public Properties beforeAll() { + Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); + + mariaDB = new MariaDBContainer(); + mariaDB.withLogConsumer(new Consumer() { + @Override + public void accept(OutputFrame outputFrame) { + logger.info(outputFrame.getUtf8String()); + } + }); + mariaDB.withDatabaseName(DATABASE_NAME); + mariaDB.withUsername(USERNAME); + mariaDB.withPassword(PASSWORD); + mariaDB.withInitScript("jdbc/mariadb/init.sql"); +// mariaDB.withUrlParam("noAccessToProcedureBodies", "true"); + mariaDB.start(); + + int port = mariaDB.getMappedPort(3306); + Properties properties = new Properties(); + properties.setProperty("JDBC_URL", mariaDB.getJdbcUrl()); + properties.setProperty("URL", mariaDB.getHost() + ":" + port); + + return properties; + } + + @Override + public void afterAll() { + if (mariaDB != null) { + mariaDB.stop(); + } + } +} diff --git a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_3_x_IT.java b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_3_x_IT.java index df50fd5fd01e..c1408822af62 100644 --- a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_3_x_IT.java +++ b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_3_x_IT.java @@ -23,7 +23,6 @@ import com.navercorp.pinpoint.pluginit.jdbc.JDBCDriverClass; import com.navercorp.pinpoint.pluginit.jdbc.JDBCTestConstants; import com.navercorp.pinpoint.pluginit.utils.AgentPath; - import com.navercorp.pinpoint.pluginit.utils.TestcontainersOption; import com.navercorp.pinpoint.test.plugin.Dependency; import com.navercorp.pinpoint.test.plugin.ImportPlugin; @@ -31,12 +30,16 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointLogLocationConfig; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Test; import org.junit.runner.RunWith; import java.lang.reflect.Method; -import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.*; +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.args; +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.cachedArgs; +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.event; +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.sql; /** * @author HyunGil Jeong @@ -48,6 +51,7 @@ @ImportPlugin("com.navercorp.pinpoint:pinpoint-mariadb-jdbc-driver-plugin") @Dependency({"org.mariadb.jdbc:mariadb-java-client:[1.3.0,1.3.max]", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MARIADB}) +@SharedTestLifeCycleClass(MariaDBServer.class) public class MariaDB_1_3_x_IT extends MariaDB_IT_Base { // see CallableParameterMetaData#queryMetaInfos diff --git a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_4_x_to_1_6_0_IT.java b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_4_x_to_1_6_0_IT.java index 77ec65bfab19..44095442c41a 100644 --- a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_4_x_to_1_6_0_IT.java +++ b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_4_x_to_1_6_0_IT.java @@ -30,6 +30,7 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointLogLocationConfig; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,6 +51,7 @@ @ImportPlugin("com.navercorp.pinpoint:pinpoint-mariadb-jdbc-driver-plugin") @Dependency({ "org.mariadb.jdbc:mariadb-java-client:[1.4.min,1.6.min)", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MARIADB}) +@SharedTestLifeCycleClass(MariaDBServer.class) public class MariaDB_1_4_x_to_1_6_0_IT extends MariaDB_IT_Base { // see CallableParameterMetaData#queryMetaInfos diff --git a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_6_x_to_1_8_0_IT.java b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_6_x_to_1_8_0_IT.java index 39900a6e529d..04c0c9c5db37 100644 --- a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_6_x_to_1_8_0_IT.java +++ b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_6_x_to_1_8_0_IT.java @@ -30,6 +30,7 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointLogLocationConfig; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -62,6 +63,7 @@ @ImportPlugin("com.navercorp.pinpoint:pinpoint-mariadb-jdbc-driver-plugin") @Dependency({ "org.mariadb.jdbc:mariadb-java-client:[1.6.0,1.8.0)", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MARIADB}) +@SharedTestLifeCycleClass(MariaDBServer.class) public class MariaDB_1_6_x_to_1_8_0_IT extends MariaDB_IT_Base { // see CallableParameterMetaData#queryMetaInfos diff --git a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_8_0_to_2_0_0_IT.java b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_8_0_to_2_0_0_IT.java index 5cae163fdece..143204493827 100644 --- a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_8_0_to_2_0_0_IT.java +++ b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_1_8_0_to_2_0_0_IT.java @@ -30,6 +30,7 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointLogLocationConfig; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -57,6 +58,7 @@ @ImportPlugin("com.navercorp.pinpoint:pinpoint-mariadb-jdbc-driver-plugin") @Dependency({ "org.mariadb.jdbc:mariadb-java-client:[1.8.0,2.min)", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MARIADB}) +@SharedTestLifeCycleClass(MariaDBServer.class) public class MariaDB_1_8_0_to_2_0_0_IT extends MariaDB_IT_Base { // see CallableParameterMetaData#queryMetaInfos diff --git a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_2_0_1_to_2_4_0_IT.java b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_2_0_1_to_2_4_0_IT.java index 3ccf8c7e3676..5f46cdda4c78 100644 --- a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_2_0_1_to_2_4_0_IT.java +++ b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_2_0_1_to_2_4_0_IT.java @@ -31,6 +31,7 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointLogLocationConfig; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,6 +52,7 @@ @ImportPlugin("com.navercorp.pinpoint:pinpoint-mariadb-jdbc-driver-plugin") @Dependency({ "org.mariadb.jdbc:mariadb-java-client:[2.0.1,2.4.min)", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MARIADB}) +@SharedTestLifeCycleClass(MariaDBServer.class) public class MariaDB_2_0_1_to_2_4_0_IT extends MariaDB_IT_Base { // see CallableParameterMetaData#queryMetaInfos diff --git a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_2_4_x_IT.java b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_2_4_x_IT.java index 9639c9dd804d..d81f6016462e 100644 --- a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_2_4_x_IT.java +++ b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_2_4_x_IT.java @@ -30,6 +30,7 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointLogLocationConfig; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -58,6 +59,7 @@ @Dependency({ "org.mariadb.jdbc:mariadb-java-client:[2.4.0,2.max)", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MARIADB}) @ImportPlugin("com.navercorp.pinpoint:pinpoint-mariadb-jdbc-driver-plugin") +@SharedTestLifeCycleClass(MariaDBServer.class) public class MariaDB_2_4_x_IT extends MariaDB_IT_Base { // see CallableParameterMetaData#queryMetaInfos diff --git a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_IT_Base.java b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_IT_Base.java index 2f7cc876e8f8..5a3768eb4172 100644 --- a/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_IT_Base.java +++ b/plugins-it/mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/MariaDB_IT_Base.java @@ -19,17 +19,11 @@ import com.navercorp.pinpoint.pluginit.jdbc.DriverManagerUtils; import com.navercorp.pinpoint.pluginit.jdbc.DriverProperties; import com.navercorp.pinpoint.pluginit.jdbc.JDBCDriverClass; -import com.navercorp.pinpoint.test.plugin.shared.AfterSharedClass; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; - +import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.After; -import org.junit.Assume; import org.junit.Before; -import org.testcontainers.DockerClientFactory; -import org.testcontainers.containers.MariaDBContainer; -import org.testcontainers.containers.output.OutputFrame; import java.sql.CallableStatement; import java.sql.Connection; @@ -40,7 +34,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; -import java.util.function.Consumer; +import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -50,7 +44,7 @@ */ public abstract class MariaDB_IT_Base { private static final Logger logger = LogManager.getLogger(MariaDB_IT_Base.class); - protected static final String DATABASE_NAME = "test"; + protected static final String DATABASE_NAME = MariaDBServer.DATABASE_NAME; // for Statement protected static final String STATEMENT_QUERY = "SELECT count(1) FROM playground"; @@ -66,64 +60,28 @@ public abstract class MariaDB_IT_Base { protected static final int CALLABLE_STATMENT_OUTPUT_PARAM_TYPE = Types.INTEGER; protected static DriverProperties driverProperties; -// @Rule - public static MariaDBContainer mariaDB = new MariaDBContainer(); - protected static final String USERNAME = "root"; - protected static final String PASSWORD = ""; + protected static final String USERNAME = MariaDBServer.USERNAME; + protected static final String PASSWORD = MariaDBServer.PASSWORD; protected static final String DB_TYPE = "MARIADB"; protected static final String DB_EXECUTE_QUERY = "MARIADB_EXECUTE_QUERY"; - // ---------- For @BeforeSharedClass, @AfterSharedClass // - // for shared test' protected static String JDBC_URL; protected static String URL; - public static String getJdbcUrl() { + public String getJdbcUrl() { return JDBC_URL; } - public static void setJdbcUrl(String jdbcUrl) { - JDBC_URL = jdbcUrl; - } - public static String getURL() { return URL; } - public static void setURL(String URL) { - MariaDB_IT_Base.URL = URL; - } - // ---------- // - - @BeforeSharedClass - public static void sharedSetUp() throws Exception { - Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); - - mariaDB.withLogConsumer(new Consumer() { - @Override - public void accept(OutputFrame outputFrame) { - logger.info(outputFrame.getUtf8String()); - } - }); - mariaDB.withDatabaseName(DATABASE_NAME); - mariaDB.withUsername(USERNAME); - mariaDB.withPassword(PASSWORD); - mariaDB.withInitScript("jdbc/mariadb/init.sql"); -// mariaDB.withUrlParam("noAccessToProcedureBodies", "true"); - mariaDB.start(); - - setJdbcUrl(mariaDB.getJdbcUrl()); - int port = mariaDB.getMappedPort(3306); - setURL(mariaDB.getHost() + ":" + port); - } - - @AfterSharedClass - public static void sharedTearDown() throws Exception { - if (mariaDB != null) { - mariaDB.stop(); - } + @SharedTestBeforeAllResult + public static void setBeforeAllResult(Properties beforeAllResult) { + JDBC_URL = beforeAllResult.getProperty("JDBC_URL"); + URL = beforeAllResult.getProperty("URL"); } abstract JDBCDriverClass getJDBCDriverClass(); diff --git a/plugins-it/mssql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mssql/MSSqlIT.java b/plugins-it/mssql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mssql/MSSqlIT.java index 1268549db5f4..07e29c935e85 100644 --- a/plugins-it/mssql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mssql/MSSqlIT.java +++ b/plugins-it/mssql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mssql/MSSqlIT.java @@ -29,18 +29,14 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointConfig; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; -import com.navercorp.pinpoint.test.plugin.shared.AfterSharedClass; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; - -import org.junit.Assume; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.testcontainers.DockerClientFactory; -import org.testcontainers.containers.MSSQLServerContainer; import java.util.Properties; @@ -56,6 +52,7 @@ JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MSSQL}) @JvmVersion(8) @PinpointConfig("pinpoint-mssql.config") +@SharedTestLifeCycleClass(MsSqlServer.class) public class MSSqlIT extends DataBaseTestCase { private static final String MSSQL = "MSSQL_JDBC"; @@ -68,53 +65,29 @@ public class MSSqlIT extends DataBaseTestCase { private static JDBCApi jdbcApi; private static JdbcUrlParserV2 jdbcUrlParser; - public static final MSSQLServerContainer mssqlserver = MSSQLServerContainerFactory.newMSSQLServerContainer(logger.getName()); - // ---------- For @BeforeSharedClass, @AfterSharedClass // private static String JDBC_URL; - private static String USER_NAME; - private static String PASS_WORD; + private static String USERNAME; + private static String PASSWORD; public static String getJdbcUrl() { return JDBC_URL; } - public static void setJdbcUrl(String jdbcUrl) { - JDBC_URL = jdbcUrl; - } - public static String getUserName() { - return USER_NAME; - } - - public static void setUserName(String userName) { - USER_NAME = userName; + return USERNAME; } public static String getPassWord() { - return PASS_WORD; - } - - public static void setPassWord(String passWord) { - PASS_WORD = passWord; + return PASSWORD; } - // ---------- // - - @BeforeSharedClass - public static void sharedSetup() { - Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); - mssqlserver.start(); - setJdbcUrl(mssqlserver.getJdbcUrl()); - setUserName(mssqlserver.getUsername()); - setPassWord(mssqlserver.getPassword()); - } - @AfterSharedClass - public static void sharedTearDown() { - if (mssqlserver != null) { - mssqlserver.stop(); - } + @SharedTestBeforeAllResult + public static void setBeforeAllResult(Properties beforeAllResult) { + JDBC_URL = beforeAllResult.getProperty("JDBC_URL"); + USERNAME = beforeAllResult.getProperty("USERNAME"); + PASSWORD = beforeAllResult.getProperty("PASSWORD"); } @BeforeClass diff --git a/plugins-it/mssql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mssql/MsSqlServer.java b/plugins-it/mssql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mssql/MsSqlServer.java new file mode 100644 index 000000000000..deba1b2ef06e --- /dev/null +++ b/plugins-it/mssql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mssql/MsSqlServer.java @@ -0,0 +1,37 @@ +package com.navercorp.pinpoint.plugin.jdbc.mssql; + +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle; +import org.junit.Assume; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.DockerClientFactory; +import org.testcontainers.containers.MSSQLServerContainer; + +import java.util.Properties; + +public class MsSqlServer implements SharedTestLifeCycle { + private final Logger logger = LoggerFactory.getLogger(getClass()); + + private MSSQLServerContainer mssqlserver; + + @Override + public Properties beforeAll() { + Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); + + mssqlserver = MSSQLServerContainerFactory.newMSSQLServerContainer(logger.getName()); + mssqlserver.start(); + + Properties properties = new Properties(); + properties.setProperty("JDBC_URL", mssqlserver.getJdbcUrl()); + properties.setProperty("USERNAME", mssqlserver.getUsername()); + properties.setProperty("PASSWORD", mssqlserver.getPassword()); + return properties; + } + + @Override + public void afterAll() { + if (mssqlserver != null) { + mssqlserver.stop(); + } + } +} diff --git a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlConnection_5_X_IT.java b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlConnection_5_X_IT.java index cfa70dd0934a..cf2b04c0c910 100644 --- a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlConnection_5_X_IT.java +++ b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlConnection_5_X_IT.java @@ -28,6 +28,7 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.Assert; @@ -49,6 +50,7 @@ @ImportPlugin("com.navercorp.pinpoint:pinpoint-mysql-jdbc-driver-plugin") @Dependency({"mysql:mysql-connector-java:[5.1.0],[5.1.34],[5.1.36,5.max]", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.7.5", JDBCTestConstants.VERSION, TestcontainersOption.MYSQLDB}) +@SharedTestLifeCycleClass(MySqlServer.class) public class MySqlConnection_5_X_IT extends MySql_IT_Base { private final Logger logger = LogManager.getLogger(this.getClass()); diff --git a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlConnection_6_X_IT.java b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlConnection_6_X_IT.java index 72dcf2cf58e7..3eeb998aa323 100644 --- a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlConnection_6_X_IT.java +++ b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlConnection_6_X_IT.java @@ -28,6 +28,7 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,6 +50,7 @@ @ImportPlugin("com.navercorp.pinpoint:pinpoint-mysql-jdbc-driver-plugin") @Dependency({"mysql:mysql-connector-java:[6.min,6.max]", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.7.5", JDBCTestConstants.VERSION, TestcontainersOption.MYSQLDB}) +@SharedTestLifeCycleClass(MySqlServer.class) public class MySqlConnection_6_X_IT extends MySql_IT_Base { private final Logger logger = LogManager.getLogger(this.getClass()); diff --git a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlLoadBalance_5_X_IT.java b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlLoadBalance_5_X_IT.java index 8788e747147b..f306a3685880 100644 --- a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlLoadBalance_5_X_IT.java +++ b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlLoadBalance_5_X_IT.java @@ -67,7 +67,7 @@ protected JDBCDriverClass getJDBCDriverClass() { public static DriverProperties getDriverProperties() { String loadbalance = UrlUtils.getLoadbalanceUrl(JDBC_URL); - return new DriverProperties(loadbalance, USERNAME, PASSWORD, new Properties()); + return new DriverProperties(loadbalance, MySqlServer.USERNAME, MySqlServer.PASSWORD, new Properties()); } @Test diff --git a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlLoadBalance_6_X_IT.java b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlLoadBalance_6_X_IT.java index 99a62503be1b..45409b81b56f 100644 --- a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlLoadBalance_6_X_IT.java +++ b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlLoadBalance_6_X_IT.java @@ -28,6 +28,7 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -54,6 +55,7 @@ @Dependency({"mysql:mysql-connector-java:[6.min,6.max]", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.7.5", JDBCTestConstants.VERSION, TestcontainersOption.MYSQLDB}) +@SharedTestLifeCycleClass(MySqlServer.class) public class MySqlLoadBalance_6_X_IT extends MySql_IT_Base { private final Logger logger = LogManager.getLogger(this.getClass()); diff --git a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlServer.java b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlServer.java new file mode 100644 index 000000000000..2d3d0c9a4000 --- /dev/null +++ b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlServer.java @@ -0,0 +1,54 @@ +package com.navercorp.pinpoint.plugin.jdbc.mysql; + +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.Assume; +import org.testcontainers.DockerClientFactory; +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.containers.output.OutputFrame; + +import java.util.Properties; +import java.util.function.Consumer; + +public class MySqlServer implements SharedTestLifeCycle { + private final Logger logger = LogManager.getLogger(getClass()); + + public static final String DATABASE_NAME = "test"; + public static final String USERNAME = "root"; + public static final String PASSWORD = ""; + + private MySQLContainer mysqlDB = new MySQLContainer(); + + @Override + public Properties beforeAll() { + Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); + + mysqlDB = new MySQLContainer(); + mysqlDB.withLogConsumer(new Consumer() { + @Override + public void accept(OutputFrame outputFrame) { + logger.info(outputFrame.getUtf8String()); + } + }); + mysqlDB.withDatabaseName(DATABASE_NAME); + mysqlDB.withUsername(USERNAME); + mysqlDB.withPassword(PASSWORD); + mysqlDB.withInitScript("init.sql"); +// mysqlDB. + mysqlDB.withUrlParam("serverTimezone", "UTC"); + mysqlDB.withUrlParam("useSSL", "false"); + mysqlDB.start(); + + Properties properties = new Properties(); + properties.setProperty("JDBC_URL", mysqlDB.getJdbcUrl()); + return properties; + } + + @Override + public void afterAll() { + if (mysqlDB != null) { + mysqlDB.stop(); + } + } +} diff --git a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_5_X_IT.java b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_5_X_IT.java index 70975271292a..beb85563cf74 100644 --- a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_5_X_IT.java +++ b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_5_X_IT.java @@ -26,6 +26,7 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -41,6 +42,7 @@ @ImportPlugin("com.navercorp.pinpoint:pinpoint-mysql-jdbc-driver-plugin") @Dependency({"mysql:mysql-connector-java:[5.min,5.1.9),[5.1.10,5.max]", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.7.5", JDBCTestConstants.VERSION, TestcontainersOption.MYSQLDB}) +@SharedTestLifeCycleClass(MySqlServer.class) public class MySql_5_X_IT extends MySql_IT_Base { private static MySqlItHelper HELPER; diff --git a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_6_X_IT.java b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_6_X_IT.java index 3371566282f8..e72d82c1e64b 100644 --- a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_6_X_IT.java +++ b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_6_X_IT.java @@ -27,6 +27,7 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,6 +46,7 @@ @Dependency({"mysql:mysql-connector-java:[6.min,6.max]", "org.slf4j:slf4j-log4j12:1.7.5", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MYSQLDB}) +@SharedTestLifeCycleClass(MySqlServer.class) public class MySql_6_X_IT extends MySql_IT_Base { private static MySqlItHelper HELPER; diff --git a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_8_X_IT.java b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_8_X_IT.java index 90af6c2db6d7..a8417761066b 100644 --- a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_8_X_IT.java +++ b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_8_X_IT.java @@ -26,6 +26,7 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -41,6 +42,7 @@ @ImportPlugin("com.navercorp.pinpoint:pinpoint-mysql-jdbc-driver-plugin") @Dependency({"mysql:mysql-connector-java:[8.0.11,)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.7.5", JDBCTestConstants.VERSION, TestcontainersOption.MYSQLDB}) +@SharedTestLifeCycleClass(MySqlServer.class) public class MySql_8_X_IT extends MySql_IT_Base { private static MySqlItHelper HELPER; diff --git a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_IT_Base.java b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_IT_Base.java index 0aeacedb5cc5..bed42bda0e4f 100644 --- a/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_IT_Base.java +++ b/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySql_IT_Base.java @@ -19,88 +19,37 @@ import com.navercorp.pinpoint.pluginit.jdbc.DriverManagerUtils; import com.navercorp.pinpoint.pluginit.jdbc.DriverProperties; import com.navercorp.pinpoint.pluginit.jdbc.JDBCDriverClass; -import com.navercorp.pinpoint.test.plugin.shared.AfterSharedClass; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.After; -import org.junit.Assume; import org.junit.Before; -import org.testcontainers.DockerClientFactory; -import org.testcontainers.containers.MySQLContainer; -import org.testcontainers.containers.output.OutputFrame; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; -import java.util.function.Consumer; /** * @author Taejin Koo */ public abstract class MySql_IT_Base { - private static final Logger logger = LogManager.getLogger(MySql_IT_Base.class); - public static MySQLContainer mysqlDB = new MySQLContainer(); + private final Logger logger = LogManager.getLogger(MySql_IT_Base.class); - protected static final String DATABASE_NAME = "test"; - protected static final String USERNAME = "root"; - protected static final String PASSWORD = ""; - - - // ---------- For @BeforeSharedClass, @AfterSharedClass // - // for shared test' protected static String JDBC_URL; - protected static String URL; + protected static final String USERNAME = MySqlServer.USERNAME; + protected static final String PASSWORD = MySqlServer.PASSWORD; public static String getJdbcUrl() { return JDBC_URL; } - public static void setJdbcUrl(String jdbcUrl) { - JDBC_URL = jdbcUrl; - } - - public static String getURL() { - return URL; - } - - public static void setURL(String URL) { - MySql_IT_Base.URL = URL; + @SharedTestBeforeAllResult + public static void setBeforeAllResult(Properties beforeAllResult) { + JDBC_URL = beforeAllResult.getProperty("JDBC_URL"); } - // ---------- // - @BeforeSharedClass - public static void sharedSetUp() throws Exception { - Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); - - mysqlDB.withLogConsumer(new Consumer() { - @Override - public void accept(OutputFrame outputFrame) { - logger.info(outputFrame.getUtf8String()); - } - }); - mysqlDB.withDatabaseName(DATABASE_NAME); - mysqlDB.withUsername(USERNAME); - mysqlDB.withPassword(PASSWORD); - mysqlDB.withInitScript("init.sql"); -// mysqlDB. - mysqlDB.withUrlParam("serverTimezone", "UTC"); - mysqlDB.withUrlParam("useSSL", "false"); - mysqlDB.start(); - - setJdbcUrl(mysqlDB.getJdbcUrl()); - int port = mysqlDB.getMappedPort(3306); - setURL(mysqlDB.getHost() + ":" + port); - } - - @AfterSharedClass - public static void sharedTearDown() throws Exception { - if (mysqlDB != null) { - mysqlDB.stop(); - } - } abstract JDBCDriverClass getJDBCDriverClass(); @@ -121,7 +70,7 @@ public void after() throws Exception { } public static DriverProperties getDriverProperties() { - return new DriverProperties(JDBC_URL, USERNAME, PASSWORD, new Properties()); + return new DriverProperties(JDBC_URL, MySqlServer.USERNAME, MySqlServer.PASSWORD, new Properties()); } } diff --git a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSQLContainerFactory.java b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSQLContainerFactory.java index a787d80ebf97..81d332e65f83 100644 --- a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSQLContainerFactory.java +++ b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSQLContainerFactory.java @@ -18,7 +18,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.testcontainers.containers.JdbcDatabaseContainer; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.output.OutputFrame; @@ -29,7 +28,7 @@ */ public class PostgreSQLContainerFactory { - public static JdbcDatabaseContainer newContainer(String loggerName) { + public static PostgreSQLContainer newContainer(String loggerName) { PostgreSQLContainer container = new PostgreSQLContainer(); container.withInitScript("init_postgresql.sql"); diff --git a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSqlBase.java b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSqlBase.java index d1a0e70a7f6e..d0276c186f14 100644 --- a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSqlBase.java +++ b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSqlBase.java @@ -19,13 +19,11 @@ import com.navercorp.pinpoint.pluginit.jdbc.DriverManagerUtils; import com.navercorp.pinpoint.pluginit.jdbc.DriverProperties; import com.navercorp.pinpoint.pluginit.jdbc.JDBCDriverClass; -import com.navercorp.pinpoint.test.plugin.shared.AfterSharedClass; - +import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.After; import org.junit.Before; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.testcontainers.containers.JdbcDatabaseContainer; import java.sql.Driver; import java.sql.DriverManager; @@ -37,45 +35,29 @@ public abstract class PostgreSqlBase { protected abstract JDBCDriverClass getJDBCDriverClass(); - private static final Logger logger = LogManager.getLogger(PostgreSqlBase.class); - - protected static JdbcDatabaseContainer container; + private final Logger logger = LogManager.getLogger(getClass()); - // ---------- For @BeforeSharedClass, @AfterSharedClass // private static String JDBC_URL; - private static String USER_NAME; - private static String PASS_WORD; + private static String USERNAME; + private static String PASSWORD; public static String getJdbcUrl() { return JDBC_URL; } - public static void setJdbcUrl(String jdbcUrl) { - JDBC_URL = jdbcUrl; - } - public static String getUserName() { - return USER_NAME; - } - - public static void setUserName(String userName) { - USER_NAME = userName; + return USERNAME; } public static String getPassWord() { - return PASS_WORD; - } - - public static void setPassWord(String passWord) { - PASS_WORD = passWord; + return PASSWORD; } - // ---------- // - @AfterSharedClass - public static void sharedTeardown() throws Exception { - if (container != null) { - container.stop(); - } + @SharedTestBeforeAllResult + public static void setBeforeAllResult(Properties beforeAllResult) { + JDBC_URL = beforeAllResult.getProperty("JDBC_URL"); + USERNAME = beforeAllResult.getProperty("USERNAME"); + PASSWORD = beforeAllResult.getProperty("PASSWORD"); } public static DriverProperties getDriverProperties() { diff --git a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSqlServer.java b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSqlServer.java new file mode 100644 index 000000000000..a54d85f17dd0 --- /dev/null +++ b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSqlServer.java @@ -0,0 +1,38 @@ +package com.navercorp.pinpoint.plugin.jdbc.postgresql; + +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.Assume; +import org.testcontainers.DockerClientFactory; +import org.testcontainers.containers.PostgreSQLContainer; + +import java.util.Properties; + +public class PostgreSqlServer implements SharedTestLifeCycle { + private final Logger logger = LogManager.getLogger(getClass()); + + private PostgreSQLContainer postgreSql; + + @Override + public Properties beforeAll() { + Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); + + postgreSql = PostgreSQLContainerFactory.newContainer(logger.getName()); + + postgreSql.start(); + + Properties properties = new Properties(); + properties.setProperty("JDBC_URL", postgreSql.getJdbcUrl()); + properties.setProperty("USERNAME", postgreSql.getUsername()); + properties.setProperty("PASSWORD", postgreSql.getPassword()); + return properties; + } + + @Override + public void afterAll() { + if (postgreSql != null) { + postgreSql.stop(); + } + } +} diff --git a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_9_4_1207_IT.java b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_9_4_1207_IT.java index 4739cc55a471..76364b56dfe5 100644 --- a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_9_4_1207_IT.java +++ b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_9_4_1207_IT.java @@ -25,15 +25,12 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; - -import org.junit.Assume; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.testcontainers.DockerClientFactory; /** * @author HyunGil Jeong @@ -44,25 +41,16 @@ @Dependency({"org.postgresql:postgresql:[9.4.1207,9.4.1208)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.7.5", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.POSTGRESQL}) +@SharedTestLifeCycleClass(PostgreSqlServer.class) public class PostgreSql_9_4_1207_IT extends PostgreSqlBase { - private static final Logger logger = LogManager.getLogger(PostgreSql_9_4_1207_IT.class); + private final Logger logger = LogManager.getLogger(getClass()); private static PostgreSqlItHelper HELPER; private static PostgreSqlJDBCDriverClass driverClass; private static PostgreSqlJDBCApi jdbcApi; - @BeforeSharedClass - public static void sharedSetup() throws Exception { - Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); - container = PostgreSQLContainerFactory.newContainer(logger.getName()); - - container.start(); - setJdbcUrl(container.getJdbcUrl()); - setUserName(container.getUsername()); - setPassWord(container.getPassword()); - } @BeforeClass public static void beforeClass() throws Exception { diff --git a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_9_x_to_9_4_1207_IT.java b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_9_x_to_9_4_1207_IT.java index abaac806b956..4bb51ee07d43 100644 --- a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_9_x_to_9_4_1207_IT.java +++ b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_9_x_to_9_4_1207_IT.java @@ -25,15 +25,12 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; - -import org.junit.Assume; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.testcontainers.DockerClientFactory; /** * @author HyunGil Jeong @@ -44,24 +41,15 @@ @Dependency({"org.postgresql:postgresql:[9.min,9.4.1207)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.7.5", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.POSTGRESQL}) +@SharedTestLifeCycleClass(PostgreSqlServer.class) public class PostgreSql_9_x_to_9_4_1207_IT extends PostgreSqlBase { - private static final Logger logger = LogManager.getLogger(PostgreSql_9_x_to_9_4_1207_IT.class); + private final Logger logger = LogManager.getLogger(getClass()); private static PostgreSqlItHelper HELPER; private static PostgreSqlJDBCDriverClass driverClass; private static PostgreSqlJDBCApi jdbcApi; - @BeforeSharedClass - public static void sharedSetup() { - Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); - container = PostgreSQLContainerFactory.newContainer(logger.getName()); - - container.start(); - setJdbcUrl(container.getJdbcUrl()); - setUserName(container.getUsername()); - setPassWord(container.getPassword()); - } @BeforeClass public static void beforeClass() { diff --git a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_Post_9_4_1208_IT.java b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_Post_9_4_1208_IT.java index 7544343ffbef..501667288694 100644 --- a/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_Post_9_4_1208_IT.java +++ b/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql/PostgreSql_Post_9_4_1208_IT.java @@ -25,16 +25,14 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; -import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass; -import org.junit.AfterClass; +import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; -import org.testcontainers.DockerClientFactory; import java.net.URL; @@ -48,25 +46,16 @@ // JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.POSTGRESQL}) @Dependency({"org.postgresql:postgresql:[9.4.1208,)", JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.POSTGRESQL}) +@SharedTestLifeCycleClass(PostgreSqlServer.class) public class PostgreSql_Post_9_4_1208_IT extends PostgreSqlBase { - private static final Logger logger = LogManager.getLogger(PostgreSql_Post_9_4_1208_IT.class); + private final Logger logger = LogManager.getLogger(getClass()); private static PostgreSqlItHelper HELPER; private static PostgreSqlJDBCDriverClass driverClass; private static PostgreSqlJDBCApi jdbcApi; - @BeforeSharedClass - public static void sharedSetup() throws Exception { - Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); - container = PostgreSQLContainerFactory.newContainer(logger.getName()); - - container.start(); - setJdbcUrl(container.getJdbcUrl()); - setUserName(container.getUsername()); - setPassWord(container.getPassword()); - } @BeforeClass public static void beforeClass() throws Exception { @@ -88,13 +77,6 @@ private static void invalidJarCheck() { Assume.assumeTrue("test skip : invalid jar ", jar != null); } - @AfterClass - public static void afterClass() throws Exception { - if (container != null) { - container.stop(); - } - } - @Override protected JDBCDriverClass getJDBCDriverClass() { return driverClass; diff --git a/plugins-it/spring-it/src/test/java/com/navercorp/pinpoint/plugin/spring/web/HttpWebServer.java b/plugins-it/spring-it/src/test/java/com/navercorp/pinpoint/plugin/spring/web/HttpWebServer.java index e926d55d644b..da5db219a948 100644 --- a/plugins-it/spring-it/src/test/java/com/navercorp/pinpoint/plugin/spring/web/HttpWebServer.java +++ b/plugins-it/spring-it/src/test/java/com/navercorp/pinpoint/plugin/spring/web/HttpWebServer.java @@ -14,7 +14,6 @@ public Properties beforeAll() { webServer = WebServer.newTestWebServer(); Properties properties = new Properties(); - properties.setProperty("ADDRESS", webServer.getCallHttpUrl()); properties.setProperty("HOST_PORT", webServer.getHostAndPort()); return properties; } catch (Exception e) { diff --git a/plugins-it/spring-it/src/test/java/com/navercorp/pinpoint/plugin/spring/web/RestTemplateIT.java b/plugins-it/spring-it/src/test/java/com/navercorp/pinpoint/plugin/spring/web/RestTemplateIT.java index 706d864f3352..ae3dc2adefd0 100644 --- a/plugins-it/spring-it/src/test/java/com/navercorp/pinpoint/plugin/spring/web/RestTemplateIT.java +++ b/plugins-it/spring-it/src/test/java/com/navercorp/pinpoint/plugin/spring/web/RestTemplateIT.java @@ -53,14 +53,14 @@ @SharedTestLifeCycleClass(HttpWebServer.class) public class RestTemplateIT { - private static String ADDRESS; + private static String HOST_PORT; @SharedTestBeforeAllResult public static void setBeforeAllResult(Properties beforeAllResult) { - ADDRESS = beforeAllResult.getProperty("ADDRESS"); + HOST_PORT = beforeAllResult.getProperty("HOST_PORT"); } public static String getCallUrl() { - return ADDRESS; + return "http://" + HOST_PORT; }