Search in sources :

Example 6 with InfiniteDelayRestartStrategy

use of org.apache.flink.runtime.executiongraph.restart.InfiniteDelayRestartStrategy in project flink by apache.

the class ExecutionGraphRestartTest method testFailWhileRestarting.

@Test
public void testFailWhileRestarting() throws Exception {
    Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());
    Instance instance = ExecutionGraphTestUtils.getInstance(new ActorTaskManagerGateway(new SimpleActorGateway(TestingUtils.directExecutionContext())), NUM_TASKS);
    scheduler.newInstanceAvailable(instance);
    // Blocking program
    ExecutionGraph executionGraph = new ExecutionGraph(TestingUtils.defaultExecutor(), TestingUtils.defaultExecutor(), new JobID(), "TestJob", new Configuration(), new SerializedValue<>(new ExecutionConfig()), AkkaUtils.getDefaultTimeout(), // We want to manually control the restart and delay
    new InfiniteDelayRestartStrategy(), scheduler);
    JobVertex jobVertex = new JobVertex("NoOpInvokable");
    jobVertex.setInvokableClass(NoOpInvokable.class);
    jobVertex.setParallelism(NUM_TASKS);
    JobGraph jobGraph = new JobGraph("TestJob", jobVertex);
    executionGraph.attachJobGraph(jobGraph.getVerticesSortedTopologicallyFromSources());
    assertEquals(JobStatus.CREATED, executionGraph.getState());
    executionGraph.scheduleForExecution();
    assertEquals(JobStatus.RUNNING, executionGraph.getState());
    // Kill the instance and wait for the job to restart
    instance.markDead();
    Deadline deadline = TestingUtils.TESTING_DURATION().fromNow();
    while (deadline.hasTimeLeft() && executionGraph.getState() != JobStatus.RESTARTING) {
        Thread.sleep(100);
    }
    assertEquals(JobStatus.RESTARTING, executionGraph.getState());
    // The restarting should not fail with an ordinary exception
    executionGraph.fail(new Exception("Test exception"));
    assertEquals(JobStatus.RESTARTING, executionGraph.getState());
    // but it should fail when sending a SuppressRestartsException
    executionGraph.fail(new SuppressRestartsException(new Exception("Test exception")));
    assertEquals(JobStatus.FAILED, executionGraph.getState());
    // The restart has been aborted
    executionGraph.restart();
    assertEquals(JobStatus.FAILED, executionGraph.getState());
}
Also used : Configuration(org.apache.flink.configuration.Configuration) Instance(org.apache.flink.runtime.instance.Instance) Scheduler(org.apache.flink.runtime.jobmanager.scheduler.Scheduler) Deadline(scala.concurrent.duration.Deadline) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) SimpleActorGateway(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.SimpleActorGateway) SuppressRestartsException(org.apache.flink.runtime.execution.SuppressRestartsException) IOException(java.io.IOException) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) SuppressRestartsException(org.apache.flink.runtime.execution.SuppressRestartsException) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) InfiniteDelayRestartStrategy(org.apache.flink.runtime.executiongraph.restart.InfiniteDelayRestartStrategy) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 7 with InfiniteDelayRestartStrategy

use of org.apache.flink.runtime.executiongraph.restart.InfiniteDelayRestartStrategy in project flink by apache.

the class ExecutionGraphSignalsTest method testSuspendWhileRestarting.

/**
	 * Tests that we can suspend a job when in state RESTARTING.
	 */
@Test
public void testSuspendWhileRestarting() throws IllegalAccessException, NoSuchFieldException {
    Field restartStrategyField = eg.getClass().getDeclaredField("restartStrategy");
    restartStrategyField.setAccessible(true);
    restartStrategyField.set(eg, new InfiniteDelayRestartStrategy());
    f.set(eg, JobStatus.RESTARTING);
    final Exception exception = new Exception("Suspended");
    eg.suspend(exception);
    assertEquals(JobStatus.SUSPENDED, eg.getState());
    assertEquals(exception, eg.getFailureCause());
}
Also used : Field(java.lang.reflect.Field) InfiniteDelayRestartStrategy(org.apache.flink.runtime.executiongraph.restart.InfiniteDelayRestartStrategy) SuppressRestartsException(org.apache.flink.runtime.execution.SuppressRestartsException) StoppingException(org.apache.flink.runtime.StoppingException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with InfiniteDelayRestartStrategy

use of org.apache.flink.runtime.executiongraph.restart.InfiniteDelayRestartStrategy in project flink by apache.

the class ExecutionGraphSignalsTest method testSuppressRestartFailureWhileRestarting.

/**
	 * Tests that a {@link SuppressRestartsException} in state RESTARTING stops the restarting
	 * immediately and sets the execution graph's state to FAILED.
	 */
@Test
public void testSuppressRestartFailureWhileRestarting() throws IllegalAccessException, NoSuchFieldException {
    Field restartStrategyField = eg.getClass().getDeclaredField("restartStrategy");
    restartStrategyField.setAccessible(true);
    restartStrategyField.set(eg, new InfiniteDelayRestartStrategy());
    f.set(eg, JobStatus.RESTARTING);
    // suppress a possible restart
    eg.fail(new SuppressRestartsException(new Exception("Test")));
    assertEquals(JobStatus.FAILED, eg.getState());
}
Also used : Field(java.lang.reflect.Field) SuppressRestartsException(org.apache.flink.runtime.execution.SuppressRestartsException) InfiniteDelayRestartStrategy(org.apache.flink.runtime.executiongraph.restart.InfiniteDelayRestartStrategy) SuppressRestartsException(org.apache.flink.runtime.execution.SuppressRestartsException) StoppingException(org.apache.flink.runtime.StoppingException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

InfiniteDelayRestartStrategy (org.apache.flink.runtime.executiongraph.restart.InfiniteDelayRestartStrategy)8 Test (org.junit.Test)8 SuppressRestartsException (org.apache.flink.runtime.execution.SuppressRestartsException)6 Instance (org.apache.flink.runtime.instance.Instance)5 IOException (java.io.IOException)3 Field (java.lang.reflect.Field)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 StoppingException (org.apache.flink.runtime.StoppingException)3 SimpleActorGateway (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.SimpleActorGateway)3 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)3 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)3 Scheduler (org.apache.flink.runtime.jobmanager.scheduler.Scheduler)3 ActorTaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Deadline (scala.concurrent.duration.Deadline)3 FailureRateRestartStrategy (org.apache.flink.runtime.executiongraph.restart.FailureRateRestartStrategy)2 FixedDelayRestartStrategy (org.apache.flink.runtime.executiongraph.restart.FixedDelayRestartStrategy)2 NoRestartStrategy (org.apache.flink.runtime.executiongraph.restart.NoRestartStrategy)2 RestartStrategy (org.apache.flink.runtime.executiongraph.restart.RestartStrategy)2 JobID (org.apache.flink.api.common.JobID)1