Skip to content

Commit 9e23fb7

Browse files
committed
Adding a helper function for cleaning up long running queries.
1 parent 3278d80 commit 9e23fb7

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
package marketplace;
22

33
import io.confluent.flink.plugin.ConfluentSettings;
4+
import org.apache.flink.core.execution.JobClient;
45
import org.apache.flink.table.api.TableEnvironment;
6+
import org.apache.flink.table.api.TableResult;
57
import org.apache.flink.util.CloseableIterator;
8+
import org.junit.jupiter.api.AfterEach;
69
import org.junit.jupiter.api.BeforeEach;
710

11+
import java.util.ArrayList;
12+
import java.util.List;
813
import java.util.stream.Stream;
914
import java.util.stream.StreamSupport;
1015

1116
public abstract class FlinkTableAPITest {
1217
protected static TableEnvironment env;
13-
public abstract void setup();
18+
private List<TableResult> cleanupList;
19+
public void setup() {};
20+
public void teardown() {};
1421

1522
@BeforeEach
1623
public void mainSetup() {
24+
cleanupList = new ArrayList<>();
1725
if(env == null) {
1826
ConfluentSettings.Builder settings = ConfluentSettings.newBuilder("/cloud.properties");
1927
env = TableEnvironment.create(settings.build());
@@ -22,8 +30,23 @@ public void mainSetup() {
2230
setup();
2331
}
2432

33+
@AfterEach
34+
public void mainTeardown() {
35+
cleanupList.forEach(tableResult -> {
36+
JobClient client = tableResult.getJobClient().orElseThrow();
37+
client.cancel().thenRun(() -> System.out.println("Job Canceled During Cleanup"));
38+
});
39+
40+
teardown();
41+
}
42+
2543
protected <T> Stream<T> toStream(CloseableIterator<T> iterator) {
2644
Iterable<T> iterable = () -> iterator;
2745
return StreamSupport.stream(iterable.spliterator(), false);
2846
}
47+
48+
protected TableResult cleanupOnExit(TableResult tableResult) {
49+
cleanupList.add(tableResult);
50+
return tableResult;
51+
}
2952
}

0 commit comments

Comments
 (0)