Skip to content

Commit

Permalink
[HotFix][E2E][JDBC] Fix not remove docker image after test finish on …
Browse files Browse the repository at this point in the history
…jdbc suite (#5586)
  • Loading branch information
CheneyYin authored Oct 4, 2023
1 parent f5ed477 commit 70a3980
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions release-note.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
- [Container Version] Fix risk of unreproducible test cases #4591
- [E2e] [Mysql-cdc] Removing the excess MySqlIncrementalSourceIT e2e reduces the CI time (#4738)
- [E2E] [Common] Update test container version of seatunnel engine (#5323)
- [E2E] [Jdbc] Fix not remove docker image after test finish on jdbc suite (#5586)

## Improve

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestTemplate;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.images.PullPolicy;
import org.testcontainers.lifecycle.Startables;

import com.github.dockerjava.api.model.Image;
Expand Down Expand Up @@ -194,7 +196,13 @@ protected String buildTableInfoWithSchema(String database, String schema, String
public void clearTable(String schema, String table) {
try (Statement statement = connection.createStatement()) {
statement.execute("TRUNCATE TABLE " + buildTableInfoWithSchema(schema, table));
connection.commit();
} catch (SQLException e) {
try {
connection.rollback();
} catch (SQLException exception) {
throw new SeaTunnelRuntimeException(JdbcITErrorCode.CLEAR_TABLE_FAILED, exception);
}
throw new SeaTunnelRuntimeException(JdbcITErrorCode.CLEAR_TABLE_FAILED, e);
}
}
Expand All @@ -220,7 +228,7 @@ public String buildTableInfoWithSchema(String schema, String table) {
@BeforeAll
@Override
public void startUp() {
dbServer = initContainer();
dbServer = initContainer().withImagePullPolicy(PullPolicy.alwaysPull());
jdbcCase = getJdbcCase();

Startables.deepStart(Stream.of(dbServer)).join();
Expand All @@ -236,8 +244,17 @@ public void startUp() {
initCatalog();
}

@AfterAll
@Override
public void tearDown() throws SQLException {
if (catalog != null) {
catalog.close();
}

if (connection != null) {
connection.close();
}

if (dbServer != null) {
dbServer.close();
String images =
Expand All @@ -258,14 +275,6 @@ public void tearDown() throws SQLException {
dbServer.getDockerImageName(),
images);
}

if (connection != null) {
connection.close();
}

if (catalog != null) {
catalog.close();
}
}

@TestTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ public void clearTable(String schema, String table) {
try (Statement statement = connection.createStatement()) {
String truncate = String.format("delete from \"%s\".%s where 1=1;", schema, table);
statement.execute(truncate);
connection.commit();
} catch (SQLException e) {
try {
connection.rollback();
} catch (SQLException exception) {
throw new SeaTunnelRuntimeException(JdbcITErrorCode.CLEAR_TABLE_FAILED, exception);
}
throw new SeaTunnelRuntimeException(JdbcITErrorCode.CLEAR_TABLE_FAILED, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ public void clearTable(String schema, String table) {
String.format(
"delete from %s where 1=1", buildTableInfoWithSchema(schema, table));
statement.execute(truncate);
connection.commit();
} catch (SQLException e) {
try {
connection.rollback();
} catch (SQLException exception) {
throw new SeaTunnelRuntimeException(JdbcITErrorCode.CLEAR_TABLE_FAILED, exception);
}
throw new SeaTunnelRuntimeException(JdbcITErrorCode.CLEAR_TABLE_FAILED, e);
}
}
Expand Down

0 comments on commit 70a3980

Please sign in to comment.