Search in sources :

Example 11 with TestingLogicalSlotBuilder

use of org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder in project flink by apache.

the class ExecutionVertexCancelTest method testCancelCallFails.

@Test
public void testCancelCallFails() {
    try {
        final ExecutionVertex vertex = getExecutionVertex();
        LogicalSlot slot = new TestingLogicalSlotBuilder().setTaskManagerGateway(new CancelSequenceSimpleAckingTaskManagerGateway(0)).createTestingLogicalSlot();
        setVertexResource(vertex, slot);
        setVertexState(vertex, ExecutionState.RUNNING);
        assertEquals(ExecutionState.RUNNING, vertex.getExecutionState());
        vertex.cancel();
        // Callback fails, leading to CANCELED
        assertEquals(ExecutionState.CANCELED, vertex.getExecutionState());
        assertFalse(slot.isAlive());
        assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
        assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELING) > 0);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) ExecutionGraphTestUtils.getExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with TestingLogicalSlotBuilder

use of org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder in project flink by apache.

the class ExecutionVertexCancelTest method testRepeatedCancelFromRunning.

@Test
public void testRepeatedCancelFromRunning() {
    try {
        final ExecutionVertex vertex = getExecutionVertex();
        LogicalSlot slot = new TestingLogicalSlotBuilder().setTaskManagerGateway(new CancelSequenceSimpleAckingTaskManagerGateway(1)).createTestingLogicalSlot();
        setVertexResource(vertex, slot);
        setVertexState(vertex, ExecutionState.RUNNING);
        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().completeCancelling();
        assertEquals(ExecutionState.CANCELED, vertex.getExecutionState());
        assertFalse(slot.isAlive());
        assertFalse(vertex.getFailureInfo().isPresent());
        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 : TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) ExecutionGraphTestUtils.getExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with TestingLogicalSlotBuilder

use of org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder in project flink by apache.

the class DefaultSchedulerTest method testExceptionHistoryConcurrentRestart.

@Test
public void testExceptionHistoryConcurrentRestart() throws Exception {
    final JobGraph jobGraph = singleJobVertexJobGraph(2);
    final TaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
    final TestingLogicalSlotBuilder logicalSlotBuilder = new TestingLogicalSlotBuilder();
    logicalSlotBuilder.setTaskManagerLocation(taskManagerLocation);
    executionSlotAllocatorFactory = new TestExecutionSlotAllocatorFactory(logicalSlotBuilder);
    final ReorganizableManuallyTriggeredScheduledExecutor delayExecutor = new ReorganizableManuallyTriggeredScheduledExecutor();
    final TestFailoverStrategyFactory failoverStrategyFactory = new TestFailoverStrategyFactory();
    final DefaultScheduler scheduler = createScheduler(jobGraph, ComponentMainThreadExecutorServiceAdapter.forMainThread(), new PipelinedRegionSchedulingStrategy.Factory(), failoverStrategyFactory, delayExecutor);
    scheduler.startScheduling();
    final ExecutionVertex executionVertex0 = Iterables.get(scheduler.getExecutionGraph().getAllExecutionVertices(), 0);
    final ExecutionVertex executionVertex1 = Iterables.get(scheduler.getExecutionGraph().getAllExecutionVertices(), 1);
    // single-ExecutionVertex failure
    final RuntimeException exception0 = new RuntimeException("failure #0");
    failoverStrategyFactory.setTasksToRestart(executionVertex0.getID());
    final long updateStateTriggeringRestartTimestamp0 = initiateFailure(scheduler, executionVertex0.getCurrentExecutionAttempt().getAttemptId(), exception0);
    // multi-ExecutionVertex failure
    final RuntimeException exception1 = new RuntimeException("failure #1");
    failoverStrategyFactory.setTasksToRestart(executionVertex1.getID(), executionVertex0.getID());
    final long updateStateTriggeringRestartTimestamp1 = initiateFailure(scheduler, executionVertex1.getCurrentExecutionAttempt().getAttemptId(), exception1);
    // there might be a race condition with the delayExecutor if the tasks are scheduled quite
    // close to each other which we want to simulate here
    Collections.reverse(delayExecutor.getCollectedScheduledTasks());
    delayExecutor.triggerNonPeriodicScheduledTasks();
    assertThat(scheduler.getExceptionHistory(), IsIterableWithSize.iterableWithSize(2));
    final Iterator<RootExceptionHistoryEntry> actualExceptionHistory = scheduler.getExceptionHistory().iterator();
    final RootExceptionHistoryEntry entry0 = actualExceptionHistory.next();
    assertThat(entry0, is(ExceptionHistoryEntryMatcher.matchesFailure(exception0, updateStateTriggeringRestartTimestamp0, executionVertex0.getTaskNameWithSubtaskIndex(), executionVertex0.getCurrentAssignedResourceLocation())));
    assertThat(entry0.getConcurrentExceptions(), IsIterableContainingInOrder.contains(ExceptionHistoryEntryMatcher.matchesFailure(exception1, updateStateTriggeringRestartTimestamp1, executionVertex1.getTaskNameWithSubtaskIndex(), executionVertex1.getCurrentAssignedResourceLocation())));
    final RootExceptionHistoryEntry entry1 = actualExceptionHistory.next();
    assertThat(entry1, is(ExceptionHistoryEntryMatcher.matchesFailure(exception1, updateStateTriggeringRestartTimestamp1, executionVertex1.getTaskNameWithSubtaskIndex(), executionVertex1.getCurrentAssignedResourceLocation())));
    assertThat(entry1.getConcurrentExceptions(), IsEmptyIterable.emptyIterable());
}
Also used : RootExceptionHistoryEntry(org.apache.flink.runtime.scheduler.exceptionhistory.RootExceptionHistoryEntry) TestFailoverStrategyFactory(org.apache.flink.runtime.executiongraph.utils.TestFailoverStrategyFactory) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) ArchivedExecutionVertex(org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) SchedulingExecutionVertex(org.apache.flink.runtime.scheduler.strategy.SchedulingExecutionVertex) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) PipelinedRegionSchedulingStrategy(org.apache.flink.runtime.scheduler.strategy.PipelinedRegionSchedulingStrategy) AdaptiveSchedulerTest(org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest) Test(org.junit.Test)

