Search in sources :

Example 16 with LogicalSlot

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

the class SingleLogicalSlotTest method testSlotRelease.

/**
 * Tests that the slot release is only signaled after the owner has taken it back.
 */
@Test
public void testSlotRelease() {
    final CompletableFuture<LogicalSlot> returnedSlotFuture = new CompletableFuture<>();
    final CompletableFuture<Boolean> returnSlotResponseFuture = new CompletableFuture<>();
    final WaitingSlotOwner waitingSlotOwner = new WaitingSlotOwner(returnedSlotFuture, returnSlotResponseFuture);
    final CompletableFuture<?> terminalStateFuture = new CompletableFuture<>();
    final CompletableFuture<?> failFuture = new CompletableFuture<>();
    final ManualTestingPayload dummyPayload = new ManualTestingPayload(failFuture, terminalStateFuture);
    final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot(waitingSlotOwner);
    assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload), is(true));
    final CompletableFuture<?> releaseFuture = singleLogicalSlot.releaseSlot(new FlinkException("Test exception"));
    assertThat(releaseFuture.isDone(), is(false));
    assertThat(returnedSlotFuture.isDone(), is(false));
    assertThat(failFuture.isDone(), is(true));
    terminalStateFuture.complete(null);
    assertThat(returnedSlotFuture.isDone(), is(true));
    returnSlotResponseFuture.complete(true);
    assertThat(releaseFuture.isDone(), is(true));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 17 with LogicalSlot

use of org.apache.flink.runtime.jobmaster.LogicalSlot 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 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());
        assertFalse(vertex.getFailureInfo().isPresent());
        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 18 with LogicalSlot

use of org.apache.flink.runtime.jobmaster.LogicalSlot 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 19 with LogicalSlot

use of org.apache.flink.runtime.jobmaster.LogicalSlot 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 20 with LogicalSlot

use of org.apache.flink.runtime.jobmaster.LogicalSlot 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

LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)57 Test (org.junit.Test)34 TestingLogicalSlotBuilder (org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder)18 CompletableFuture (java.util.concurrent.CompletableFuture)13 SlotRequestId (org.apache.flink.runtime.jobmaster.SlotRequestId)13 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)9 ExecutionGraphTestUtils.getExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex)9 TestingPhysicalSlot (org.apache.flink.runtime.scheduler.TestingPhysicalSlot)9 ExecutionVertexID (org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID)8 ExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionVertex)7 SimpleAckingTaskManagerGateway (org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 TaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway)6 FlinkException (org.apache.flink.util.FlinkException)6 TestLogger (org.apache.flink.util.TestLogger)6 IOException (java.io.IOException)5 List (java.util.List)5 Map (java.util.Map)5 Consumer (java.util.function.Consumer)5