use of org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method testRegisterSlotsAcceptsAllSlots.
@Test
public void testRegisterSlotsAcceptsAllSlots() {
final DefaultDeclarativeSlotPool declarativeSlotPool = createDefaultDeclarativeSlotPool();
final int numberSlots = 10;
final Collection<SlotOffer> slots = createSlotOffersForResourceRequirements(ResourceCounter.withResource(RESOURCE_PROFILE_1, numberSlots));
declarativeSlotPool.registerSlots(slots, new LocalTaskManagerLocation(), SlotPoolTestUtils.createTaskManagerGateway(null), 0);
final Collection<? extends SlotInfo> allSlotsInformation = declarativeSlotPool.getAllSlotsInformation();
assertThat(allSlotsInformation, hasSize(numberSlots));
for (SlotInfo slotInfo : allSlotsInformation) {
assertThat(slotInfo.getResourceProfile(), is(RESOURCE_PROFILE_1));
}
}
use of org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method withSlotPoolContainingOneTaskManagerWithTwoSlotsWithUniqueResourceProfiles.
private static void withSlotPoolContainingOneTaskManagerWithTwoSlotsWithUniqueResourceProfiles(QuadConsumer<DefaultDeclarativeSlotPool, SlotOffer, SlotOffer, TaskManagerLocation> test) {
final DefaultDeclarativeSlotPool slotPool = DefaultDeclarativeSlotPoolBuilder.builder().build();
final ResourceCounter resourceRequirements = ResourceCounter.withResource(RESOURCE_PROFILE_1, 1).add(RESOURCE_PROFILE_2, 1);
final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
final FreeSlotConsumer freeSlotConsumer = new FreeSlotConsumer();
final TestingTaskExecutorGateway testingTaskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setFreeSlotFunction(freeSlotConsumer).createTestingTaskExecutorGateway();
final Iterator<SlotOffer> slotOffers = increaseRequirementsAndOfferSlotsToSlotPool(slotPool, resourceRequirements, taskManagerLocation, testingTaskExecutorGateway).iterator();
final SlotOffer slot1 = slotOffers.next();
final SlotOffer slot2 = slotOffers.next();
test.accept(slotPool, slot1, slot2, taskManagerLocation);
}
use of org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method testReleaseSlotsRemovesSlots.
@Test
public void testReleaseSlotsRemovesSlots() throws InterruptedException {
final NewResourceRequirementsService notifyNewResourceRequirements = new NewResourceRequirementsService();
final DefaultDeclarativeSlotPool slotPool = createDefaultDeclarativeSlotPool(notifyNewResourceRequirements);
final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
increaseRequirementsAndOfferSlotsToSlotPool(slotPool, createResourceRequirements(), taskManagerLocation);
notifyNewResourceRequirements.takeResourceRequirements();
slotPool.releaseSlots(taskManagerLocation.getResourceID(), new FlinkException("Test failure"));
assertThat(slotPool.getAllSlotsInformation(), is(empty()));
}
use of org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method testReleaseSlotReturnsSlot.
@Test
public void testReleaseSlotReturnsSlot() throws InterruptedException {
final NewSlotsService notifyNewSlots = new NewSlotsService();
final DefaultDeclarativeSlotPool slotPool = createDefaultDeclarativeSlotPoolWithNewSlotsListener(notifyNewSlots);
final ResourceCounter resourceRequirements = createResourceRequirements();
final FreeSlotConsumer freeSlotConsumer = new FreeSlotConsumer();
final TestingTaskExecutorGateway testingTaskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setFreeSlotFunction(freeSlotConsumer).createTestingTaskExecutorGateway();
increaseRequirementsAndOfferSlotsToSlotPool(slotPool, resourceRequirements, new LocalTaskManagerLocation(), testingTaskExecutorGateway);
final Collection<? extends PhysicalSlot> physicalSlots = notifyNewSlots.takeNewSlots();
final PhysicalSlot physicalSlot = physicalSlots.iterator().next();
slotPool.releaseSlot(physicalSlot.getAllocationId(), new FlinkException("Test failure"));
final AllocationID freedSlot = Iterables.getOnlyElement(freeSlotConsumer.drainFreedSlots());
assertThat(freedSlot, is(physicalSlot.getAllocationId()));
}
use of org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation in project flink by apache.
the class DeclarativeSlotPoolBridgeTest method testIfJobIsRestartingAllOfferedSlotsWillBeRegistered.
@Test
public void testIfJobIsRestartingAllOfferedSlotsWillBeRegistered() throws Exception {
final CompletableFuture<Void> registerSlotsCalledFuture = new CompletableFuture<>();
final TestingDeclarativeSlotPoolFactory declarativeSlotPoolFactory = new TestingDeclarativeSlotPoolFactory(TestingDeclarativeSlotPool.builder().setRegisterSlotsFunction((slotOffers, taskManagerLocation, taskManagerGateway, aLong) -> registerSlotsCalledFuture.complete(null)));
try (DeclarativeSlotPoolBridge declarativeSlotPoolBridge = createDeclarativeSlotPoolBridge(declarativeSlotPoolFactory, requestSlotMatchingStrategy)) {
declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
declarativeSlotPoolBridge.setIsJobRestarting(true);
final LocalTaskManagerLocation localTaskManagerLocation = new LocalTaskManagerLocation();
declarativeSlotPoolBridge.registerTaskManager(localTaskManagerLocation.getResourceID());
declarativeSlotPoolBridge.offerSlots(localTaskManagerLocation, new SimpleAckingTaskManagerGateway(), Collections.singleton(new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY)));
// make sure that the register slots method is called
registerSlotsCalledFuture.join();
}
}
Aggregations