Search in sources :

Example 1 with TestingClusterEntrypointProcess

use of org.apache.flink.runtime.testutils.TestingClusterEntrypointProcess in project flink by apache.

the class ClusterEntrypointTest method testCloseAsyncShouldBeExecutedInShutdownHook.

@Test
public void testCloseAsyncShouldBeExecutedInShutdownHook() throws Exception {
    // This test only works on Linux and Mac OS because we are sending SIGTERM to a
    // JAVA process via "kill {pid}"
    assumeTrue(OperatingSystem.isLinux() || OperatingSystem.isMac());
    final File markerFile = new File(TEMPORARY_FOLDER.getRoot(), UUID.randomUUID() + ".marker");
    final TestingClusterEntrypointProcess clusterEntrypointProcess = new TestingClusterEntrypointProcess(markerFile);
    clusterEntrypointProcess.startProcess();
    boolean success = false;
    try {
        final long pid = clusterEntrypointProcess.getProcessId();
        assertTrue("Cannot determine process ID", pid != -1);
        // wait for the marker file to appear, which means the process is up properly
        TestJvmProcess.waitForMarkerFile(markerFile, 30000);
        TestJvmProcess.killProcessWithSigTerm(pid);
        final boolean exited = clusterEntrypointProcess.waitFor(TIMEOUT_MS, TimeUnit.MILLISECONDS);
        assertThat(String.format("Process %s does not exit within %s ms", pid, TIMEOUT_MS), exited, is(true));
        assertThat("markerFile should be deleted in closeAsync shutdownHook", markerFile.exists(), is(false));
        success = true;
    } finally {
        if (!success) {
            clusterEntrypointProcess.printProcessLog();
        }
        clusterEntrypointProcess.destroy();
    }
}
Also used : TestingClusterEntrypointProcess(org.apache.flink.runtime.testutils.TestingClusterEntrypointProcess) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 TestingClusterEntrypointProcess (org.apache.flink.runtime.testutils.TestingClusterEntrypointProcess)1 Test (org.junit.Test)1