File tree 10 files changed +73
-24
lines changed
mariadb-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc
mssql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mssql
mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/mysql
src/main/java/com/navercorp/pinpoint/pluginit/jdbc/testcontainers
postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/postgresql
10 files changed +73
-24
lines changed Original file line number Diff line number Diff line change 1
1
package com .navercorp .pinpoint .plugin .jdbc ;
2
2
3
+ import com .navercorp .pinpoint .pluginit .jdbc .testcontainers .DatabaseContainers ;
3
4
import com .navercorp .pinpoint .test .plugin .shared .SharedTestLifeCycle ;
4
5
import org .apache .logging .log4j .LogManager ;
5
6
import org .apache .logging .log4j .Logger ;
@@ -38,10 +39,8 @@ public void accept(OutputFrame outputFrame) {
38
39
mariaDB .start ();
39
40
40
41
int port = mariaDB .getMappedPort (3306 );
41
- Properties properties = new Properties ();
42
- properties .setProperty ("JDBC_URL" , mariaDB .getJdbcUrl ());
42
+ Properties properties = DatabaseContainers .toProperties (mariaDB );
43
43
properties .setProperty ("URL" , mariaDB .getHost () + ":" + port );
44
-
45
44
return properties ;
46
45
}
47
46
Original file line number Diff line number Diff line change 19
19
import com .navercorp .pinpoint .pluginit .jdbc .DriverManagerUtils ;
20
20
import com .navercorp .pinpoint .pluginit .jdbc .DriverProperties ;
21
21
import com .navercorp .pinpoint .pluginit .jdbc .JDBCDriverClass ;
22
+ import com .navercorp .pinpoint .pluginit .jdbc .testcontainers .DatabaseContainers ;
22
23
import com .navercorp .pinpoint .test .plugin .shared .SharedTestBeforeAllResult ;
23
24
import org .apache .logging .log4j .LogManager ;
24
25
import org .apache .logging .log4j .Logger ;
@@ -80,7 +81,7 @@ public static String getURL() {
80
81
81
82
@ SharedTestBeforeAllResult
82
83
public static void setBeforeAllResult (Properties beforeAllResult ) {
83
- JDBC_URL = beforeAllResult . getProperty ( "JDBC_URL" );
84
+ JDBC_URL = DatabaseContainers . getJdbcUrl ( beforeAllResult );
84
85
URL = beforeAllResult .getProperty ("URL" );
85
86
}
86
87
Original file line number Diff line number Diff line change 22
22
import com .navercorp .pinpoint .pluginit .jdbc .JDBCApi ;
23
23
import com .navercorp .pinpoint .pluginit .jdbc .JDBCDriverClass ;
24
24
import com .navercorp .pinpoint .pluginit .jdbc .JDBCTestConstants ;
25
+ import com .navercorp .pinpoint .pluginit .jdbc .testcontainers .DatabaseContainers ;
25
26
import com .navercorp .pinpoint .pluginit .utils .AgentPath ;
26
27
import com .navercorp .pinpoint .pluginit .utils .TestcontainersOption ;
27
28
import com .navercorp .pinpoint .test .plugin .Dependency ;
@@ -85,9 +86,9 @@ public static String getPassWord() {
85
86
86
87
@ SharedTestBeforeAllResult
87
88
public static void setBeforeAllResult (Properties beforeAllResult ) {
88
- JDBC_URL = beforeAllResult . getProperty ( "JDBC_URL" );
89
- USERNAME = beforeAllResult . getProperty ( "USERNAME" );
90
- PASSWORD = beforeAllResult . getProperty ( "PASSWORD" );
89
+ JDBC_URL = DatabaseContainers . getJdbcUrl ( beforeAllResult );
90
+ USERNAME = DatabaseContainers . getUsername ( beforeAllResult );
91
+ PASSWORD = DatabaseContainers . getPassword ( beforeAllResult );
91
92
}
92
93
93
94
@ BeforeClass
Original file line number Diff line number Diff line change 1
1
package com .navercorp .pinpoint .plugin .jdbc .mssql ;
2
2
3
+ import com .navercorp .pinpoint .pluginit .jdbc .testcontainers .DatabaseContainers ;
3
4
import com .navercorp .pinpoint .test .plugin .shared .SharedTestLifeCycle ;
4
5
import org .junit .Assume ;
5
6
import org .slf4j .Logger ;
@@ -21,11 +22,7 @@ public Properties beforeAll() {
21
22
mssqlserver = MSSQLServerContainerFactory .newMSSQLServerContainer (logger .getName ());
22
23
mssqlserver .start ();
23
24
24
- Properties properties = new Properties ();
25
- properties .setProperty ("JDBC_URL" , mssqlserver .getJdbcUrl ());
26
- properties .setProperty ("USERNAME" , mssqlserver .getUsername ());
27
- properties .setProperty ("PASSWORD" , mssqlserver .getPassword ());
28
- return properties ;
25
+ return DatabaseContainers .toProperties (mssqlserver );
29
26
}
30
27
31
28
@ Override
Original file line number Diff line number Diff line change 1
1
package com .navercorp .pinpoint .plugin .jdbc .mysql ;
2
2
3
+ import com .navercorp .pinpoint .pluginit .jdbc .testcontainers .DatabaseContainers ;
3
4
import com .navercorp .pinpoint .test .plugin .shared .SharedTestLifeCycle ;
4
5
import org .apache .logging .log4j .LogManager ;
5
6
import org .apache .logging .log4j .Logger ;
@@ -40,9 +41,7 @@ public void accept(OutputFrame outputFrame) {
40
41
mysqlDB .withUrlParam ("useSSL" , "false" );
41
42
mysqlDB .start ();
42
43
43
- Properties properties = new Properties ();
44
- properties .setProperty ("JDBC_URL" , mysqlDB .getJdbcUrl ());
45
- return properties ;
44
+ return DatabaseContainers .toProperties (mysqlDB );
46
45
}
47
46
48
47
@ Override
Original file line number Diff line number Diff line change 19
19
import com .navercorp .pinpoint .pluginit .jdbc .DriverManagerUtils ;
20
20
import com .navercorp .pinpoint .pluginit .jdbc .DriverProperties ;
21
21
import com .navercorp .pinpoint .pluginit .jdbc .JDBCDriverClass ;
22
+ import com .navercorp .pinpoint .pluginit .jdbc .testcontainers .DatabaseContainers ;
22
23
import com .navercorp .pinpoint .test .plugin .shared .SharedTestBeforeAllResult ;
23
24
import org .apache .logging .log4j .LogManager ;
24
25
import org .apache .logging .log4j .Logger ;
@@ -47,7 +48,7 @@ public static String getJdbcUrl() {
47
48
48
49
@ SharedTestBeforeAllResult
49
50
public static void setBeforeAllResult (Properties beforeAllResult ) {
50
- JDBC_URL = beforeAllResult . getProperty ( "JDBC_URL" );
51
+ JDBC_URL = DatabaseContainers . getJdbcUrl ( beforeAllResult );
51
52
}
52
53
53
54
Original file line number Diff line number Diff line change 49
49
<artifactId >junit</artifactId >
50
50
<scope >provided</scope >
51
51
</dependency >
52
+ <dependency >
53
+ <groupId >org.testcontainers</groupId >
54
+ <artifactId >testcontainers</artifactId >
55
+ <version >${testcontainers.version} </version >
56
+ <optional >true</optional >
57
+ <scope >compile</scope >
58
+ </dependency >
59
+ <dependency >
60
+ <groupId >org.testcontainers</groupId >
61
+ <artifactId >jdbc</artifactId >
62
+ <version >${testcontainers.version} </version >
63
+ <optional >true</optional >
64
+ <scope >compile</scope >
65
+ </dependency >
52
66
</dependencies >
53
67
54
68
<build >
Original file line number Diff line number Diff line change
1
+ package com .navercorp .pinpoint .pluginit .jdbc .testcontainers ;
2
+
3
+ import org .testcontainers .containers .JdbcDatabaseContainer ;
4
+
5
+ import java .util .Objects ;
6
+ import java .util .Properties ;
7
+
8
+ public final class DatabaseContainers {
9
+
10
+ public static final String JDBC_URL = "JDBC_URL" ;
11
+ public static final String USERNAME = "USERNAME" ;
12
+ public static final String PASSWORD = "PASSWORD" ;
13
+
14
+ private DatabaseContainers () {
15
+ }
16
+
17
+ public static Properties toProperties (JdbcDatabaseContainer container ) {
18
+ Objects .requireNonNull (container , "container" );
19
+
20
+ Properties properties = new Properties ();
21
+ properties .setProperty (JDBC_URL , container .getJdbcUrl ());
22
+ properties .setProperty (USERNAME , container .getUsername ());
23
+ properties .setProperty (PASSWORD , container .getPassword ());
24
+ return properties ;
25
+ }
26
+
27
+ public static String getJdbcUrl (Properties p ) {
28
+ return p .getProperty (JDBC_URL );
29
+ }
30
+
31
+ public static String getUsername (Properties p ) {
32
+ return p .getProperty (USERNAME );
33
+ }
34
+
35
+ public static String getPassword (Properties p ) {
36
+ return p .getProperty (PASSWORD );
37
+ }
38
+
39
+ }
Original file line number Diff line number Diff line change 19
19
import com .navercorp .pinpoint .pluginit .jdbc .DriverManagerUtils ;
20
20
import com .navercorp .pinpoint .pluginit .jdbc .DriverProperties ;
21
21
import com .navercorp .pinpoint .pluginit .jdbc .JDBCDriverClass ;
22
+ import com .navercorp .pinpoint .pluginit .jdbc .testcontainers .DatabaseContainers ;
22
23
import com .navercorp .pinpoint .test .plugin .shared .SharedTestBeforeAllResult ;
23
24
import org .apache .logging .log4j .LogManager ;
24
25
import org .apache .logging .log4j .Logger ;
@@ -55,9 +56,9 @@ public static String getPassWord() {
55
56
56
57
@ SharedTestBeforeAllResult
57
58
public static void setBeforeAllResult (Properties beforeAllResult ) {
58
- JDBC_URL = beforeAllResult . getProperty ( "JDBC_URL" );
59
- USERNAME = beforeAllResult . getProperty ( "USERNAME" );
60
- PASSWORD = beforeAllResult . getProperty ( "PASSWORD" );
59
+ JDBC_URL = DatabaseContainers . getJdbcUrl ( beforeAllResult );
60
+ USERNAME = DatabaseContainers . getUsername ( beforeAllResult );
61
+ PASSWORD = DatabaseContainers . getPassword ( beforeAllResult );
61
62
}
62
63
63
64
public static DriverProperties getDriverProperties () {
Original file line number Diff line number Diff line change 1
1
package com .navercorp .pinpoint .plugin .jdbc .postgresql ;
2
2
3
+ import com .navercorp .pinpoint .pluginit .jdbc .testcontainers .DatabaseContainers ;
3
4
import com .navercorp .pinpoint .test .plugin .shared .SharedTestLifeCycle ;
4
5
import org .apache .logging .log4j .LogManager ;
5
6
import org .apache .logging .log4j .Logger ;
@@ -22,11 +23,7 @@ public Properties beforeAll() {
22
23
23
24
postgreSql .start ();
24
25
25
- Properties properties = new Properties ();
26
- properties .setProperty ("JDBC_URL" , postgreSql .getJdbcUrl ());
27
- properties .setProperty ("USERNAME" , postgreSql .getUsername ());
28
- properties .setProperty ("PASSWORD" , postgreSql .getPassword ());
29
- return properties ;
26
+ return DatabaseContainers .toProperties (postgreSql );
30
27
}
31
28
32
29
@ Override
You can’t perform that action at this time.
0 commit comments