Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#8965] Cleanup #8977

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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