Search in sources :

Example 6 with ResourceCounter

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);
}
Also used : SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) TestingTaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)

Example 7 with ResourceCounter

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));
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) Test(org.junit.Test)

Example 8 with ResourceCounter

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)));
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) Test(org.junit.Test)

Example 9 with ResourceCounter

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());
}
Also used : SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) Test(org.junit.Test)

Example 10 with ResourceCounter

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)));
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) Test(org.junit.Test)

Aggregations

ResourceCounter (org.apache.flink.runtime.util.ResourceCounter)39 Test (org.junit.Test)24 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)10 SlotOffer (org.apache.flink.runtime.taskexecutor.slot.SlotOffer)8 FlinkException (org.apache.flink.util.FlinkException)7 Map (java.util.Map)5 JobID (org.apache.flink.api.common.JobID)5 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)5 LocalTaskManagerLocation (org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation)5 ArrayList (java.util.ArrayList)4 TestingTaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)4 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)4 HashMap (java.util.HashMap)3 Time (org.apache.flink.api.common.time.Time)3 ArchivedExecutionGraphTest (org.apache.flink.runtime.executiongraph.ArchivedExecutionGraphTest)3 DefaultSchedulerTest (org.apache.flink.runtime.scheduler.DefaultSchedulerTest)3 ResourceRequirement (org.apache.flink.runtime.slots.ResourceRequirement)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 InstanceID (org.apache.flink.runtime.instance.InstanceID)2 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)2