Search in sources :

Example 26 with SlotRequestId

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

the class SlotSharingExecutionSlotAllocatorTest method testPhysicalSlotReleaseLogicalSlots.

@Test
public void testPhysicalSlotReleaseLogicalSlots() throws ExecutionException, InterruptedException {
    AllocationContext context = AllocationContext.newBuilder().addGroup(EV1, EV2).build();
    List<SlotExecutionVertexAssignment> assignments = context.allocateSlotsFor(EV1, EV2);
    List<TestingPayload> payloads = assignments.stream().map(assignment -> {
        TestingPayload payload = new TestingPayload();
        assignment.getLogicalSlotFuture().thenAccept(logicalSlot -> logicalSlot.tryAssignPayload(payload));
        return payload;
    }).collect(Collectors.toList());
    SlotRequestId slotRequestId = context.getSlotProvider().getFirstRequestOrFail().getSlotRequestId();
    TestingPhysicalSlot physicalSlot = context.getSlotProvider().getFirstResponseOrFail().get();
    assertThat(payloads.stream().allMatch(payload -> payload.getTerminalStateFuture().isDone()), is(false));
    assertThat(physicalSlot.getPayload(), notNullValue());
    physicalSlot.getPayload().release(new Throwable());
    assertThat(payloads.stream().allMatch(payload -> payload.getTerminalStateFuture().isDone()), is(true));
    assertThat(context.getSlotProvider().getCancellations().containsKey(slotRequestId), is(true));
    context.allocateSlotsFor(EV1, EV2);
    // there should be one more physical slot allocation, as the first allocation should be
    // removed after releasing all logical slots
    assertThat(context.getSlotProvider().getRequests().keySet(), hasSize(2));
}
Also used : DummyPayload(org.apache.flink.runtime.jobmaster.slotpool.DummyPayload) CoreMatchers.is(org.hamcrest.CoreMatchers.is) FlinkException(org.apache.flink.util.FlinkException) BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) Arrays(java.util.Arrays) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest) PhysicalSlotRequestBulk(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequestBulk) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) SharedSlotProfileRetrieverFactory(org.apache.flink.runtime.scheduler.SharedSlotProfileRetriever.SharedSlotProfileRetrieverFactory) Map(java.util.Map) PhysicalSlotRequestBulkChecker(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequestBulkChecker) TestLogger(org.apache.flink.util.TestLogger) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.fail(org.junit.Assert.fail) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) ExecutionGraphTestUtils.createRandomExecutionVertexId(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createRandomExecutionVertexId) Matchers.empty(org.hamcrest.Matchers.empty) CancellationException(java.util.concurrent.CancellationException) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Collection(java.util.Collection) TestingPayload(org.apache.flink.runtime.jobmaster.TestingPayload) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) SlotProfileTestingUtils(org.apache.flink.runtime.clusterframework.types.SlotProfileTestingUtils) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Optional(java.util.Optional) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPayload(org.apache.flink.runtime.jobmaster.TestingPayload) Test(org.junit.Test)

Example 27 with SlotRequestId

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

the class SlotSharingExecutionSlotAllocatorTest method fulfilOneOfTwoSlotRequestsAndGetPendingProfile.

private static ResourceProfile fulfilOneOfTwoSlotRequestsAndGetPendingProfile(AllocationContext context, AllocationID allocationId) {
    Map<SlotRequestId, PhysicalSlotRequest> requests = context.getSlotProvider().getRequests();
    List<SlotRequestId> slotRequestIds = new ArrayList<>(requests.keySet());
    assertThat(slotRequestIds, hasSize(2));
    SlotRequestId slotRequestId1 = slotRequestIds.get(0);
    SlotRequestId slotRequestId2 = slotRequestIds.get(1);
    context.getSlotProvider().getResultForRequestId(slotRequestId1).complete(TestingPhysicalSlot.builder().withAllocationID(allocationId).build());
    return requests.get(slotRequestId2).getSlotProfile().getPhysicalSlotResourceProfile();
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest) ArrayList(java.util.ArrayList)

Example 28 with SlotRequestId

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

the class SlotSharingExecutionSlotAllocatorTest method testFailedPhysicalSlotRequestFailsLogicalSlotFuturesAndRemovesSharedSlot.