Example 14 with TestingLogicalSlotBuilder

use of org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder in project flink by apache.

the class ExecutionGraphToInputsLocationsRetrieverAdapterTest method testGetTaskManagerLocationWhenScheduled.

/**
 * Tests that it can get the task manager location in an Execution.
 */
@Test
public void testGetTaskManagerLocationWhenScheduled() throws Exception {
    final JobVertex jobVertex = ExecutionGraphTestUtils.createNoOpVertex(1);
    final TestingLogicalSlot testingLogicalSlot = new TestingLogicalSlotBuilder().createTestingLogicalSlot();
    final ExecutionGraph eg = ExecutionGraphTestUtils.createSimpleTestGraph(jobVertex);
    final ExecutionGraphToInputsLocationsRetrieverAdapter inputsLocationsRetriever = new ExecutionGraphToInputsLocationsRetrieverAdapter(eg);
    final ExecutionVertex onlyExecutionVertex = eg.getAllExecutionVertices().iterator().next();
    onlyExecutionVertex.getCurrentExecutionAttempt().transitionState(ExecutionState.SCHEDULED);
    onlyExecutionVertex.deployToSlot(testingLogicalSlot);
    ExecutionVertexID executionVertexId = new ExecutionVertexID(jobVertex.getID(), 0);
    Optional<CompletableFuture<TaskManagerLocation>> taskManagerLocationOptional = inputsLocationsRetriever.getTaskManagerLocation(executionVertexId);
    assertTrue(taskManagerLocationOptional.isPresent());
    final CompletableFuture<TaskManagerLocation> taskManagerLocationFuture = taskManagerLocationOptional.get();
    assertThat(taskManagerLocationFuture.get(), is(testingLogicalSlot.getTaskManagerLocation()));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) TestingLogicalSlot(org.apache.flink.runtime.jobmaster.TestingLogicalSlot) TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) Test(org.junit.Test)

Example 15 with TestingLogicalSlotBuilder

use of org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder in project flink by apache.

the class DeploymentHandleTest method getLogicalSlotReturnsSlotIfFutureCompletedNormally.

@Test
public void getLogicalSlotReturnsSlotIfFutureCompletedNormally() {
    final LogicalSlot logicalSlot = new TestingLogicalSlotBuilder().createTestingLogicalSlot();
    logicalSlotFuture.complete(logicalSlot);
    assertTrue(deploymentHandle.getLogicalSlot().isPresent());
    assertSame(logicalSlot, deploymentHandle.getLogicalSlot().get());
}
Also used : TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Aggregations

TestingLogicalSlotBuilder (org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder)26 Test (org.junit.Test)19 LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)16 ExecutionGraphTestUtils.getExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex)10 ExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionVertex)7 TestingLogicalSlot (org.apache.flink.runtime.jobmaster.TestingLogicalSlot)7 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)6 IOException (java.io.IOException)5 SimpleAckingTaskManagerGateway (org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway)4 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)4 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)4 ArrayList (java.util.ArrayList)3 JobID (org.apache.flink.api.common.JobID)3 ExecutionGraph (org.apache.flink.runtime.executiongraph.ExecutionGraph)3 TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)3 List (java.util.List)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Configuration (org.apache.flink.configuration.Configuration)2 JobException (org.apache.flink.runtime.JobException)2