|
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; |
28 | 27 | import org.apache.flink.streaming.api.datastream.DataStream; |
29 | 28 | import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; |
|
36 | 35 | import org.apache.flink.table.utils.EncodingUtils; |
37 | 36 | import org.apache.flink.test.util.SuccessException; |
38 | 37 | import org.apache.flink.types.Row; |
| 38 | +import org.apache.flink.util.FlinkException; |
39 | 39 | import org.apache.flink.util.function.RunnableWithException; |
40 | 40 |
|
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; |
45 | 46 | import org.junit.Before; |
46 | 47 | import org.junit.Test; |
|
66 | 67 | import java.util.stream.IntStream; |
67 | 68 |
|
68 | 69 | import static org.apache.flink.core.testutils.CommonTestUtils.waitUtil; |
| 70 | +import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches; |
| 71 | +import static org.apache.flink.core.testutils.FlinkAssertions.assertThatChainOfCauses; |
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,28 @@ private static boolean isCausedByJobFinished(Throwable e) { |
1513 | 1516 | } |
1514 | 1517 |
|
1515 | 1518 | private void cleanupTopic(String topic) { |
1516 | | - ignoreExceptions(() -> deleteTestTopic(topic)); |
| 1519 | + ignoreExceptions(() -> deleteTestTopic(topic), UnknownTopicOrPartitionException.class); |
1517 | 1520 | } |
1518 | 1521 |
|
1519 | | - private static void ignoreExceptions(RunnableWithException e) { |
| 1522 | + @SafeVarargs |
| 1523 | + private static void ignoreExceptions( |
| 1524 | + RunnableWithException runnable, Class<? extends Exception>... exClasses) { |
1520 | 1525 | try { |
1521 | | - e.run(); |
| 1526 | + runnable.run(); |
| 1527 | + } catch (InterruptedException e) { |
| 1528 | + Thread.currentThread().interrupt(); |
1522 | 1529 | } catch (Exception ex) { |
1523 | | - // ignore |
| 1530 | + // check if the exception is one of the ignored ones |
| 1531 | + assertThatChainOfCauses(ex) |
| 1532 | + .anyMatch( |
| 1533 | + cause -> Arrays.stream(exClasses).anyMatch(cl -> cl.isInstance(cause))); |
1524 | 1534 | } |
1525 | 1535 | } |
1526 | 1536 |
|
1527 | 1537 | private static void cancelJob(TableResult tableResult) { |
1528 | | - if (tableResult != null) { |
1529 | | - ignoreExceptions(() -> tableResult.getJobClient().ifPresent(JobClient::cancel)); |
| 1538 | + if (tableResult != null && tableResult.getJobClient().isPresent()) { |
| 1539 | + ignoreExceptions( |
| 1540 | + () -> tableResult.getJobClient().get().cancel().get(), FlinkException.class); |
1530 | 1541 | } |
1531 | 1542 | } |
1532 | 1543 | } |
0 commit comments