@Test
public void testFailedPhysicalSlotRequestFailsLogicalSlotFuturesAndRemovesSharedSlot() {
    AllocationContext context = AllocationContext.newBuilder().addGroup(EV1).withPhysicalSlotProvider(TestingPhysicalSlotProvider.createWithoutImmediatePhysicalSlotCreation()).build();
    CompletableFuture<LogicalSlot> logicalSlotFuture = context.allocateSlotsFor(EV1).get(0).getLogicalSlotFuture();
    SlotRequestId slotRequestId = context.getSlotProvider().getFirstRequestOrFail().getSlotRequestId();
    assertThat(logicalSlotFuture.isDone(), is(false));
    context.getSlotProvider().getResponses().get(slotRequestId).completeExceptionally(new Throwable());
    assertThat(logicalSlotFuture.isCompletedExceptionally(), is(true));
    // next allocation allocates new shared slot
    context.allocateSlotsFor(EV1);
    assertThat(context.getSlotProvider().getRequests().keySet(), hasSize(2));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 29 with SlotRequestId

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

the class SlotSharingExecutionSlotAllocatorTest method testLogicalSlotRequestCancellationOrRelease.

private static void testLogicalSlotRequestCancellationOrRelease(boolean completePhysicalSlotFutureManually, boolean cancelsPhysicalSlotRequestAndRemovesSharedSlot, BiConsumerWithException<AllocationContext, SlotExecutionVertexAssignment, Exception> cancelOrReleaseAction) throws Exception {
    AllocationContext.Builder allocationContextBuilder = AllocationContext.newBuilder().addGroup(EV1, EV2, EV3);
    if (completePhysicalSlotFutureManually) {
        allocationContextBuilder.withPhysicalSlotProvider(TestingPhysicalSlotProvider.createWithoutImmediatePhysicalSlotCreation());
    }
    AllocationContext context = allocationContextBuilder.build();
    List<SlotExecutionVertexAssignment> assignments = context.allocateSlotsFor(EV1, EV2);
    assertThat(context.getSlotProvider().getRequests().keySet(), hasSize(1));
    // cancel or release only one sharing logical slots
    cancelOrReleaseAction.accept(context, assignments.get(0));
    List<SlotExecutionVertexAssignment> assignmentsAfterOneCancellation = context.allocateSlotsFor(EV1, EV2);
    // there should be no more physical slot allocations, as the first logical slot reuses the
    // previous shared slot
    assertThat(context.getSlotProvider().getRequests().keySet(), hasSize(1));
    // cancel or release all sharing logical slots
    for (SlotExecutionVertexAssignment assignment : assignmentsAfterOneCancellation) {
        cancelOrReleaseAction.accept(context, assignment);
    }
    SlotRequestId slotRequestId = context.getSlotProvider().getFirstRequestOrFail().getSlotRequestId();
    assertThat(context.getSlotProvider().getCancellations().containsKey(slotRequestId), is(cancelsPhysicalSlotRequestAndRemovesSharedSlot));
    context.allocateSlotsFor(EV3);
    // there should be one more physical slot allocation if the first allocation should be
    // removed with all logical slots
    int expectedNumberOfRequests = cancelsPhysicalSlotRequestAndRemovesSharedSlot ? 2 : 1;
    assertThat(context.getSlotProvider().getRequests().keySet(), hasSize(expectedNumberOfRequests));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId)

Example 30 with SlotRequestId

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

the class SlotSharingExecutionSlotAllocatorTest method testBulkClearIfPhysicalSlotRequestFails.

@Test
public void testBulkClearIfPhysicalSlotRequestFails() {
    TestingPhysicalSlotRequestBulkChecker bulkChecker = new TestingPhysicalSlotRequestBulkChecker();
    AllocationContext context = createBulkCheckerContextWithEv12GroupAndEv3Group(bulkChecker);
    context.allocateSlotsFor(EV1, EV3);
    SlotRequestId slotRequestId = context.getSlotProvider().getFirstRequestOrFail().getSlotRequestId();
    context.getSlotProvider().getResultForRequestId(slotRequestId).completeExceptionally(new Throwable());
    PhysicalSlotRequestBulk bulk = bulkChecker.getBulk();
    assertThat(bulk.getPendingRequests(), hasSize(0));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) PhysicalSlotRequestBulk(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequestBulk) Test(org.junit.Test)

Aggregations

SlotRequestId (org.apache.flink.runtime.jobmaster.SlotRequestId)51 Test (org.junit.Test)40 TestingPhysicalSlot (org.apache.flink.runtime.scheduler.TestingPhysicalSlot)15 LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)11 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)8 TestLogger (org.apache.flink.util.TestLogger)6 Collectors (java.util.stream.Collectors)5 CoreMatchers.is (org.hamcrest.CoreMatchers.is)5 Assert.fail (org.junit.Assert.fail)5 Collection (java.util.Collection)4 Collections (java.util.Collections)4 List (java.util.List)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Consumer (java.util.function.Consumer)4 Time (org.apache.flink.api.common.time.Time)4 Arrays (java.util.Arrays)3 ExecutionException (java.util.concurrent.ExecutionException)3 SlotProfile (org.apache.flink.runtime.clusterframework.types.SlotProfile)3