From 4f860208ebc4a57db1a47552026c574158e3708a Mon Sep 17 00:00:00 2001 From: laglangyue <373435126@qq.com> Date: Mon, 17 Oct 2022 00:47:54 +0800 Subject: [PATCH] fix --- .../connectors/seatunnel/jdbc/JdbcDb2IT.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcDb2IT.java b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcDb2IT.java index fe99d9a82d24..7b302ae85f92 100644 --- a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcDb2IT.java +++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcDb2IT.java @@ -73,7 +73,8 @@ public void startUp() throws Exception { given().ignoreExceptions() .await() .atMost(180, TimeUnit.SECONDS) - .untilAsserted(this::initializeDbServer); + .untilAsserted(this::initializeJdbcConnection); + initializeJdbcTable(); } @Override @@ -86,7 +87,7 @@ public void tearDown() throws Exception { } } - private void initializeDbServer() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException { + private void initializeJdbcConnection() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException { Properties properties = new Properties(); properties.setProperty("user", USER); properties.setProperty("password", PASSWORD); @@ -97,7 +98,6 @@ private void initializeDbServer() throws SQLException, ClassNotFoundException, I Assertions.assertTrue(resultSet.next()); resultSet.close(); statement.close(); - initializeJdbcTable(); } /** @@ -127,7 +127,11 @@ private void initializeJdbcTable() { } } - private void assertHasData(String table) throws SQLException { + private void assertHasData(String table) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException { + if(jdbcConnection.isValid(10)){ + initializeJdbcConnection(); + } + try (Statement statement = jdbcConnection.createStatement()) { String sql = String.format("select * from \"%s\".%s", USER, table); ResultSet source = statement.executeQuery(sql); @@ -138,13 +142,13 @@ private void assertHasData(String table) throws SQLException { } @Test - void pullImageOK() throws SQLException { + void pullImageOK() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException { assertHasData(SOURCE_TABLE); } @TestTemplate @DisplayName("JDBC-DM end to end test") - public void testJdbcSourceAndSink(TestContainer container) throws IOException, InterruptedException, SQLException { + public void testJdbcSourceAndSink(TestContainer container) throws IOException, InterruptedException, SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException { assertHasData(SOURCE_TABLE); Container.ExecResult execResult = container.executeJob("/jdbc_db2_source_and_sink.conf"); Assertions.assertEquals(0, execResult.getExitCode());