Search in sources :

Example 26 with SimpleSlot

use of org.apache.flink.runtime.instance.SimpleSlot 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 27 with SimpleSlot

use of org.apache.flink.runtime.instance.SimpleSlot 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 28 with SimpleSlot

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

the class ExecutionVertexDeploymentTest method testTddProducedPartitionsLazyScheduling.

/**
	 * Tests that the lazy scheduling flag is correctly forwarded to the produced partition descriptors.
	 */
@Test
public void testTddProducedPartitionsLazyScheduling() throws Exception {
    TestingUtils.QueuedActionExecutionContext context = TestingUtils.queuedActionExecutionContext();
    ExecutionJobVertex jobVertex = getExecutionVertex(new JobVertexID(), context);
    IntermediateResult result = new IntermediateResult(new IntermediateDataSetID(), jobVertex, 1, ResultPartitionType.PIPELINED);
    ExecutionVertex vertex = new ExecutionVertex(jobVertex, 0, new IntermediateResult[] { result }, Time.minutes(1));
    ExecutionEdge mockEdge = createMockExecutionEdge(1);
    result.getPartitions()[0].addConsumerGroup();
    result.getPartitions()[0].addConsumer(mockEdge, 0);
    AllocatedSlot allocatedSlot = mock(AllocatedSlot.class);
    when(allocatedSlot.getSlotAllocationId()).thenReturn(new AllocationID());
    Slot root = mock(Slot.class);
    when(root.getSlotNumber()).thenReturn(1);
    SimpleSlot slot = mock(SimpleSlot.class);
    when(slot.getRoot()).thenReturn(root);
    when(slot.getAllocatedSlot()).thenReturn(allocatedSlot);
    when(root.getAllocatedSlot()).thenReturn(allocatedSlot);
    for (ScheduleMode mode : ScheduleMode.values()) {
        vertex.getExecutionGraph().setScheduleMode(mode);
        TaskDeploymentDescriptor tdd = vertex.createDeploymentDescriptor(new ExecutionAttemptID(), slot, null, 1);
        Collection<ResultPartitionDeploymentDescriptor> producedPartitions = tdd.getProducedPartitions();
        assertEquals(1, producedPartitions.size());
        ResultPartitionDeploymentDescriptor desc = producedPartitions.iterator().next();
        assertEquals(mode.allowLazyDeployment(), desc.sendScheduleOrUpdateConsumersMessage());
    }
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) ResultPartitionDeploymentDescriptor(org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) ExecutionGraphTestUtils.getExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex) TestingUtils(org.apache.flink.runtime.testingUtils.TestingUtils) ScheduleMode(org.apache.flink.runtime.jobgraph.ScheduleMode) Slot(org.apache.flink.runtime.instance.Slot) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) IntermediateDataSetID(org.apache.flink.runtime.jobgraph.IntermediateDataSetID) TaskDeploymentDescriptor(org.apache.flink.runtime.deployment.TaskDeploymentDescriptor) Test(org.junit.Test)

Example 29 with SimpleSlot

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

the class ExecutionVertexDeploymentTest method testFailCallOvertakesDeploymentAnswer.

