Search in sources :

Example 31 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway in project flink by apache.

the class ExecutionVertexCancelTest method testCancelConcurrentlyToDeploying_CallsNotOvertaking.

@Test
public void testCancelConcurrentlyToDeploying_CallsNotOvertaking() {
    try {
        final JobVertexID jid = new JobVertexID();
        final TestingUtils.QueuedActionExecutionContext executionContext = TestingUtils.queuedActionExecutionContext();
        final TestingUtils.ActionQueue actions = executionContext.actionQueue();
        final ExecutionJobVertex ejv = getExecutionVertex(jid, executionContext);
        final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0], AkkaUtils.getDefaultTimeout());
        setVertexState(vertex, ExecutionState.SCHEDULED);
        assertEquals(ExecutionState.SCHEDULED, vertex.getExecutionState());
        ActorGateway actorGateway = new CancelSequenceActorGateway(executionContext, 2);
        Instance instance = getInstance(new ActorTaskManagerGateway(actorGateway));
        SimpleSlot slot = instance.allocateSimpleSlot(new JobID());
        vertex.deployToSlot(slot);
        assertEquals(ExecutionState.DEPLOYING, vertex.getExecutionState());
        vertex.cancel();
        assertEquals(ExecutionState.CANCELING, vertex.getExecutionState());
        // first action happens (deploy)
        actions.triggerNextAction();
        assertEquals(ExecutionState.CANCELING, vertex.getExecutionState());
        // the deploy call found itself in canceling after it returned and needs to send a cancel call
        // the call did not yet execute, so it is still in canceling
        assertEquals(ExecutionState.CANCELING, vertex.getExecutionState());
        // second action happens (cancel call from cancel function)
        actions.triggerNextAction();
        // TaskManager reports back (canceling done)
        vertex.getCurrentExecutionAttempt().cancelingComplete();
        // should properly set state to cancelled
        assertEquals(ExecutionState.CANCELED, vertex.getExecutionState());
        // trigger the correction canceling call
        actions.triggerNextAction();
        assertEquals(ExecutionState.CANCELED, vertex.getExecutionState());
        assertTrue(slot.isReleased());
        assertNull(vertex.getFailureCause());
        assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELING) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELED) > 0);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Instance(org.apache.flink.runtime.instance.Instance) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) IOException(java.io.IOException) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) TestingUtils(org.apache.flink.runtime.testingUtils.TestingUtils) BaseTestingActorGateway(org.apache.flink.runtime.instance.BaseTestingActorGateway) DummyActorGateway(org.apache.flink.runtime.instance.DummyActorGateway) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 32 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway in project flink by apache.

the class ExecutionVertexCancelTest method testRepeatedCancelFromRunning.

@Test
public void testRepeatedCancelFromRunning() {
    try {
        final JobVertexID jid = new JobVertexID();
        final ExecutionJobVertex ejv = getExecutionVertex(jid, new DirectScheduledExecutorService());
        final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0], AkkaUtils.getDefaultTimeout());
        final ActorGateway actorGateway = new CancelSequenceActorGateway(TestingUtils.directExecutionContext(), 1);
        Instance instance = getInstance(new ActorTaskManagerGateway(actorGateway));
        SimpleSlot slot = instance.allocateSimpleSlot(new JobID());
        setVertexState(vertex, ExecutionState.RUNNING);
        setVertexResource(vertex, slot);
        assertEquals(ExecutionState.RUNNING, vertex.getExecutionState());
        vertex.cancel();
        assertEquals(ExecutionState.CANCELING, vertex.getExecutionState());
        vertex.cancel();
        assertEquals(ExecutionState.CANCELING, vertex.getExecutionState());
        // callback by TaskManager after canceling completes
        vertex.getCurrentExecutionAttempt().cancelingComplete();
        assertEquals(ExecutionState.CANCELED, vertex.getExecutionState());
        assertTrue(slot.isReleased());
        assertNull(vertex.getFailureCause());
        assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELING) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELED) > 0);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Instance(org.apache.flink.runtime.instance.Instance) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) BaseTestingActorGateway(org.apache.flink.runtime.instance.BaseTestingActorGateway) DummyActorGateway(org.apache.flink.runtime.instance.DummyActorGateway) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) JobID(org.apache.flink.api.common.JobID) IOException(java.io.IOException) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) Test(org.junit.Test)

Example 33 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway in project flink by apache.

the class ExecutionVertexCancelTest method testCancelFromRunningDidNotFindTask.

@Test
public void testCancelFromRunningDidNotFindTask() {
    // this may happen when the task finished or failed while the call was in progress
    try {
        final JobVertexID jid = new JobVertexID();
        final ExecutionJobVertex ejv = getExecutionVertex(jid, new DirectScheduledExecutorService());
        final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0], AkkaUtils.getDefaultTimeout());
        final ActorGateway actorGateway = new CancelSequenceActorGateway(TestingUtils.directExecutionContext(), 1);
        Instance instance = getInstance(new ActorTaskManagerGateway(actorGateway));
        SimpleSlot slot = instance.allocateSimpleSlot(new JobID());
        setVertexState(vertex, ExecutionState.RUNNING);
        setVertexResource(vertex, slot);
        assertEquals(ExecutionState.RUNNING, vertex.getExecutionState());
        vertex.cancel();
        assertEquals(ExecutionState.CANCELING, vertex.getExecutionState());
        assertNull(vertex.getFailureCause());
        assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELING) > 0);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Instance(org.apache.flink.runtime.instance.Instance) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) BaseTestingActorGateway(org.apache.flink.runtime.instance.BaseTestingActorGateway) DummyActorGateway(org.apache.flink.runtime.instance.DummyActorGateway) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) JobID(org.apache.flink.api.common.JobID) IOException(java.io.IOException) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) Test(org.junit.Test)

