use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class SharedSlotTest method testAllocateLogicalSlotIssuesUniqueSlotRequestIds.
@Test
public void testAllocateLogicalSlotIssuesUniqueSlotRequestIds() {
final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
});
final LogicalSlot logicalSlot1 = sharedSlot.allocateLogicalSlot();
final LogicalSlot logicalSlot2 = sharedSlot.allocateLogicalSlot();
assertThat(logicalSlot1.getSlotRequestId(), not(equalTo(logicalSlot2.getSlotRequestId())));
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class SharedSlotTest method testReturnLogicalSlotRejectsAliveSlots.
@Test(expected = IllegalStateException.class)
public void testReturnLogicalSlotRejectsAliveSlots() {
final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
});
final LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot();
sharedSlot.returnLogicalSlot(logicalSlot);
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class SharedSlotTest method testCanReturnLogicalSlotDuringRelease.
@Test
public void testCanReturnLogicalSlotDuringRelease() {
final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
});
final LogicalSlot logicalSlot1 = sharedSlot.allocateLogicalSlot();
final LogicalSlot logicalSlot2 = sharedSlot.allocateLogicalSlot();
// both slots try to release the other one, simulating that the failure of one execution due
// to the release also fails others
logicalSlot1.tryAssignPayload(new TestLogicalSlotPayload(cause -> {
if (logicalSlot2.isAlive()) {
logicalSlot2.releaseSlot(cause);
}
}));
logicalSlot2.tryAssignPayload(new TestLogicalSlotPayload(cause -> {
if (logicalSlot1.isAlive()) {
logicalSlot1.releaseSlot(cause);
}
}));
sharedSlot.release(new Exception("test"));
// if all logical slots were released, and the sharedSlot no longer allows the allocation of
// logical slots, then the slot release was completed
assertThat(logicalSlot1.isAlive(), is(false));
assertThat(logicalSlot2.isAlive(), is(false));
try {
sharedSlot.allocateLogicalSlot();
fail("Allocation of logical slot should have failed because the slot was released.");
} catch (IllegalStateException expected) {
}
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class DeclarativeSlotPoolBridgeResourceDeclarationTest method testRequirementsIncreasedOnSlotReservation.
@Test
public void testRequirementsIncreasedOnSlotReservation() throws Exception {
declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
final PhysicalSlot newSlot = createAllocatedSlot(new AllocationID());
declarativeSlotPoolBridge.newSlotsAreAvailable(Collections.singleton(newSlot));
// allocating (==reserving) an available (==free) slot should increase the requirements
final SlotRequestId slotRequestId = new SlotRequestId();
declarativeSlotPoolBridge.allocateAvailableSlot(slotRequestId, newSlot.getAllocationId(), ResourceProfile.UNKNOWN);
assertThat(requirementListener.getRequirements().getResourceCount(ResourceProfile.UNKNOWN), is(1));
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class DeclarativeSlotPoolBridgeResourceDeclarationTest method testRequirementsDecreasedOnAllocationTimeout.
@Test
public void testRequirementsDecreasedOnAllocationTimeout() throws Exception {
final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
try {
ComponentMainThreadExecutor mainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forSingleThreadExecutor(scheduledExecutorService);
declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
// requesting the allocation of a new slot increases the requirements
final CompletableFuture<PhysicalSlot> allocationFuture = CompletableFuture.supplyAsync(() -> declarativeSlotPoolBridge.requestNewAllocatedSlot(new SlotRequestId(), ResourceProfile.UNKNOWN, Time.milliseconds(5)), mainThreadExecutor).get();
// waiting for the timeout
assertThat(allocationFuture, FlinkMatchers.futureWillCompleteExceptionally(Duration.ofMinutes(1)));
// when the allocation fails the requirements should be reduced (it is the users
// responsibility to retry)
CompletableFuture.runAsync(() -> assertThat(requirementListener.getRequirements().getResourceCount(ResourceProfile.UNKNOWN), is(0)), mainThreadExecutor).join();
} finally {
scheduledExecutorService.shutdown();
}
}
Aggregations