use of org.apache.flink.runtime.util.ResourceCounter 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.util.ResourceCounter in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method testIncreasingResourceRequirementsWillSendResourceRequirementNotification.
@Test
public void testIncreasingResourceRequirementsWillSendResourceRequirementNotification() throws InterruptedException {
final NewResourceRequirementsService requirementsListener = new NewResourceRequirementsService();
final DeclarativeSlotPool slotPool = createDefaultDeclarativeSlotPool(requirementsListener);
final ResourceCounter increment1 = ResourceCounter.withResource(RESOURCE_PROFILE_1, 1);
final ResourceCounter increment2 = createResourceRequirements();
slotPool.increaseResourceRequirementsBy(increment1);
slotPool.increaseResourceRequirementsBy(increment2);
assertThat(requirementsListener.takeResourceRequirements(), is(toResourceRequirements(increment1)));
final ResourceCounter totalResources = increment1.add(increment2);
assertThat(requirementsListener.takeResourceRequirements(), is(toResourceRequirements(totalResources)));
assertThat(requirementsListener.hasNextResourceRequirements(), is(false));
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method testSetResourceRequirementsForInitialResourceRequirements.
@Test
public void testSetResourceRequirementsForInitialResourceRequirements() {
final DefaultDeclarativeSlotPool slotPool = new DefaultDeclarativeSlotPoolBuilder().build();
final ResourceCounter resourceRequirements = ResourceCounter.withResource(RESOURCE_PROFILE_1, 2);
slotPool.setResourceRequirements(resourceRequirements);
assertThat(slotPool.getResourceRequirements(), is(toResourceRequirements(resourceRequirements)));
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method testDuplicateSlotOfferings.
@Test
public void testDuplicateSlotOfferings() throws InterruptedException {
final NewSlotsService notifyNewSlots = new NewSlotsService();
final DefaultDeclarativeSlotPool slotPool = createDefaultDeclarativeSlotPoolWithNewSlotsListener(notifyNewSlots);
final ResourceCounter resourceRequirements = createResourceRequirements();
slotPool.increaseResourceRequirementsBy(resourceRequirements);
final Collection<SlotOffer> slotOffers = createSlotOffersForResourceRequirements(resourceRequirements);
SlotPoolTestUtils.offerSlots(slotPool, slotOffers);
drainNewSlotService(notifyNewSlots);
final Collection<SlotOffer> acceptedSlots = SlotPoolTestUtils.offerSlots(slotPool, slotOffers);
assertThat(acceptedSlots, containsInAnyOrder(slotOffers.toArray()));
// duplicate slots should not trigger notify new slots
assertFalse(notifyNewSlots.hasNextNewSlots());
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method testGetResourceRequirements.
@Test
public void testGetResourceRequirements() {
final DefaultDeclarativeSlotPool slotPool = DefaultDeclarativeSlotPoolBuilder.builder().build();
assertThat(slotPool.getResourceRequirements(), is(toResourceRequirements(ResourceCounter.empty())));
final ResourceCounter resourceRequirements = createResourceRequirements();
slotPool.increaseResourceRequirementsBy(resourceRequirements);
assertThat(slotPool.getResourceRequirements(), is(toResourceRequirements(resourceRequirements)));
}
Aggregations