Skip to content

Commit

Permalink
[db2] [tests] Fix unstable Db2ConnectorITCase due to cleanup failure
Browse files Browse the repository at this point in the history
This closes apache#2345.
  • Loading branch information
yuxiqian authored Aug 3, 2023
1 parent 1330cc4 commit 61b9a2a
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ public void before() {
env.setParallelism(1);
}

private void cancelJobIfRunning(TableResult result)
throws InterruptedException, ExecutionException {
try {
result.getJobClient().get().cancel().get();
} catch (IllegalStateException ignored) {
// job isn't running, ignore it
}
}

@Test
public void testConsumingAllEvents()
throws SQLException, InterruptedException, ExecutionException {
Expand Down Expand Up @@ -163,7 +172,7 @@ public void testConsumingAllEvents()
List<String> actual = TestValuesTableFactory.getResults("sink");
assertThat(actual, containsInAnyOrder(expected));

result.getJobClient().get().cancel().get();
cancelJobIfRunning(result);
}

@Test
Expand Down Expand Up @@ -254,7 +263,7 @@ public void testAllTypes() throws Exception {
List<String> actual = TestValuesTableFactory.getRawResults("sink");
assertEquals(expected, actual);

result.getJobClient().get().cancel().get();
cancelJobIfRunning(result);
}

@Test
Expand Down Expand Up @@ -322,7 +331,7 @@ public void testStartupFromLatestOffset() throws Exception {
List<String> actual = TestValuesTableFactory.getResults("sink");
assertThat(actual, containsInAnyOrder(expected));

result.getJobClient().get().cancel().get();
cancelJobIfRunning(result);
}

@Test
Expand Down Expand Up @@ -419,7 +428,7 @@ public void testMetadataColumns() throws Throwable {
Collections.sort(expected);
Collections.sort(actual);
assertEquals(expected, actual);
result.getJobClient().get().cancel().get();
cancelJobIfRunning(result);
}

private static void waitForSnapshotStarted(String sinkName) throws InterruptedException {
Expand Down

0 comments on commit 61b9a2a

Please sign in to comment.