use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method testReleaseSlotDecreasesFulfilledResourceRequirements.
@Test
public void testReleaseSlotDecreasesFulfilledResourceRequirements() throws InterruptedException {
final NewSlotsService notifyNewSlots = new NewSlotsService();
final DefaultDeclarativeSlotPool slotPool = createDefaultDeclarativeSlotPoolWithNewSlotsListener(notifyNewSlots);
final ResourceCounter resourceRequirements = createResourceRequirements();
increaseRequirementsAndOfferSlotsToSlotPool(slotPool, resourceRequirements, null);
final Collection<? extends PhysicalSlot> physicalSlots = notifyNewSlots.takeNewSlots();
final PhysicalSlot physicalSlot = physicalSlots.iterator().next();
slotPool.releaseSlot(physicalSlot.getAllocationId(), new FlinkException("Test failure"));
final ResourceCounter finalResourceRequirements = resourceRequirements.subtract(physicalSlot.getResourceProfile(), 1);
assertThat(slotPool.getFulfilledResourceRequirements(), is(finalResourceRequirements));
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class FineGrainedTaskManagerTrackerTest method testAddAndRemovePendingTaskManager.
@Test
public void testAddAndRemovePendingTaskManager() {
final PendingTaskManager pendingTaskManager = new PendingTaskManager(ResourceProfile.ANY, 1);
final FineGrainedTaskManagerTracker taskManagerTracker = new FineGrainedTaskManagerTracker();
final JobID jobId = new JobID();
final ResourceCounter resourceCounter = ResourceCounter.withResource(ResourceProfile.ANY, 1);
// Add pending task manager
taskManagerTracker.addPendingTaskManager(pendingTaskManager);
taskManagerTracker.replaceAllPendingAllocations(Collections.singletonMap(pendingTaskManager.getPendingTaskManagerId(), Collections.singletonMap(jobId, resourceCounter)));
assertThat(taskManagerTracker.getPendingTaskManagers().size(), is(1));
assertThat(taskManagerTracker.getPendingTaskManagersByTotalAndDefaultSlotResourceProfile(ResourceProfile.ANY, ResourceProfile.ANY).size(), is(1));
// Remove pending task manager
final Map<JobID, ResourceCounter> records = taskManagerTracker.removePendingTaskManager(pendingTaskManager.getPendingTaskManagerId());
assertThat(taskManagerTracker.getPendingTaskManagers(), is(empty()));
assertThat(taskManagerTracker.getPendingAllocationsOfPendingTaskManager(pendingTaskManager.getPendingTaskManagerId()).size(), is(0));
assertThat(taskManagerTracker.getPendingTaskManagersByTotalAndDefaultSlotResourceProfile(ResourceProfile.ANY, ResourceProfile.ANY).size(), is(0));
assertTrue(records.containsKey(jobId));
assertThat(records.get(jobId).getResourceCount(ResourceProfile.ANY), is(1));
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class AdaptiveSchedulerTest method testHasEnoughResourcesReturnsTrueIfSatisfied.
@Test
public void testHasEnoughResourcesReturnsTrueIfSatisfied() throws Exception {
final JobGraph jobGraph = createJobGraph();
final DefaultDeclarativeSlotPool declarativeSlotPool = createDeclarativeSlotPool(jobGraph.getJobID());
final AdaptiveScheduler scheduler = new AdaptiveSchedulerBuilder(jobGraph, mainThreadExecutor).setDeclarativeSlotPool(declarativeSlotPool).build();
scheduler.startScheduling();
final ResourceCounter resourceRequirement = ResourceCounter.withResource(ResourceProfile.UNKNOWN, 1);
offerSlots(declarativeSlotPool, createSlotOffersForResourceRequirements(resourceRequirement));
assertThat(scheduler.hasDesiredResources(resourceRequirement)).isTrue();
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class SlotSharingSlotAllocatorTest method testCalculateRequiredSlots.
@Test
public void testCalculateRequiredSlots() {
final SlotSharingSlotAllocator slotAllocator = SlotSharingSlotAllocator.createSlotSharingSlotAllocator(TEST_RESERVE_SLOT_FUNCTION, TEST_FREE_SLOT_FUNCTION, TEST_IS_SLOT_FREE_FUNCTION);
final ResourceCounter resourceCounter = slotAllocator.calculateRequiredSlots(Arrays.asList(vertex1, vertex2, vertex3));
assertThat(resourceCounter.getResources(), contains(ResourceProfile.UNKNOWN));
assertThat(resourceCounter.getResourceCount(ResourceProfile.UNKNOWN), is(Math.max(vertex1.getParallelism(), vertex2.getParallelism()) + vertex3.getParallelism()));
}
Aggregations