use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class SimpleRequestSlotMatchingStrategyTest method testSlotRequestsAreMatchedInOrder.
@Test
public void testSlotRequestsAreMatchedInOrder() {
final SimpleRequestSlotMatchingStrategy simpleRequestSlotMatchingStrategy = SimpleRequestSlotMatchingStrategy.INSTANCE;
final Collection<PhysicalSlot> slots = Arrays.asList(TestingPhysicalSlot.builder().build());
final PendingRequest pendingRequest1 = PendingRequest.createNormalRequest(new SlotRequestId(), ResourceProfile.UNKNOWN, Collections.emptyList());
final PendingRequest pendingRequest2 = PendingRequest.createNormalRequest(new SlotRequestId(), ResourceProfile.UNKNOWN, Collections.emptyList());
final Collection<PendingRequest> pendingRequests = Arrays.asList(pendingRequest1, pendingRequest2);
final Collection<RequestSlotMatchingStrategy.RequestSlotMatch> requestSlotMatches = simpleRequestSlotMatchingStrategy.matchRequestsAndSlots(slots, pendingRequests);
assertThat(requestSlotMatches).hasSize(1);
assertThat(Iterators.getOnlyElement(requestSlotMatches.iterator()).getPendingRequest().getSlotRequestId()).isEqualTo(pendingRequest1.getSlotRequestId());
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class DeclarativeSlotPoolBridgeTest method testSlotOffer.
@Test
public void testSlotOffer() throws Exception {
final SlotRequestId slotRequestId = new SlotRequestId();
final AllocationID expectedAllocationId = new AllocationID();
final PhysicalSlot allocatedSlot = createAllocatedSlot(expectedAllocationId);
final TestingDeclarativeSlotPoolFactory declarativeSlotPoolFactory = new TestingDeclarativeSlotPoolFactory(TestingDeclarativeSlotPool.builder());
try (DeclarativeSlotPoolBridge declarativeSlotPoolBridge = createDeclarativeSlotPoolBridge(declarativeSlotPoolFactory, requestSlotMatchingStrategy)) {
declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
CompletableFuture<PhysicalSlot> slotAllocationFuture = declarativeSlotPoolBridge.requestNewAllocatedSlot(slotRequestId, ResourceProfile.UNKNOWN, null);
declarativeSlotPoolBridge.newSlotsAreAvailable(Collections.singleton(allocatedSlot));
slotAllocationFuture.join();
}
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class DeclarativeSlotPoolBridgeTest method testNoConcurrentModificationWhenSuspendingAndReleasingSlot.
@Test
public void testNoConcurrentModificationWhenSuspendingAndReleasingSlot() throws Exception {
try (DeclarativeSlotPoolBridge declarativeSlotPoolBridge = createDeclarativeSlotPoolBridge(new DefaultDeclarativeSlotPoolFactory(), requestSlotMatchingStrategy)) {
declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
final List<SlotRequestId> slotRequestIds = Arrays.asList(new SlotRequestId(), new SlotRequestId());
final List<CompletableFuture<PhysicalSlot>> slotFutures = slotRequestIds.stream().map(slotRequestId -> {
final CompletableFuture<PhysicalSlot> slotFuture = declarativeSlotPoolBridge.requestNewAllocatedSlot(slotRequestId, ResourceProfile.UNKNOWN, rpcTimeout);
slotFuture.whenComplete((physicalSlot, throwable) -> {
if (throwable != null) {
declarativeSlotPoolBridge.releaseSlot(slotRequestId, throwable);
}
});
return slotFuture;
}).collect(Collectors.toList());
declarativeSlotPoolBridge.close();
try {
FutureUtils.waitForAll(slotFutures).get();
fail("The slot futures should be completed exceptionally.");
} catch (ExecutionException expected) {
// expected
}
}
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class PreferredAllocationRequestSlotMatchingStrategyTest method testNewSlotsAreMatchedAgainstPreferredAllocationIDs.
/**
* This test ensures that new slots are matched against the preferred allocationIds of the
* pending requests.
*/
@Test
public void testNewSlotsAreMatchedAgainstPreferredAllocationIDs() throws Exception {
final PreferredAllocationRequestSlotMatchingStrategy strategy = PreferredAllocationRequestSlotMatchingStrategy.INSTANCE;
final AllocationID allocationId1 = new AllocationID();
final AllocationID allocationId2 = new AllocationID();
final Collection<TestingPhysicalSlot> slots = Arrays.asList(TestingPhysicalSlot.builder().withAllocationID(allocationId1).build(), TestingPhysicalSlot.builder().withAllocationID(allocationId2).build());
final Collection<PendingRequest> pendingRequests = Arrays.asList(PendingRequest.createNormalRequest(new SlotRequestId(), ResourceProfile.UNKNOWN, Collections.singleton(allocationId2)), PendingRequest.createNormalRequest(new SlotRequestId(), ResourceProfile.UNKNOWN, Collections.singleton(allocationId1)));
final Collection<RequestSlotMatchingStrategy.RequestSlotMatch> requestSlotMatches = strategy.matchRequestsAndSlots(slots, pendingRequests);
assertThat(requestSlotMatches).hasSize(2);
for (RequestSlotMatchingStrategy.RequestSlotMatch requestSlotMatch : requestSlotMatches) {
assertThat(requestSlotMatch.getPendingRequest().getPreferredAllocations()).contains(requestSlotMatch.getSlot().getAllocationId());
}
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class SlotSharingExecutionSlotAllocatorTest method failLogicalSlotsIfPhysicalSlotIsFailed.
@Test
public void failLogicalSlotsIfPhysicalSlotIsFailed() {
final TestingPhysicalSlotRequestBulkChecker bulkChecker = new TestingPhysicalSlotRequestBulkChecker();
AllocationContext context = AllocationContext.newBuilder().addGroup(EV1, EV2).withBulkChecker(bulkChecker).withPhysicalSlotProvider(TestingPhysicalSlotProvider.createWithFailingPhysicalSlotCreation(new FlinkException("test failure"))).build();
final List<SlotExecutionVertexAssignment> allocatedSlots = context.allocateSlotsFor(EV1, EV2);
for (SlotExecutionVertexAssignment allocatedSlot : allocatedSlots) {
assertTrue(allocatedSlot.getLogicalSlotFuture().isCompletedExceptionally());
}
assertThat(bulkChecker.getBulk().getPendingRequests(), is(empty()));
final Set<SlotRequestId> requests = context.getSlotProvider().getRequests().keySet();
assertThat(context.getSlotProvider().getCancellations().keySet(), is(requests));
}
Aggregations