Search in sources :

Example 36 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.

the class DeclarativeSlotPoolBridgeTest method testNotEnoughResourcesAvailableFailsPendingRequests.

@Test
public void testNotEnoughResourcesAvailableFailsPendingRequests() throws Exception {
    final SlotRequestId slotRequestId = new SlotRequestId();
    final TestingDeclarativeSlotPoolFactory declarativeSlotPoolFactory = new TestingDeclarativeSlotPoolFactory(TestingDeclarativeSlotPool.builder());
    try (DeclarativeSlotPoolBridge declarativeSlotPoolBridge = createDeclarativeSlotPoolBridge(declarativeSlotPoolFactory, requestSlotMatchingStrategy)) {
        declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
        CompletableFuture<PhysicalSlot> slotAllocationFuture = CompletableFuture.supplyAsync(() -> declarativeSlotPoolBridge.requestNewAllocatedSlot(slotRequestId, ResourceProfile.UNKNOWN, Time.minutes(5)), mainThreadExecutor).get();
        mainThreadExecutor.execute(() -> declarativeSlotPoolBridge.notifyNotEnoughResourcesAvailable(Collections.emptyList()));
        assertThat(slotAllocationFuture, FlinkMatchers.futureWillCompleteExceptionally(NoResourceAvailableException.class, Duration.ofSeconds(10)));
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) NoResourceAvailableException(org.apache.flink.runtime.jobmanager.scheduler.NoResourceAvailableException) Test(org.junit.Test)

Example 37 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.

the class DeclarativeSlotPoolBridgeTest method testAcceptingOfferedSlotsWithoutResourceManagerConnected.

@Test
public void testAcceptingOfferedSlotsWithoutResourceManagerConnected() throws Exception {
    try (DeclarativeSlotPoolBridge declarativeSlotPoolBridge = createDeclarativeSlotPoolBridge(new DefaultDeclarativeSlotPoolFactory(), requestSlotMatchingStrategy)) {
        declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
        final CompletableFuture<PhysicalSlot> slotFuture = declarativeSlotPoolBridge.requestNewAllocatedSlot(new SlotRequestId(), ResourceProfile.UNKNOWN, rpcTimeout);
        final LocalTaskManagerLocation localTaskManagerLocation = new LocalTaskManagerLocation();
        declarativeSlotPoolBridge.registerTaskManager(localTaskManagerLocation.getResourceID());
        final AllocationID allocationId = new AllocationID();
        declarativeSlotPoolBridge.offerSlots(localTaskManagerLocation, new SimpleAckingTaskManagerGateway(), Collections.singleton(new SlotOffer(allocationId, 0, ResourceProfile.ANY)));
        assertThat(slotFuture.join().getAllocationId(), is(allocationId));
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) SimpleAckingTaskManagerGateway(org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway) 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)

Example 38 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.

the class DeclarativeSlotPoolBridgeTest method testReleasingAllocatedSlot.

@Test
public void testReleasingAllocatedSlot() throws Exception {
    final CompletableFuture<AllocationID> releaseSlotFuture = new CompletableFuture<>();
    final AllocationID expectedAllocationId = new AllocationID();
    final PhysicalSlot allocatedSlot = createAllocatedSlot(expectedAllocationId);
    final TestingDeclarativeSlotPoolBuilder builder = TestingDeclarativeSlotPool.builder().setReserveFreeSlotFunction((allocationId, resourceProfile) -> {
        assertThat(allocationId, is(expectedAllocationId));
        return allocatedSlot;
    }).setFreeReservedSlotFunction((allocationID, throwable, aLong) -> {
        releaseSlotFuture.complete(allocationID);
        return ResourceCounter.empty();
    });
    final TestingDeclarativeSlotPoolFactory declarativeSlotPoolFactory = new TestingDeclarativeSlotPoolFactory(builder);
    try (DeclarativeSlotPoolBridge declarativeSlotPoolBridge = createDeclarativeSlotPoolBridge(declarativeSlotPoolFactory, requestSlotMatchingStrategy)) {
        declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
        final SlotRequestId slotRequestId = new SlotRequestId();
        declarativeSlotPoolBridge.allocateAvailableSlot(slotRequestId, expectedAllocationId, allocatedSlot.getResourceProfile());
        declarativeSlotPoolBridge.releaseSlot(slotRequestId, null);
        assertThat(releaseSlotFuture.join(), is(expectedAllocationId));
    }
}
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) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) CompletableFuture(java.util.concurrent.CompletableFuture) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Test(org.junit.Test)

Example 39 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.

the class DeclarativeSlotPoolBridgeResourceDeclarationTest method testRequirementsIncreasedOnNewAllocation.

@Test
public void testRequirementsIncreasedOnNewAllocation() throws Exception {
    declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
    // requesting the allocation of a new slot should increase the requirements
    declarativeSlotPoolBridge.requestNewAllocatedSlot(new SlotRequestId(), ResourceProfile.UNKNOWN, Time.minutes(5));
    assertThat(requirementListener.getRequirements().getResourceCount(ResourceProfile.UNKNOWN), is(1));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) Test(org.junit.Test)

Example 40 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.

the class PhysicalSlotRequestBulkCheckerImplTest method testBulkTimeoutOnCheck.

@Test
public void testBulkTimeoutOnCheck() {
    final PhysicalSlotRequestBulkWithTimestamp bulk = createPhysicalSlotRequestBulkWithTimestamp(new SlotRequestId());
    clock.advanceTime(TIMEOUT.toMilliseconds() + 1L, TimeUnit.MILLISECONDS);
    assertThat(checkBulkTimeout(bulk), is(PhysicalSlotRequestBulkCheckerImpl.TimeoutCheckResult.TIMEOUT));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) Test(org.junit.Test)

Aggregations

SlotRequestId (org.apache.flink.runtime.jobmaster.SlotRequestId)51 Test (org.junit.Test)40 TestingPhysicalSlot (org.apache.flink.runtime.scheduler.TestingPhysicalSlot)15 LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)11 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)8 TestLogger (org.apache.flink.util.TestLogger)6 Collectors (java.util.stream.Collectors)5 CoreMatchers.is (org.hamcrest.CoreMatchers.is)5 Assert.fail (org.junit.Assert.fail)5 Collection (java.util.Collection)4 Collections (java.util.Collections)4 List (java.util.List)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Consumer (java.util.function.Consumer)4 Time (org.apache.flink.api.common.time.Time)4 Arrays (java.util.Arrays)3 ExecutionException (java.util.concurrent.ExecutionException)3 SlotProfile (org.apache.flink.runtime.clusterframework.types.SlotProfile)3