Search in sources :

Example 1 with TestingPayload

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

the class SlotSharingExecutionSlotAllocatorTest method testPhysicalSlotReleaseLogicalSlots.

@Test
public void testPhysicalSlotReleaseLogicalSlots() throws ExecutionException, InterruptedException {
    AllocationContext context = AllocationContext.newBuilder().addGroup(EV1, EV2).build();
    List<SlotExecutionVertexAssignment> assignments = context.allocateSlotsFor(EV1, EV2);
    List<TestingPayload> payloads = assignments.stream().map(assignment -> {
        TestingPayload payload = new TestingPayload();
        assignment.getLogicalSlotFuture().thenAccept(logicalSlot -> logicalSlot.tryAssignPayload(payload));
        return payload;
    }).collect(Collectors.toList());
    SlotRequestId slotRequestId = context.getSlotProvider().getFirstRequestOrFail().getSlotRequestId();
    TestingPhysicalSlot physicalSlot = context.getSlotProvider().getFirstResponseOrFail().get();
    assertThat(payloads.stream().allMatch(payload -> payload.getTerminalStateFuture().isDone()), is(false));
    assertThat(physicalSlot.getPayload(), notNullValue());
    physicalSlot.getPayload().release(new Throwable());
    assertThat(payloads.stream().allMatch(payload -> payload.getTerminalStateFuture().isDone()), is(true));
    assertThat(context.getSlotProvider().getCancellations().containsKey(slotRequestId), is(true));
    context.allocateSlotsFor(EV1, EV2);
    // there should be one more physical slot allocation, as the first allocation should be
    // removed after releasing all logical slots
    assertThat(context.getSlotProvider().getRequests().keySet(), hasSize(2));
}
Also used : DummyPayload(org.apache.flink.runtime.jobmaster.slotpool.DummyPayload) CoreMatchers.is(org.hamcrest.CoreMatchers.is) FlinkException(org.apache.flink.util.FlinkException) BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) Arrays(java.util.Arrays) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest) PhysicalSlotRequestBulk(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequestBulk) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) SharedSlotProfileRetrieverFactory(org.apache.flink.runtime.scheduler.SharedSlotProfileRetriever.SharedSlotProfileRetrieverFactory) Map(java.util.Map) PhysicalSlotRequestBulkChecker(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequestBulkChecker) TestLogger(org.apache.flink.util.TestLogger) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.fail(org.junit.Assert.fail) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) ExecutionGraphTestUtils.createRandomExecutionVertexId(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createRandomExecutionVertexId) Matchers.empty(org.hamcrest.Matchers.empty) CancellationException(java.util.concurrent.CancellationException) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Collection(java.util.Collection) TestingPayload(org.apache.flink.runtime.jobmaster.TestingPayload) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) SlotProfileTestingUtils(org.apache.flink.runtime.clusterframework.types.SlotProfileTestingUtils) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Optional(java.util.Optional) 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) TestingPayload(org.apache.flink.runtime.jobmaster.TestingPayload) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CancellationException (java.util.concurrent.CancellationException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 Time (org.apache.flink.api.common.time.Time)1 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)1 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)1 SlotProfile (org.apache.flink.runtime.clusterframework.types.SlotProfile)1 SlotProfileTestingUtils (org.apache.flink.runtime.clusterframework.types.SlotProfileTestingUtils)1 ExecutionGraphTestUtils.createRandomExecutionVertexId (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createRandomExecutionVertexId)1