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));
}
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();
}
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));
}
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));
}
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));
}
Aggregations