|
23 | 23 | import org.apache.flink.configuration.CoreOptions;
|
24 | 24 | import org.apache.flink.core.execution.JobClient;
|
25 | 25 | import org.apache.flink.core.execution.SavepointFormatType;
|
26 |
| -import org.apache.flink.core.testutils.FlinkAssertions; |
27 | 26 | import org.apache.flink.runtime.jobgraph.SavepointConfigOptions;
|
| 27 | +import org.apache.flink.runtime.messages.FlinkJobTerminatedWithoutCancellationException; |
28 | 28 | import org.apache.flink.streaming.api.datastream.DataStream;
|
29 | 29 | import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
|
30 | 30 | import org.apache.flink.streaming.api.functions.sink.SinkFunction;
|
|
41 | 41 | import org.apache.kafka.clients.consumer.NoOffsetForPartitionException;
|
42 | 42 | import org.apache.kafka.clients.consumer.OffsetAndMetadata;
|
43 | 43 | import org.apache.kafka.common.TopicPartition;
|
| 44 | +import org.apache.kafka.common.errors.UnknownTopicOrPartitionException; |
44 | 45 | import org.assertj.core.api.Assertions;
|
| 46 | +import org.assertj.core.api.ThrowingConsumer; |
45 | 47 | import org.junit.Before;
|
46 | 48 | import org.junit.Test;
|
47 | 49 | import org.junit.runner.RunWith;
|
|
66 | 68 | import java.util.stream.IntStream;
|
67 | 69 |
|
68 | 70 | import static org.apache.flink.core.testutils.CommonTestUtils.waitUtil;
|
| 71 | +import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches; |
69 | 72 | import static org.apache.flink.streaming.connectors.kafka.table.KafkaTableTestUtils.collectAllRows;
|
70 | 73 | import static org.apache.flink.streaming.connectors.kafka.table.KafkaTableTestUtils.collectRows;
|
71 | 74 | import static org.apache.flink.streaming.connectors.kafka.table.KafkaTableTestUtils.readLines;
|
@@ -1318,7 +1321,7 @@ public void testStartFromGroupOffsetsEarliest() throws Exception {
|
1318 | 1321 | @Test
|
1319 | 1322 | public void testStartFromGroupOffsetsNone() {
|
1320 | 1323 | Assertions.assertThatThrownBy(() -> testStartFromGroupOffsetsWithNoneResetStrategy())
|
1321 |
| - .satisfies(FlinkAssertions.anyCauseMatches(NoOffsetForPartitionException.class)); |
| 1324 | + .satisfies(anyCauseMatches(NoOffsetForPartitionException.class)); |
1322 | 1325 | }
|
1323 | 1326 |
|
1324 | 1327 | private List<String> appendNewData(
|
@@ -1513,20 +1516,31 @@ private static boolean isCausedByJobFinished(Throwable e) {
|
1513 | 1516 | }
|
1514 | 1517 |
|
1515 | 1518 | private void cleanupTopic(String topic) {
|
1516 |
| - ignoreExceptions(() -> deleteTestTopic(topic)); |
| 1519 | + ignoreExceptions( |
| 1520 | + () -> deleteTestTopic(topic), |
| 1521 | + anyCauseMatches(UnknownTopicOrPartitionException.class)); |
1517 | 1522 | }
|
1518 | 1523 |
|
1519 |
| - private static void ignoreExceptions(RunnableWithException e) { |
1520 |
| - try { |
1521 |
| - e.run(); |
1522 |
| - } catch (Exception ex) { |
1523 |
| - // ignore |
| 1524 | + private static void cancelJob(TableResult tableResult) { |
| 1525 | + if (tableResult != null && tableResult.getJobClient().isPresent()) { |
| 1526 | + ignoreExceptions( |
| 1527 | + () -> tableResult.getJobClient().get().cancel().get(), |
| 1528 | + anyCauseMatches(FlinkJobTerminatedWithoutCancellationException.class), |
| 1529 | + anyCauseMatches( |
| 1530 | + "MiniCluster is not yet running or has already been shut down.")); |
1524 | 1531 | }
|
1525 | 1532 | }
|
1526 | 1533 |
|
1527 |
| - private static void cancelJob(TableResult tableResult) { |
1528 |
| - if (tableResult != null) { |
1529 |
| - ignoreExceptions(() -> tableResult.getJobClient().ifPresent(JobClient::cancel)); |
| 1534 | + @SafeVarargs |
| 1535 | + private static void ignoreExceptions( |
| 1536 | + RunnableWithException runnable, ThrowingConsumer<? super Throwable>... ignoreIf) { |
| 1537 | + try { |
| 1538 | + runnable.run(); |
| 1539 | + } catch (InterruptedException e) { |
| 1540 | + Thread.currentThread().interrupt(); |
| 1541 | + } catch (Exception ex) { |
| 1542 | + // check if the exception is one of the ignored ones |
| 1543 | + assertThat(ex).satisfiesAnyOf(ignoreIf); |
1530 | 1544 | }
|
1531 | 1545 | }
|
1532 | 1546 | }
|
0 commit comments