Skip to content

Commit

Permalink
[#8965] Apply SharedTestLifeCycle to Oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jun 28, 2022
1 parent e6e26b4 commit a22f54f
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,29 @@
import com.navercorp.pinpoint.pluginit.jdbc.DriverProperties;
import com.navercorp.pinpoint.pluginit.jdbc.JDBCTestConstants;
import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.pluginit.utils.PluginITConstants;
import com.navercorp.pinpoint.test.plugin.Dependency;
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.Repository;
import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass;

import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass;
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.containers.wait.strategy.Wait;

@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent(AgentPath.PATH)
@Dependency({"com.oracle.database.jdbc:ojdbc6:(,)", JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER_15_3})
@Dependency({"com.oracle.database.jdbc:ojdbc6:(,)", PluginITConstants.VERSION, JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER_15_3})
@ImportPlugin("com.navercorp.pinpoint:pinpoint-oracle-jdbc-driver-plugin")
@SharedTestLifeCycleClass(OracleServer11x.class)
public class Oracle11_Ojdbc6_IT extends Oracle_IT_Base {
private static final Logger logger = LogManager.getLogger(Oracle11_Ojdbc6_IT.class);

@BeforeSharedClass
public static void sharedSetup() throws Exception {
logger.info("Setting up oracle db...");
startOracleDB(OracleITConstants.ORACLE_11_X_IMAGE, Wait.defaultWaitStrategy());
}
private final Logger logger = LogManager.getLogger(Oracle11_Ojdbc6_IT.class);

@BeforeClass
public static void setup() throws Exception {
public static void setup() {
DriverProperties driverProperties = createDriverProperties();
helper = new OracleItHelper(driverProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,29 @@
import com.navercorp.pinpoint.pluginit.jdbc.DriverProperties;
import com.navercorp.pinpoint.pluginit.jdbc.JDBCTestConstants;
import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.pluginit.utils.PluginITConstants;
import com.navercorp.pinpoint.test.plugin.Dependency;
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.Repository;
import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass;

import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass;
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.containers.wait.strategy.Wait;

@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent(AgentPath.PATH)
@Dependency({"com.oracle.database.jdbc:ojdbc8:[12,19)", JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER_15_3})
@Dependency({"com.oracle.database.jdbc:ojdbc8:[12,19)", PluginITConstants.VERSION, JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER_15_3})
@ImportPlugin("com.navercorp.pinpoint:pinpoint-oracle-jdbc-driver-plugin")
@SharedTestLifeCycleClass(OracleServer12x.class)
public class Oracle12_18_Ojdbc8_IT extends Oracle_IT_Base{
private static final Logger logger = LogManager.getLogger(Oracle12_18_Ojdbc8_IT.class);

@BeforeSharedClass
public static void sharedSetup() throws Exception {
logger.info("Setting up oracle db...");

startOracleDB(OracleITConstants.ORACLE_12_X_IMAGE, Wait.forLogMessage(".*Database ready to use.*\\n", 1));
}
private final Logger logger = LogManager.getLogger(Oracle12_18_Ojdbc8_IT.class);

@BeforeClass
public static void setup() throws Exception {
public static void setup() {
DriverProperties driverProperties = createDriverProperties();
helper = new OracleItHelper(driverProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,31 @@

import com.navercorp.pinpoint.pluginit.jdbc.*;
import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.test.plugin.*;
import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass;
import com.navercorp.pinpoint.pluginit.utils.PluginITConstants;

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.PinpointPluginTestSuite;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass;
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.containers.wait.strategy.Wait;

@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent(AgentPath.PATH)
@Dependency({"com.oracle.database.jdbc:ojdbc10:[19.9,)", JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER})
@Dependency({"com.oracle.database.jdbc:ojdbc10:[19.9,)", PluginITConstants.VERSION, JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER})
@JvmVersion(11)
@ImportPlugin("com.navercorp.pinpoint:pinpoint-oracle-jdbc-driver-plugin")
@SharedTestLifeCycleClass(OracleServer19x.class)
public class Oracle19_Ojdbc10_IT extends Oracle_IT_Base {
private static final Logger logger = LogManager.getLogger(Oracle19_Ojdbc10_IT.class);

@BeforeSharedClass
public static void sharedSetup() throws Exception {
logger.info("Setting up oracle db...");
startOracleDB(OracleITConstants.ORACLE_18_X_IMAGE, Wait.forLogMessage(".*Completed.*", 1));
}
private final Logger logger = LogManager.getLogger(Oracle19_Ojdbc10_IT.class);

@BeforeClass
public static void setup() throws Exception {
public static void setup() {
DriverProperties driverProperties = createDriverProperties();
helper = new OracleItHelper(driverProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,30 @@
import com.navercorp.pinpoint.pluginit.jdbc.DriverProperties;
import com.navercorp.pinpoint.pluginit.jdbc.JDBCTestConstants;
import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.test.plugin.*;
import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass;

import com.navercorp.pinpoint.pluginit.utils.PluginITConstants;
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.PinpointPluginTestSuite;
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.containers.wait.strategy.Wait;

@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent(AgentPath.PATH)
@Dependency({"com.oracle.database.jdbc:ojdbc10:[19,19.9)", JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER})
@Dependency({"com.oracle.database.jdbc:ojdbc10:[19,19.9)", PluginITConstants.VERSION, JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER})
@JvmVersion(11)
@ImportPlugin("com.navercorp.pinpoint:pinpoint-oracle-jdbc-driver-plugin")
@SharedTestLifeCycleClass(OracleServer19x.class)
public class Oracle19_Ojdbc10_IT_ConnectWithGssCredential_IT extends Oracle_IT_Base {
private static final Logger logger = LogManager.getLogger(Oracle19_Ojdbc10_IT_ConnectWithGssCredential_IT.class);

@BeforeSharedClass
public static void sharedSetup() throws Exception {
logger.info("Setting up oracle db...");
startOracleDB(OracleITConstants.ORACLE_18_X_IMAGE, Wait.forLogMessage(".*Completed.*", 1));
}
private final Logger logger = LogManager.getLogger(Oracle19_Ojdbc10_IT_ConnectWithGssCredential_IT.class);

@BeforeClass
public static void setup() throws Exception {
public static void setup() {
DriverProperties driverProperties = createDriverProperties();
helper = new OracleItHelper(driverProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,31 @@
*/
package com.navercorp.pinpoint.plugin.jdbc.oracle;

import com.navercorp.pinpoint.pluginit.jdbc.*;
import com.navercorp.pinpoint.pluginit.jdbc.DriverProperties;
import com.navercorp.pinpoint.pluginit.jdbc.JDBCTestConstants;
import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.test.plugin.*;
import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass;

import com.navercorp.pinpoint.pluginit.utils.PluginITConstants;
import com.navercorp.pinpoint.test.plugin.Dependency;
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.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.containers.wait.strategy.Wait;

@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent(AgentPath.PATH)
@Dependency({"com.oracle.database.jdbc:ojdbc8:[19,19.9)", JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER})
@Dependency({"com.oracle.database.jdbc:ojdbc8:[19,19.9)", PluginITConstants.VERSION, JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER})
@ImportPlugin("com.navercorp.pinpoint:pinpoint-oracle-jdbc-driver-plugin")
@SharedTestLifeCycleClass(OracleServer19x.class)
public class Oracle19_Ojdbc8_ConnectWithGssCredential_IT extends Oracle_IT_Base {
private static final Logger logger = LogManager.getLogger(Oracle19_Ojdbc8_ConnectWithGssCredential_IT.class);

@BeforeSharedClass
public static void sharedSetup() throws Exception {
logger.info("Setting up oracle db...");
startOracleDB(OracleITConstants.ORACLE_18_X_IMAGE, Wait.forLogMessage(".*Completed.*", 1));
}
private final Logger logger = LogManager.getLogger(Oracle19_Ojdbc8_ConnectWithGssCredential_IT.class);

@BeforeClass
public static void setup() throws Exception {
public static void setup() {
DriverProperties driverProperties = createDriverProperties();
helper = new OracleItHelper(driverProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,31 @@
*/
package com.navercorp.pinpoint.plugin.jdbc.oracle;

import com.navercorp.pinpoint.pluginit.jdbc.*;
import com.navercorp.pinpoint.pluginit.jdbc.DriverProperties;
import com.navercorp.pinpoint.pluginit.jdbc.JDBCTestConstants;
import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.test.plugin.*;
import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass;

import com.navercorp.pinpoint.pluginit.utils.PluginITConstants;
import com.navercorp.pinpoint.test.plugin.Dependency;
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.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.containers.wait.strategy.Wait;

@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent(AgentPath.PATH)
@Dependency({"com.oracle.database.jdbc:ojdbc8:[19.9,)", JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER})
@Dependency({"com.oracle.database.jdbc:ojdbc8:[19.9,)", PluginITConstants.VERSION, JDBCTestConstants.VERSION, OracleITConstants.ORACLE_TESTCONTAINER})
@ImportPlugin("com.navercorp.pinpoint:pinpoint-oracle-jdbc-driver-plugin")
@SharedTestLifeCycleClass(OracleServer19x.class)
public class Oracle19_Ojdbc8_IT extends Oracle_IT_Base {
private static final Logger logger = LogManager.getLogger(Oracle19_Ojdbc8_IT.class);

@BeforeSharedClass
public static void sharedSetup() throws Exception {
logger.info("Setting up oracle db...");
startOracleDB(OracleITConstants.ORACLE_18_X_IMAGE, Wait.forLogMessage(".*Completed.*", 1));
}
private final Logger logger = LogManager.getLogger(Oracle19_Ojdbc8_IT.class);

@BeforeClass
public static void setup() throws Exception {
public static void setup() {
DriverProperties driverProperties = createDriverProperties();
helper = new OracleItHelper(driverProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void create(JDBCApi jdbcApi) throws Exception {
statement.execute("CREATE OR REPLACE TRIGGER test_trigger BEFORE INSERT ON test FOR EACH ROW BEGIN SELECT test_seq.nextval INTO :new.id FROM dual; END;");
statement.execute("CREATE OR REPLACE PROCEDURE concatCharacters(a IN VARCHAR2, b IN VARCHAR2, c OUT VARCHAR2) AS BEGIN c := a || b; END concatCharacters;");
statement.execute("CREATE OR REPLACE PROCEDURE swapAndGetSum(a IN OUT NUMBER, b IN OUT NUMBER, c OUT NUMBER) IS BEGIN c := a; a := b; b := c; SELECT c + a INTO c FROM DUAL; END swapAndGetSum;");
statement.close();
conn.commit();
conn.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.navercorp.pinpoint.plugin.jdbc.oracle;

import com.navercorp.pinpoint.pluginit.jdbc.DriverProperties;
import com.navercorp.pinpoint.pluginit.jdbc.JDBCDriverClass;
import com.navercorp.pinpoint.pluginit.jdbc.testcontainers.DatabaseContainers;
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.OracleContainer;
import org.testcontainers.containers.wait.strategy.WaitStrategy;

import java.time.Duration;
import java.util.Objects;
import java.util.Properties;

public class OracleServer implements SharedTestLifeCycle {
private final Logger logger = LogManager.getLogger(getClass());
private final String dockerImageVersion;
private final WaitStrategy waitStrategy;

private OracleContainer oracle;

public OracleServer(String dockerImageVersion, WaitStrategy waitStrategy) {
this.dockerImageVersion = Objects.requireNonNull(dockerImageVersion, "dockerImageVersion");
this.waitStrategy = Objects.requireNonNull(waitStrategy, "waitStrategy");
}

@Override
public Properties beforeAll() {
Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable());

logger.info("Setting up oracle db... {}", dockerImageVersion);

startOracleDB(dockerImageVersion, waitStrategy);
logger.info("initSchema");
initSchema();


return DatabaseContainers.toProperties(oracle);
}

private void initSchema() {
DriverProperties driverProperties = new DriverProperties(oracle.getJdbcUrl(), oracle.getUsername(), oracle.getPassword(), new Properties());
OracleItHelper helper = new OracleItHelper(driverProperties);
JDBCDriverClass driverClass = new OracleJDBCDriverClass();
OracleJDBCApi JDBC_API = new OracleJDBCApi(driverClass);
try {
helper.create(JDBC_API);
} catch (Exception e) {
throw new RuntimeException("schema init error", e);
}
}

private void startOracleDB(String dockerImageVersion, WaitStrategy waitStrategy) {
Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable());
oracle = new OracleContainerWithWait(dockerImageVersion);

if (waitStrategy != null) {
oracle.setWaitStrategy(waitStrategy);
oracle.withStartupTimeout(Duration.ofSeconds(300));
oracle.addEnv("DBCA_ADDITIONAL_PARAMS", "-initParams sga_target=0M pga_aggreegate_target=0M");
oracle.withReuse(true);
}

oracle.start();
}

@Override
public void afterAll() {
if (oracle != null) {
oracle.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.navercorp.pinpoint.plugin.jdbc.oracle;

import org.testcontainers.containers.wait.strategy.Wait;

public class OracleServer11x extends OracleServer {
public OracleServer11x() {
super(OracleITConstants.ORACLE_11_X_IMAGE, Wait.defaultWaitStrategy());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.navercorp.pinpoint.plugin.jdbc.oracle;

import org.testcontainers.containers.wait.strategy.Wait;

public class OracleServer12x extends OracleServer {
public OracleServer12x() {
super(OracleITConstants.ORACLE_12_X_IMAGE, Wait.forLogMessage(".*Database ready to use.*\\n", 1));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.navercorp.pinpoint.plugin.jdbc.oracle;

import org.testcontainers.containers.wait.strategy.Wait;

public class OracleServer19x extends OracleServer {
public OracleServer19x() {
super(OracleITConstants.ORACLE_18_X_IMAGE, Wait.forLogMessage(".*Completed.*", 1));
}

}
Loading

0 comments on commit a22f54f

Please sign in to comment.