use of org.apache.flink.api.common.time.Deadline in project flink by apache.
the class CommonTestUtils method waitForAllTaskRunning.
public static void waitForAllTaskRunning(SupplierWithException<AccessExecutionGraph, Exception> executionGraphSupplier, Deadline timeout, boolean allowFinished) throws Exception {
Predicate<AccessExecutionVertex> subtaskPredicate = task -> {
switch(task.getExecutionState()) {
case RUNNING:
return true;
case FINISHED:
if (allowFinished) {
return true;
} else {
throw new RuntimeException("Sub-Task finished unexpectedly" + task);
}
default:
return false;
}
};
waitUntilCondition(() -> {
final AccessExecutionGraph graph = executionGraphSupplier.get();
if (graph.getState().isGloballyTerminalState()) {
final ErrorInfo failureInfo = graph.getFailureInfo();
fail(format("Graph is in globally terminal state (%s)", graph.getState()), failureInfo != null ? failureInfo.getException() : null);
}
return graph.getState() == JobStatus.RUNNING && graph.getAllVertices().values().stream().allMatch(jobVertex -> Arrays.stream(jobVertex.getTaskVertices()).allMatch(subtaskPredicate));
}, timeout);
}
use of org.apache.flink.api.common.time.Deadline in project flink by apache.
the class SystemProcessingTimeService method shutdownServiceUninterruptible.
@Override
public boolean shutdownServiceUninterruptible(long timeoutMs) {
final Deadline deadline = Deadline.fromNow(Duration.ofMillis(timeoutMs));
boolean shutdownComplete = false;
boolean receivedInterrupt = false;
do {
try {
// wait for a reasonable time for all pending timer threads to finish
shutdownComplete = shutdownAndAwaitPending(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
} catch (InterruptedException iex) {
receivedInterrupt = true;
LOG.trace("Intercepted attempt to interrupt timer service shutdown.", iex);
}
} while (deadline.hasTimeLeft() && !shutdownComplete);
if (receivedInterrupt) {
Thread.currentThread().interrupt();
}
return shutdownComplete;
}
use of org.apache.flink.api.common.time.Deadline in project flink by apache.
the class AbstractHAJobRunITCase method testJobExecutionInHaMode.
@Test
public void testJobExecutionInHaMode(@InjectMiniCluster MiniCluster flinkCluster) throws Exception {
final JobGraph jobGraph = JobGraphTestUtils.singleNoOpJobGraph();
// providing a timeout helps making the test fail in case some issue occurred while
// initializing the cluster
flinkCluster.submitJob(jobGraph).get(30, TimeUnit.SECONDS);
final Deadline deadline = Deadline.fromNow(Duration.ofSeconds(30));
final JobStatus jobStatus = FutureUtils.retrySuccessfulWithDelay(() -> flinkCluster.getJobStatus(jobGraph.getJobID()), Time.milliseconds(10), deadline, status -> flinkCluster.isRunning() && status == JobStatus.FINISHED, TestingUtils.defaultScheduledExecutor()).get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
assertThat(jobStatus).isEqualTo(JobStatus.FINISHED);
runAfterJobTermination();
}
use of org.apache.flink.api.common.time.Deadline in project flink by apache.
the class FileChannelManagerImplTest method testDirectoriesCleanupOnKill.
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();
}
}
use of org.apache.flink.api.common.time.Deadline in project flink by apache.
the class LeaderChangeClusterComponentsTest method testTaskExecutorsReconnectToClusterWithLeadershipChange.
@Test
public void testTaskExecutorsReconnectToClusterWithLeadershipChange() throws Exception {
final Deadline deadline = Deadline.fromNow(TESTING_TIMEOUT);
waitUntilTaskExecutorsHaveConnected(NUM_TMS, deadline);
highAvailabilityServices.revokeResourceManagerLeadership().get();
highAvailabilityServices.grantResourceManagerLeadership();
// wait for the ResourceManager to confirm the leadership
assertThat(LeaderRetrievalUtils.retrieveLeaderConnectionInfo(highAvailabilityServices.getResourceManagerLeaderRetriever(), TESTING_TIMEOUT).getLeaderSessionId(), is(notNullValue()));
waitUntilTaskExecutorsHaveConnected(NUM_TMS, deadline);
}
Aggregations