-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#8965] Apply SharedTestLifeCycle to Jtds
- Loading branch information
Showing
2 changed files
with
59 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
plugins-it/jtds-it/src/test/java/com/navercorp/pinpoint/plugin/jdbc/jtds/MsSqlServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.navercorp.pinpoint.plugin.jdbc.jtds; | ||
|
||
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle; | ||
import org.junit.Assume; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.DockerClientFactory; | ||
import org.testcontainers.containers.MSSQLServerContainer; | ||
import org.testcontainers.containers.output.OutputFrame; | ||
|
||
import java.util.Properties; | ||
import java.util.function.Consumer; | ||
|
||
public class MsSqlServer implements SharedTestLifeCycle { | ||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
private MSSQLServerContainer mssqlserver; | ||
@Override | ||
public Properties beforeAll() { | ||
Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); | ||
|
||
mssqlserver = new MSSQLServerContainer("mcr.microsoft.com/mssql/server:2019-latest"); | ||
mssqlserver.addEnv("ACCEPT_EULA", "y"); | ||
mssqlserver.withInitScript("sql/init_mssql.sql"); | ||
mssqlserver.withPassword(JtdsITConstants.PASSWORD); | ||
|
||
|
||
mssqlserver.withLogConsumer(new Consumer<OutputFrame>() { | ||
@Override | ||
public void accept(OutputFrame outputFrame) { | ||
logger.info(outputFrame.getUtf8String()); | ||
} | ||
}); | ||
mssqlserver.start(); | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty("JDBC_URL", mssqlserver.getJdbcUrl()); | ||
return properties; | ||
} | ||
|
||
@Override | ||
public void afterAll() { | ||
if (mssqlserver != null) { | ||
mssqlserver.stop(); | ||
} | ||
} | ||
} |