Search in sources :

Example 21 with SlotRequestId

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

the class SimpleRequestSlotMatchingStrategyTest method testSlotRequestsAreMatchedInOrder.

@Test
public void testSlotRequestsAreMatchedInOrder() {
    final SimpleRequestSlotMatchingStrategy simpleRequestSlotMatchingStrategy = SimpleRequestSlotMatchingStrategy.INSTANCE;
    final Collection<PhysicalSlot> slots = Arrays.asList(TestingPhysicalSlot.builder().build());
    final PendingRequest pendingRequest1 = PendingRequest.createNormalRequest(new SlotRequestId(), ResourceProfile.UNKNOWN, Collections.emptyList());
    final PendingRequest pendingRequest2 = PendingRequest.createNormalRequest(new SlotRequestId(), ResourceProfile.UNKNOWN, Collections.emptyList());
    final Collection<PendingRequest> pendingRequests = Arrays.asList(pendingRequest1, pendingRequest2);
    final Collection<RequestSlotMatchingStrategy.RequestSlotMatch> requestSlotMatches = simpleRequestSlotMatchingStrategy.matchRequestsAndSlots(slots, pendingRequests);
    assertThat(requestSlotMatches).hasSize(1);
    assertThat(Iterators.getOnlyElement(requestSlotMatches.iterator()).getPendingRequest().getSlotRequestId()).isEqualTo(pendingRequest1.getSlotRequestId());
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) Test(org.junit.jupiter.api.Test)

Example 22 with SlotRequestId

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

the class DeclarativeSlotPoolBridgeTest method testSlotOffer.

@Test
public void testSlotOffer() throws Exception {
    final SlotRequestId slotRequestId = new SlotRequestId();
    final AllocationID expectedAllocationId = new AllocationID();
    final PhysicalSlot allocatedSlot = createAllocatedSlot(expectedAllocationId);
    final TestingDeclarativeSlotPoolFactory declarativeSlotPoolFactory = new TestingDeclarativeSlotPoolFactory(TestingDeclarativeSlotPool.builder());
    try (DeclarativeSlotPoolBridge declarativeSlotPoolBridge = createDeclarativeSlotPoolBridge(declarativeSlotPoolFactory, requestSlotMatchingStrategy)) {
        declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
        CompletableFuture<PhysicalSlot> slotAllocationFuture = declarativeSlotPoolBridge.requestNewAllocatedSlot(slotRequestId, ResourceProfile.UNKNOWN, null);
        declarativeSlotPoolBridge.newSlotsAreAvailable(Collections.singleton(allocatedSlot));
        slotAllocationFuture.join();
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Test(org.junit.Test)

Example 23 with SlotRequestId

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

the class DeclarativeSlotPoolBridgeTest method testNoConcurrentModificationWhenSuspendingAndReleasingSlot.

@Test
public void testNoConcurrentModificationWhenSuspendingAndReleasingSlot() throws Exception {
    try (DeclarativeSlotPoolBridge declarativeSlotPoolBridge = createDeclarativeSlotPoolBridge(new DefaultDeclarativeSlotPoolFactory(), requestSlotMatchingStrategy)) {
        declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
        final List<SlotRequestId> slotRequestIds = Arrays.asList(new SlotRequestId(), new SlotRequestId());
        final List<CompletableFuture<PhysicalSlot>> slotFutures = slotRequestIds.stream().map(slotRequestId -> {
            final CompletableFuture<PhysicalSlot> slotFuture = declarativeSlotPoolBridge.requestNewAllocatedSlot(slotRequestId, ResourceProfile.UNKNOWN, rpcTimeout);
            slotFuture.whenComplete((physicalSlot, throwable) -> {
                if (throwable != null) {
                    declarativeSlotPoolBridge.releaseSlot(slotRequestId, throwable);
                }
            });
            return slotFuture;
        }).collect(Collectors.toList());
        declarativeSlotPoolBridge.close();
        try {
            FutureUtils.waitForAll(slotFutures).get();
            fail("The slot futures should be completed exceptionally.");
        } catch (ExecutionException expected) {
        // expected
        }
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) 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) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 24 with SlotRequestId

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

the class PreferredAllocationRequestSlotMatchingStrategyTest method testNewSlotsAreMatchedAgainstPreferredAllocationIDs.

/**
 * This test ensures that new slots are matched against the preferred allocationIds of the
 * pending requests.
 */
@Test
public void testNewSlotsAreMatchedAgainstPreferredAllocationIDs() throws Exception {
    final PreferredAllocationRequestSlotMatchingStrategy strategy = PreferredAllocationRequestSlotMatchingStrategy.INSTANCE;
    final AllocationID allocationId1 = new AllocationID();
    final AllocationID allocationId2 = new AllocationID();
    final Collection<TestingPhysicalSlot> slots = Arrays.asList(TestingPhysicalSlot.builder().withAllocationID(allocationId1).build(), TestingPhysicalSlot.builder().withAllocationID(allocationId2).build());
    final Collection<PendingRequest> pendingRequests = Arrays.asList(PendingRequest.createNormalRequest(new SlotRequestId(), ResourceProfile.UNKNOWN, Collections.singleton(allocationId2)), PendingRequest.createNormalRequest(new SlotRequestId(), ResourceProfile.UNKNOWN, Collections.singleton(allocationId1)));
    final Collection<RequestSlotMatchingStrategy.RequestSlotMatch> requestSlotMatches = strategy.matchRequestsAndSlots(slots, pendingRequests);
    assertThat(requestSlotMatches).hasSize(2);
    for (RequestSlotMatchingStrategy.RequestSlotMatch requestSlotMatch : requestSlotMatches) {
        assertThat(requestSlotMatch.getPendingRequest().getPreferredAllocations()).contains(requestSlotMatch.getSlot().getAllocationId());
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Test(org.junit.jupiter.api.Test)

Example 25 with SlotRequestId

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

the class SlotSharingExecutionSlotAllocatorTest method failLogicalSlotsIfPhysicalSlotIsFailed.

@Test
public void failLogicalSlotsIfPhysicalSlotIsFailed() {
    final TestingPhysicalSlotRequestBulkChecker bulkChecker = new TestingPhysicalSlotRequestBulkChecker();
    AllocationContext context = AllocationContext.newBuilder().addGroup(EV1, EV2).withBulkChecker(bulkChecker).withPhysicalSlotProvider(TestingPhysicalSlotProvider.createWithFailingPhysicalSlotCreation(new FlinkException("test failure"))).build();
    final List<SlotExecutionVertexAssignment> allocatedSlots = context.allocateSlotsFor(EV1, EV2);
    for (SlotExecutionVertexAssignment allocatedSlot : allocatedSlots) {
        assertTrue(allocatedSlot.getLogicalSlotFuture().isCompletedExceptionally());
    }
    assertThat(bulkChecker.getBulk().getPendingRequests(), is(empty()));
    final Set<SlotRequestId> requests = context.getSlotProvider().getRequests().keySet();
    assertThat(context.getSlotProvider().getCancellations().keySet(), is(requests));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) FlinkException(org.apache.flink.util.FlinkException) 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