Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
laglangyue committed Oct 18, 2022
1 parent 7e3b5ef commit c09599e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
7 changes: 6 additions & 1 deletion seatunnel-connectors-v2/connector-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
<version>${oracle.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc</artifactId>
<version>${db2.version}</version>
<scope>provided</scope>
</dependency>

</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -112,7 +118,6 @@
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc</artifactId>
<version>${db2.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
<artifactId>ojdbc8</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,36 @@ public class JdbcDb2IT extends TestSuiteBase implements TestResource {
* <a href="https://hub.docker.com/r/ibmcom/db2">db2 in dockerhub</a>
*/
private static final String IMAGE = "ibmcom/db2:latest";
private static final String HOST = "spark_e2e_db2";
private static final String HOST = "e2e_db2";
private static final int PORT = 50000;
private static final int LOCAL_PORT = 50000;
private static final int LOCAL_PORT = 50001;
private static final String USER = "DB2INST1";
private static final String PASSWORD = "123456";
private static final String DRIVER = "com.ibm.db2.jcc.DB2Driver";

private static final String DATABASE = "testdb";
private static final String DATABASE = "E2E";
private static final String SOURCE_TABLE = "E2E_TABLE_SOURCE";
private static final String SINK_TABLE = "E2E_TABLE_SINK";
private String jdbcUrl;
private GenericContainer<?> dbserver;
private GenericContainer<?> dbServer;
private Connection jdbcConnection;

@BeforeAll
@Override
public void startUp() throws Exception {
dbserver = new GenericContainer<>(IMAGE)
.withNetwork(TestContainer.NETWORK)
dbServer = new GenericContainer<>(IMAGE)
.withNetwork(NETWORK)
.withNetworkAliases(HOST)
.withPrivilegedMode(true)
.withLogConsumer(new Slf4jLogConsumer(LOG))
.withEnv("DB2INST1_PASSWORD", PASSWORD)
.withEnv("DBNAME", DATABASE)
.withEnv("LICENSE", "accept")
.withSharedMemorySize(4 * 1024 * 1024 * 1024L)
;
dbserver.setPortBindings(Lists.newArrayList(String.format("%s:%s", LOCAL_PORT, PORT)));
Startables.deepStart(Stream.of(dbserver)).join();
jdbcUrl = String.format("jdbc:db2://%s:%s/%s", dbserver.getHost(), LOCAL_PORT, DATABASE);
dbServer.setPortBindings(Lists.newArrayList(String.format("%s:%s", LOCAL_PORT, PORT)));
Startables.deepStart(Stream.of(dbServer)).join();
jdbcUrl = String.format("jdbc:db2://%s:%s/%s", dbServer.getHost(), LOCAL_PORT, DATABASE);
LOG.info("DB2 container started");
given().ignoreExceptions()
.await()
Expand All @@ -82,8 +83,8 @@ public void tearDown() throws Exception {
if (jdbcConnection != null) {
jdbcConnection.close();
}
if (dbserver != null) {
dbserver.close();
if (dbServer != null) {
dbServer.close();
}
}

Expand Down Expand Up @@ -127,11 +128,7 @@ private void initializeJdbcTable() {
}
}

private void assertHasData(String table) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
if(jdbcConnection.isValid(10)){
initializeJdbcConnection();
}

private void assertHasData(String table) {
try (Statement statement = jdbcConnection.createStatement()) {
String sql = String.format("select * from \"%s\".%s", USER, table);
ResultSet source = statement.executeQuery(sql);
Expand All @@ -142,13 +139,13 @@ private void assertHasData(String table) throws SQLException, ClassNotFoundExcep
}

@Test
void pullImageOK() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
void pullImageOK() {
assertHasData(SOURCE_TABLE);
}

@TestTemplate
@DisplayName("JDBC-Db2 end to end test")
public void testJdbcSourceAndSink(TestContainer container) throws IOException, InterruptedException, SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
public void testJdbcSourceAndSink(TestContainer container) throws IOException, InterruptedException {
assertHasData(SOURCE_TABLE);
Container.ExecResult execResult = container.executeJob("/jdbc_db2_source_and_sink.conf");
Assertions.assertEquals(0, execResult.getExitCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ source {
# This is a example source plugin **only for test and demonstrate the feature source plugin**
Jdbc {
driver = com.ibm.db2.jcc.DB2Driver
url = "jdbc:db2://spark_e2e_db2:50000/testdb"
user = DB2INST1
password = 123456
url = "jdbc:db2://e2e_db2:50000/E2E"
user = "DB2INST1"
password = "123456"
query = """
select COL_BOOLEAN,
COL_INT,
Expand Down Expand Up @@ -65,9 +65,9 @@ transform {
sink {
Jdbc {
driver = com.ibm.db2.jcc.DB2Driver
url = "jdbc:db2://spark_e2e_db2:50000/testdb"
user = DB2INST1
password = 123456
url = "jdbc:db2://e2e_db2:50000/E2E"
user = "DB2INST1"
password = "123456"
query = """
insert into "DB2INST1".E2E_TABLE_SINK(COL_BOOLEAN, COL_INT, COL_INTEGER, COL_SMALLINT, COL_BIGINT, COL_DECIMAL, COL_DEC,
COL_NUMERIC, COL_NUMBER, COL_REAL, COL_FLOAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc</artifactId>
<version>db2jcc4</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
Expand Down

0 comments on commit c09599e

Please sign in to comment.