Java Code Examples for org.apache.flink.runtime.testutils.TestJvmProcess#waitForMarkerFile()
The following examples show how to use
org.apache.flink.runtime.testutils.TestJvmProcess#waitForMarkerFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockingShutdownTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testProcessShutdownBlocking() throws Exception { // this test works only on linux assumeTrue(OperatingSystem.isLinux()); final File markerFile = new File( EnvironmentInformation.getTemporaryFileDirectory(), UUID.randomUUID() + ".marker"); final BlockingShutdownProcess blockingProcess = new BlockingShutdownProcess(markerFile.getAbsolutePath(), 0, false); try { blockingProcess.startProcess(); long pid = blockingProcess.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); // send it a regular kill command (SIG_TERM) Process kill = Runtime.getRuntime().exec("kill " + pid); kill.waitFor(); assertEquals("failed to send SIG_TERM to process", 0, kill.exitValue()); // minimal delay until the Java process object notices that the process is gone // this will not let the test fail predictably if the process is actually in fact going away, // but it would create frequent failures. Not ideal, but the best we can do without // severely prolonging the test Thread.sleep(50); // the process should not go away by itself assertTrue("Test broken, process shutdown blocking does not work", blockingProcess.isAlive()); } finally { blockingProcess.destroy(); //noinspection ResultOfMethodCallIgnored markerFile.delete(); } }
Example 2
Source File: BlockingShutdownTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testProcessShutdownBlocking() throws Exception { // this test works only on linux assumeTrue(OperatingSystem.isLinux()); final File markerFile = new File( EnvironmentInformation.getTemporaryFileDirectory(), UUID.randomUUID() + ".marker"); final BlockingShutdownProcess blockingProcess = new BlockingShutdownProcess(markerFile.getAbsolutePath(), 0, false); try { blockingProcess.startProcess(); long pid = blockingProcess.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); // send it a regular kill command (SIG_TERM) Process kill = Runtime.getRuntime().exec("kill " + pid); kill.waitFor(); assertEquals("failed to send SIG_TERM to process", 0, kill.exitValue()); // minimal delay until the Java process object notices that the process is gone // this will not let the test fail predictably if the process is actually in fact going away, // but it would create frequent failures. Not ideal, but the best we can do without // severely prolonging the test Thread.sleep(50); // the process should not go away by itself assertTrue("Test broken, process shutdown blocking does not work", blockingProcess.isAlive()); } finally { blockingProcess.destroy(); //noinspection ResultOfMethodCallIgnored markerFile.delete(); } }
Example 3
Source File: BlockingShutdownTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testProcessShutdownBlocking() throws Exception { // this test works only on linux assumeTrue(OperatingSystem.isLinux()); final File markerFile = new File( EnvironmentInformation.getTemporaryFileDirectory(), UUID.randomUUID() + ".marker"); final BlockingShutdownProcess blockingProcess = new BlockingShutdownProcess(markerFile.getAbsolutePath(), 0, false); try { blockingProcess.startProcess(); long pid = blockingProcess.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); // send it a regular kill command (SIG_TERM) Process kill = Runtime.getRuntime().exec("kill " + pid); kill.waitFor(); assertEquals("failed to send SIG_TERM to process", 0, kill.exitValue()); // minimal delay until the Java process object notices that the process is gone // this will not let the test fail predictably if the process is actually in fact going away, // but it would create frequent failures. Not ideal, but the best we can do without // severely prolonging the test Thread.sleep(50); // the process should not go away by itself assertTrue("Test broken, process shutdown blocking does not work", blockingProcess.isAlive()); } finally { blockingProcess.destroy(); //noinspection ResultOfMethodCallIgnored markerFile.delete(); } }
Example 4
Source File: FileChannelManagerImplTest.java From flink with Apache License 2.0 | 4 votes |
private void testDirectoriesCleanupOnKill(boolean callerHasHook) throws Exception { assumeTrue(OperatingSystem.isLinux() || OperatingSystem.isFreeBSD() || OperatingSystem.isSolaris() || OperatingSystem.isMac()); File fileChannelDir = temporaryFolder.newFolder(); File signalDir = temporaryFolder.newFolder(); File signalFile = new File(signalDir.getAbsolutePath(), SIGNAL_FILE_FOR_KILLING); FileChannelManagerTestProcess fileChannelManagerTestProcess = new FileChannelManagerTestProcess( callerHasHook, fileChannelDir.getAbsolutePath(), signalFile.getAbsolutePath()); try { fileChannelManagerTestProcess.startProcess(); // Waits till the process has created temporary files and registered the corresponding shutdown hooks. TestJvmProcess.waitForMarkerFile(signalFile, TEST_TIMEOUT.toMillis()); Process kill = Runtime.getRuntime().exec("kill " + fileChannelManagerTestProcess.getProcessId()); kill.waitFor(); assertEquals("Failed to send SIG_TERM to process", 0, kill.exitValue()); Deadline deadline = Deadline.now().plus(TEST_TIMEOUT); while (fileChannelManagerTestProcess.isAlive() && deadline.hasTimeLeft()) { Thread.sleep(100); } assertFalse( "The file channel manager test process does not terminate in time, its output is: \n" + fileChannelManagerTestProcess.getProcessOutput(), fileChannelManagerTestProcess.isAlive()); // Checks if the directories are cleared. assertFalse( "The file channel manager test process does not remove the tmp shuffle directories after termination, " + "its output is \n" + fileChannelManagerTestProcess.getProcessOutput(), fileOrDirExists(fileChannelDir, DIR_NAME_PREFIX)); } finally { fileChannelManagerTestProcess.destroy(); } }