Search in sources :

Example 6 with LocalTaskManagerLocation

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

Example 7 with LocalTaskManagerLocation

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);
}
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 8 with LocalTaskManagerLocation

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

Example 9 with LocalTaskManagerLocation

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()));
}
Also used : LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) TestingTaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 10 with LocalTaskManagerLocation

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();
    }
}
Also used : ComponentMainThreadExecutorServiceAdapter(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter) CoreMatchers.is(org.hamcrest.CoreMatchers.is) NoResourceAvailableException(org.apache.flink.runtime.jobmanager.scheduler.NoResourceAvailableException) Arrays(java.util.Arrays) ComponentMainThreadExecutor(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor) SystemClock(org.apache.flink.util.clock.SystemClock) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) RunWith(org.junit.runner.RunWith) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) CompletableFuture(java.util.concurrent.CompletableFuture) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) RpcTaskManagerGateway(org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway) Duration(java.time.Duration) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) Nonnull(javax.annotation.Nonnull) Parameterized(org.junit.runners.Parameterized) Collection(java.util.Collection) JobMasterId(org.apache.flink.runtime.jobmaster.JobMasterId) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) SimpleAckingTaskManagerGateway(org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) JobID(org.apache.flink.api.common.JobID) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SimpleAckingTaskManagerGateway(org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway) CompletableFuture(java.util.concurrent.CompletableFuture) SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Test(org.junit.Test)

Aggregations

LocalTaskManagerLocation (org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation)30 Test (org.junit.Test)24 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)13 SlotOffer (org.apache.flink.runtime.taskexecutor.slot.SlotOffer)12 TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)9 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)8 ResourceCounter (org.apache.flink.runtime.util.ResourceCounter)7 SimpleAckingTaskManagerGateway (org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway)6 CompletableFuture (java.util.concurrent.CompletableFuture)5 ArchivedExecutionVertex (org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex)5 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)5 RootExceptionHistoryEntry (org.apache.flink.runtime.scheduler.exceptionhistory.RootExceptionHistoryEntry)5 TestingTaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)5 FlinkException (org.apache.flink.util.FlinkException)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 JobID (org.apache.flink.api.common.JobID)4 Time (org.apache.flink.api.common.time.Time)4 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)4 List (java.util.List)3