@Test
public void testFailCallOvertakesDeploymentAnswer() {
    try {
        final TestingUtils.QueuedActionExecutionContext context = TestingUtils.queuedActionExecutionContext();
        final TestingUtils.ActionQueue queue = context.actionQueue();
        final JobVertexID jid = new JobVertexID();
        final ExecutionJobVertex ejv = getExecutionVertex(jid, context);
        final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0], AkkaUtils.getDefaultTimeout());
        final ExecutionAttemptID eid = vertex.getCurrentExecutionAttempt().getAttemptId();
        final Instance instance = getInstance(new ActorTaskManagerGateway(new ExecutionVertexCancelTest.CancelSequenceActorGateway(context, 2)));
        final SimpleSlot slot = instance.allocateSimpleSlot(ejv.getJobId());
        assertEquals(ExecutionState.CREATED, vertex.getExecutionState());
        vertex.deployToSlot(slot);
        assertEquals(ExecutionState.DEPLOYING, vertex.getExecutionState());
        Exception testError = new Exception("test error");
        vertex.fail(testError);
        assertEquals(ExecutionState.FAILED, vertex.getExecutionState());
        // cancel call overtakes deploy call
        Runnable deploy = queue.popNextAction();
        Runnable cancel1 = queue.popNextAction();
        cancel1.run();
        // execute the FutureUtils.retry loop (will complete immediately)
        queue.triggerNextAction();
        // execute the exceptionallyAsync call in Execution#sendRpcCall which won't don anything
        queue.triggerNextAction();
        deploy.run();
        // execute exceptionallyAsync call in Execution#deployToSlot
        queue.triggerNextAction();
        assertEquals(ExecutionState.FAILED, vertex.getExecutionState());
        assertEquals(testError, vertex.getFailureCause());
        assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.DEPLOYING) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.FAILED) > 0);
        assertTrue(queue.isEmpty());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Instance(org.apache.flink.runtime.instance.Instance) ExecutionGraphTestUtils.getInstance(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getInstance) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) ExecutionGraphTestUtils.getExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) TestingUtils(org.apache.flink.runtime.testingUtils.TestingUtils) Test(org.junit.Test)

Example 30 with SimpleSlot

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

the class ExecutionVertexDeploymentTest method testDeployWithAsynchronousAnswer.

@Test
public void testDeployWithAsynchronousAnswer() {
    try {
        final JobVertexID jid = new JobVertexID();
        final ExecutionJobVertex ejv = getExecutionVertex(jid);
        final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0], AkkaUtils.getDefaultTimeout());
        final Instance instance = getInstance(new ActorTaskManagerGateway(new SimpleActorGateway(TestingUtils.defaultExecutionContext())));
        final SimpleSlot slot = instance.allocateSimpleSlot(ejv.getJobId());
        assertEquals(ExecutionState.CREATED, vertex.getExecutionState());
        vertex.deployToSlot(slot);
        // no repeated scheduling
        try {
            vertex.deployToSlot(slot);
            fail("Scheduled from wrong state");
        } catch (IllegalStateException e) {
        // as expected
        }
        assertEquals(ExecutionState.DEPLOYING, vertex.getExecutionState());
        // no repeated scheduling
        try {
            vertex.deployToSlot(slot);
            fail("Scheduled from wrong state");
        } catch (IllegalStateException e) {
        // as expected
        }
        assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.DEPLOYING) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.RUNNING) == 0);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Instance(org.apache.flink.runtime.instance.Instance) ExecutionGraphTestUtils.getInstance(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getInstance) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) SimpleActorGateway(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.SimpleActorGateway) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) ExecutionGraphTestUtils.getExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) Test(org.junit.Test)

Aggregations

SimpleSlot (org.apache.flink.runtime.instance.SimpleSlot)78 Test (org.junit.Test)59 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)46 Instance (org.apache.flink.runtime.instance.Instance)38 ExecutionException (java.util.concurrent.ExecutionException)25 ActorTaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway)22 JobID (org.apache.flink.api.common.JobID)20 TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)16 TaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway)14 FlinkCompletableFuture (org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture)13 SchedulerTestUtils.getRandomInstance (org.apache.flink.runtime.jobmanager.scheduler.SchedulerTestUtils.getRandomInstance)13 ExecutionGraphTestUtils.getExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex)12 ExecutionGraphTestUtils.getInstance (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getInstance)12 IOException (java.io.IOException)10 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)8 BaseTestingActorGateway (org.apache.flink.runtime.instance.BaseTestingActorGateway)8 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)8 Scheduler (org.apache.flink.runtime.jobmanager.scheduler.Scheduler)8 AllocatedSlot (org.apache.flink.runtime.jobmanager.slots.AllocatedSlot)8 Future (org.apache.flink.runtime.concurrent.Future)7