Example 34 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway in project flink by apache.

the class ExecutionVertexCancelTest method testCancelCallFails.

@Test
public void testCancelCallFails() {
    try {
        final JobVertexID jid = new JobVertexID();
        final ExecutionJobVertex ejv = getExecutionVertex(jid, new DirectScheduledExecutorService());
        final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0], AkkaUtils.getDefaultTimeout());
        final ActorGateway gateway = new CancelSequenceActorGateway(TestingUtils.directExecutionContext(), 0);
        Instance instance = getInstance(new ActorTaskManagerGateway(gateway));
        SimpleSlot slot = instance.allocateSimpleSlot(new JobID());
        setVertexState(vertex, ExecutionState.RUNNING);
        setVertexResource(vertex, slot);
        assertEquals(ExecutionState.RUNNING, vertex.getExecutionState());
        vertex.cancel();
        // Callback fails, leading to CANCELED
        assertEquals(ExecutionState.CANCELED, vertex.getExecutionState());
        assertTrue(slot.isReleased());
        assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELING) > 0);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Instance(org.apache.flink.runtime.instance.Instance) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) BaseTestingActorGateway(org.apache.flink.runtime.instance.BaseTestingActorGateway) DummyActorGateway(org.apache.flink.runtime.instance.DummyActorGateway) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) JobID(org.apache.flink.api.common.JobID) IOException(java.io.IOException) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) Test(org.junit.Test)

Example 35 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway in project flink by apache.

the class CoordinatorShutdownTest method testCoordinatorShutsDownOnSuccess.

@Test
public void testCoordinatorShutsDownOnSuccess() {
    LocalFlinkMiniCluster cluster = null;
    try {
        Configuration config = new Configuration();
        config.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, 1);
        config.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, 1);
        cluster = new LocalFlinkMiniCluster(config, true);
        cluster.start();
        // build a test graph with snapshotting enabled
        JobVertex vertex = new JobVertex("Test Vertex");
        vertex.setInvokableClass(BlockingInvokable.class);
        List<JobVertexID> vertexIdList = Collections.singletonList(vertex.getID());
        JobGraph testGraph = new JobGraph("test job", vertex);
        testGraph.setSnapshotSettings(new JobSnapshottingSettings(vertexIdList, vertexIdList, vertexIdList, 5000, 60000, 0L, Integer.MAX_VALUE, ExternalizedCheckpointSettings.none(), null, true));
        ActorGateway jmGateway = cluster.getLeaderGateway(TestingUtils.TESTING_DURATION());
        FiniteDuration timeout = new FiniteDuration(60, TimeUnit.SECONDS);
        JobManagerMessages.SubmitJob submitMessage = new JobManagerMessages.SubmitJob(testGraph, ListeningBehaviour.EXECUTION_RESULT);
        // submit is successful, but then the job blocks due to the invokable
        Future<Object> submitFuture = jmGateway.ask(submitMessage, timeout);
        Await.result(submitFuture, timeout);
        // get the execution graph and store the ExecutionGraph reference
        Future<Object> jobRequestFuture = jmGateway.ask(new JobManagerMessages.RequestJob(testGraph.getJobID()), timeout);
        ExecutionGraph graph = (ExecutionGraph) ((JobManagerMessages.JobFound) Await.result(jobRequestFuture, timeout)).executionGraph();
        assertNotNull(graph);
        BlockingInvokable.unblock();
        graph.waitUntilFinished();
        // verify that the coordinator was shut down
        CheckpointCoordinator coord = graph.getCheckpointCoordinator();
        assertTrue(coord == null || coord.isShutdown());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        if (cluster != null) {
            cluster.shutdown();
            cluster.awaitTermination();
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) JobSnapshottingSettings(org.apache.flink.runtime.jobgraph.tasks.JobSnapshottingSettings) JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) FiniteDuration(scala.concurrent.duration.FiniteDuration) LocalFlinkMiniCluster(org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) Test(org.junit.Test)

Aggregations

ActorGateway (org.apache.flink.runtime.instance.ActorGateway)115 Test (org.junit.Test)91 JobID (org.apache.flink.api.common.JobID)47 Configuration (org.apache.flink.configuration.Configuration)46 FiniteDuration (scala.concurrent.duration.FiniteDuration)45 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)41 JavaTestKit (akka.testkit.JavaTestKit)34 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)32 IOException (java.io.IOException)31 ActorRef (akka.actor.ActorRef)30 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)27 JobManagerMessages (org.apache.flink.runtime.messages.JobManagerMessages)27 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)20 Deadline (scala.concurrent.duration.Deadline)20 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)17 TestingJobManagerMessages (org.apache.flink.runtime.testingUtils.TestingJobManagerMessages)17 TaskManagerServicesConfiguration (org.apache.flink.runtime.taskexecutor.TaskManagerServicesConfiguration)16 File (java.io.File)15 SubmitJob (org.apache.flink.runtime.messages.JobManagerMessages.SubmitJob)15 TriggerSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint)15