Skip to content

Commit

Permalink
[pinpoint-apm#8965] Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jun 24, 2022
1 parent ffe9556 commit 675fd1b
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.navercorp.pinpoint.plugin.jdbc;

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;
Expand Down Expand Up @@ -38,10 +39,8 @@ public void accept(OutputFrame outputFrame) {
mariaDB.start();

int port = mariaDB.getMappedPort(3306);
Properties properties = new Properties();
properties.setProperty("JDBC_URL", mariaDB.getJdbcUrl());
Properties properties = DatabaseContainers.toProperties(mariaDB);
properties.setProperty("URL", mariaDB.getHost() + ":" + port);

return properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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.pluginit.jdbc.testcontainers.DatabaseContainers;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -80,7 +81,7 @@ public static String getURL() {

@SharedTestBeforeAllResult
public static void setBeforeAllResult(Properties beforeAllResult) {
JDBC_URL = beforeAllResult.getProperty("JDBC_URL");
JDBC_URL = DatabaseContainers.getJdbcUrl(beforeAllResult);
URL = beforeAllResult.getProperty("URL");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.navercorp.pinpoint.pluginit.jdbc.JDBCApi;
import com.navercorp.pinpoint.pluginit.jdbc.JDBCDriverClass;
import com.navercorp.pinpoint.pluginit.jdbc.JDBCTestConstants;
import com.navercorp.pinpoint.pluginit.jdbc.testcontainers.DatabaseContainers;
import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.pluginit.utils.TestcontainersOption;
import com.navercorp.pinpoint.test.plugin.Dependency;
Expand Down Expand Up @@ -85,9 +86,9 @@ public static String getPassWord() {

@SharedTestBeforeAllResult
public static void setBeforeAllResult(Properties beforeAllResult) {
JDBC_URL = beforeAllResult.getProperty("JDBC_URL");
USERNAME = beforeAllResult.getProperty("USERNAME");
PASSWORD = beforeAllResult.getProperty("PASSWORD");
JDBC_URL = DatabaseContainers.getJdbcUrl(beforeAllResult);
USERNAME = DatabaseContainers.getUsername(beforeAllResult);
PASSWORD = DatabaseContainers.getPassword(beforeAllResult);
}

@BeforeClass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.navercorp.pinpoint.plugin.jdbc.mssql;

import com.navercorp.pinpoint.pluginit.jdbc.testcontainers.DatabaseContainers;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle;
import org.junit.Assume;
import org.slf4j.Logger;
Expand All @@ -21,11 +22,7 @@ public Properties beforeAll() {
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;
return DatabaseContainers.toProperties(mssqlserver);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.navercorp.pinpoint.plugin.jdbc.mysql;

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;
Expand Down Expand Up @@ -40,9 +41,7 @@ public void accept(OutputFrame outputFrame) {
mysqlDB.withUrlParam("useSSL", "false");
mysqlDB.start();

Properties properties = new Properties();
properties.setProperty("JDBC_URL", mysqlDB.getJdbcUrl());
return properties;
return DatabaseContainers.toProperties(mysqlDB);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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.pluginit.jdbc.testcontainers.DatabaseContainers;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -47,7 +48,7 @@ public static String getJdbcUrl() {

@SharedTestBeforeAllResult
public static void setBeforeAllResult(Properties beforeAllResult) {
JDBC_URL = beforeAllResult.getProperty("JDBC_URL");
JDBC_URL = DatabaseContainers.getJdbcUrl(beforeAllResult);
}


Expand Down
14 changes: 14 additions & 0 deletions plugins-it/plugins-it-jdbc-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@
<artifactId>junit</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>jdbc</artifactId>
<version>${testcontainers.version}</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.navercorp.pinpoint.pluginit.jdbc;

import com.navercorp.pinpoint.common.util.PropertyUtils;
import org.testcontainers.containers.JdbcDatabaseContainer;

import java.io.IOException;
import java.util.Properties;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.navercorp.pinpoint.pluginit.jdbc.testcontainers;

import org.testcontainers.containers.JdbcDatabaseContainer;

import java.util.Objects;
import java.util.Properties;

public final class DatabaseContainers {

public static final String JDBC_URL = "JDBC_URL";
public static final String USERNAME = "USERNAME";
public static final String PASSWORD = "PASSWORD";

private DatabaseContainers() {
}

public static Properties toProperties(JdbcDatabaseContainer container) {
Objects.requireNonNull(container, "container");

Properties properties = new Properties();
properties.setProperty(JDBC_URL, container.getJdbcUrl());
properties.setProperty(USERNAME, container.getUsername());
properties.setProperty(PASSWORD, container.getPassword());
return properties;
}

public static String getJdbcUrl(Properties p) {
return p.getProperty(JDBC_URL);
}

public static String getUsername(Properties p) {
return p.getProperty(USERNAME);
}

public static String getPassword(Properties p) {
return p.getProperty(PASSWORD);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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.pluginit.jdbc.testcontainers.DatabaseContainers;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -55,9 +56,9 @@ public static String getPassWord() {

@SharedTestBeforeAllResult
public static void setBeforeAllResult(Properties beforeAllResult) {
JDBC_URL = beforeAllResult.getProperty("JDBC_URL");
USERNAME = beforeAllResult.getProperty("USERNAME");
PASSWORD = beforeAllResult.getProperty("PASSWORD");
JDBC_URL = DatabaseContainers.getJdbcUrl(beforeAllResult);
USERNAME = DatabaseContainers.getUsername(beforeAllResult);
PASSWORD = DatabaseContainers.getPassword(beforeAllResult);
}

public static DriverProperties getDriverProperties() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.navercorp.pinpoint.plugin.jdbc.postgresql;

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;
Expand All @@ -22,11 +23,7 @@ public Properties beforeAll() {

postgreSql.start();

Properties properties = new Properties();
properties.setProperty("JDBC_URL", postgreSql.getJdbcUrl());
properties.setProperty("USERNAME", postgreSql.getUsername());
properties.setProperty("PASSWORD", postgreSql.getPassword());
return properties;
return DatabaseContainers.toProperties(postgreSql);
}

@Override
Expand Down

0 comments on commit 675fd1b

Please sign in to comment.