use of org.apache.flink.runtime.jobmaster.LogicalSlot 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.LogicalSlot in project flink by apache.
the class SharedSlotTest method testReleaseEmptyDoesNotCallAllocatorReleaseBack.
@Test
public void testReleaseEmptyDoesNotCallAllocatorReleaseBack() {
CompletableFuture<PhysicalSlot> slotContextFuture = CompletableFuture.completedFuture(new TestingPhysicalSlot(RP, new AllocationID()));
CompletableFuture<SharedSlot> sharedSlotReleaseFuture = new CompletableFuture<>();
AtomicInteger released = new AtomicInteger(0);
SharedSlot sharedSlot = SharedSlotBuilder.newBuilder().withSlotContextFuture(slotContextFuture).withExternalReleaseCallback(g -> {
// checks that release -> externalReleaseCallback -> release
// does not lead to infinite recursion
// due to SharedSlot.state.RELEASED check
sharedSlotReleaseFuture.join().release(new Throwable());
released.incrementAndGet();
}).build();
sharedSlotReleaseFuture.complete(sharedSlot);
LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot(EV1).join();
assertThat(released.get(), is(0));
// returns the only and last slot, calling the external release callback
sharedSlot.returnLogicalSlot(logicalSlot);
assertThat(released.get(), is(1));
// slot is already released, it should not get released again
sharedSlot.release(new Throwable());
assertThat(released.get(), is(1));
}
use of org.apache.flink.runtime.jobmaster.LogicalSlot in project flink by apache.
the class SharedSlotTest method testLogicalSlotAllocation.
@Test
public void testLogicalSlotAllocation() {
CompletableFuture<PhysicalSlot> slotContextFuture = new CompletableFuture<>();
CompletableFuture<ExecutionSlotSharingGroup> released = new CompletableFuture<>();
SharedSlot sharedSlot = SharedSlotBuilder.newBuilder().withSlotContextFuture(slotContextFuture).slotWillBeOccupiedIndefinitely().withExternalReleaseCallback(released::complete).build();
CompletableFuture<LogicalSlot> logicalSlotFuture = sharedSlot.allocateLogicalSlot(EV1);
assertThat(logicalSlotFuture.isDone(), is(false));
AllocationID allocationId = new AllocationID();
LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
SimpleAckingTaskManagerGateway taskManagerGateway = new SimpleAckingTaskManagerGateway();
slotContextFuture.complete(new TestingPhysicalSlot(allocationId, taskManagerLocation, 3, taskManagerGateway, RP));
assertThat(sharedSlot.isEmpty(), is(false));
assertThat(released.isDone(), is(false));
assertThat(logicalSlotFuture.isDone(), is(true));
LogicalSlot logicalSlot = logicalSlotFuture.join();
assertThat(logicalSlot.getAllocationId(), is(allocationId));
assertThat(logicalSlot.getTaskManagerLocation(), is(taskManagerLocation));
assertThat(logicalSlot.getTaskManagerGateway(), is(taskManagerGateway));
assertThat(logicalSlot.getLocality(), is(Locality.UNKNOWN));
}
use of org.apache.flink.runtime.jobmaster.LogicalSlot in project flink by apache.
the class TestExecutionSlotAllocator method createSlotVertexAssignments.
private List<SlotExecutionVertexAssignment> createSlotVertexAssignments(final Collection<ExecutionVertexID> executionVertexIds) {
final List<SlotExecutionVertexAssignment> result = new ArrayList<>();
for (ExecutionVertexID executionVertexId : executionVertexIds) {
final CompletableFuture<LogicalSlot> logicalSlotFuture = new CompletableFuture<>();
result.add(new SlotExecutionVertexAssignment(executionVertexId, logicalSlotFuture));
}
return result;
}
use of org.apache.flink.runtime.jobmaster.LogicalSlot in project flink by apache.
the class TestExecutionSlotAllocator method returnLogicalSlot.
@Override
public void returnLogicalSlot(final LogicalSlot logicalSlot) {
returnedSlots.add(logicalSlot);
if (completePendingRequestsWithReturnedSlots) {
if (pendingRequests.size() > 0) {
// logical slots are not re-usable, creating a new one instead.
final LogicalSlot slot = logicalSlotBuilder.setSlotOwner(this).createTestingLogicalSlot();
final SlotExecutionVertexAssignment slotVertexAssignment = pendingRequests.remove(pendingRequests.keySet().stream().findAny().get());
slotVertexAssignment.getLogicalSlotFuture().complete(slot);
}
}
}
Aggregations