Skip to content

Commit

Permalink
[#8965] Apply SharedTestLifeCycle to MariaDB
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jun 24, 2022
1 parent 3e53062 commit f963fb9
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -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<OutputFrame>() {
@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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@
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;
import com.navercorp.pinpoint.test.plugin.JvmVersion;
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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand All @@ -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<OutputFrame>() {
@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();
Expand Down

0 comments on commit f963fb9

Please sign in to comment.