Search in sources :

Example 6 with SlotRequestId

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

the class SharedSlotTest method testAllocateLogicalSlotIssuesUniqueSlotRequestIds.

@Test
public void testAllocateLogicalSlotIssuesUniqueSlotRequestIds() {
    final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
    final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
    });
    final LogicalSlot logicalSlot1 = sharedSlot.allocateLogicalSlot();
    final LogicalSlot logicalSlot2 = sharedSlot.allocateLogicalSlot();
    assertThat(logicalSlot1.getSlotRequestId(), not(equalTo(logicalSlot2.getSlotRequestId())));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 7 with SlotRequestId

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

the class SharedSlotTest method testReturnLogicalSlotRejectsAliveSlots.

@Test(expected = IllegalStateException.class)
public void testReturnLogicalSlotRejectsAliveSlots() {
    final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
    final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
    });
    final LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot();
    sharedSlot.returnLogicalSlot(logicalSlot);
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 8 with SlotRequestId

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

the class SharedSlotTest method testCanReturnLogicalSlotDuringRelease.

@Test
public void testCanReturnLogicalSlotDuringRelease() {
    final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
    final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
    });
    final LogicalSlot logicalSlot1 = sharedSlot.allocateLogicalSlot();
    final LogicalSlot logicalSlot2 = sharedSlot.allocateLogicalSlot();
    // both slots try to release the other one, simulating that the failure of one execution due
    // to the release also fails others
    logicalSlot1.tryAssignPayload(new TestLogicalSlotPayload(cause -> {
        if (logicalSlot2.isAlive()) {
            logicalSlot2.releaseSlot(cause);
        }
    }));
    logicalSlot2.tryAssignPayload(new TestLogicalSlotPayload(cause -> {
        if (logicalSlot1.isAlive()) {
            logicalSlot1.releaseSlot(cause);
        }
    }));
    sharedSlot.release(new Exception("test"));
    // if all logical slots were released, and the sharedSlot no longer allows the allocation of
    // logical slots, then the slot release was completed
    assertThat(logicalSlot1.isAlive(), is(false));
    assertThat(logicalSlot2.isAlive(), is(false));
    try {
        sharedSlot.allocateLogicalSlot();
        fail("Allocation of logical slot should have failed because the slot was released.");
    } catch (IllegalStateException expected) {
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestingPhysicalSlotPayload(org.apache.flink.runtime.jobmaster.slotpool.TestingPhysicalSlotPayload) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) Locality(org.apache.flink.runtime.jobmanager.scheduler.Locality) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) Consumer(java.util.function.Consumer) Assert.assertThat(org.junit.Assert.assertThat) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 9 with SlotRequestId

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

the class DeclarativeSlotPoolBridgeResourceDeclarationTest method testRequirementsIncreasedOnSlotReservation.

@Test
public void testRequirementsIncreasedOnSlotReservation() throws Exception {
    declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
    final PhysicalSlot newSlot = createAllocatedSlot(new AllocationID());
    declarativeSlotPoolBridge.newSlotsAreAvailable(Collections.singleton(newSlot));
    // allocating (==reserving) an available (==free) slot should increase the requirements
    final SlotRequestId slotRequestId = new SlotRequestId();
    declarativeSlotPoolBridge.allocateAvailableSlot(slotRequestId, newSlot.getAllocationId(), ResourceProfile.UNKNOWN);
    assertThat(requirementListener.getRequirements().getResourceCount(ResourceProfile.UNKNOWN), is(1));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Test(org.junit.Test)

Example 10 with SlotRequestId

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

the class DeclarativeSlotPoolBridgeResourceDeclarationTest method testRequirementsDecreasedOnAllocationTimeout.

@Test
public void testRequirementsDecreasedOnAllocationTimeout() throws Exception {
    final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    try {
        ComponentMainThreadExecutor mainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forSingleThreadExecutor(scheduledExecutorService);
        declarativeSlotPoolBridge.start(jobMasterId, "localhost", mainThreadExecutor);
        // requesting the allocation of a new slot increases the requirements
        final CompletableFuture<PhysicalSlot> allocationFuture = CompletableFuture.supplyAsync(() -> declarativeSlotPoolBridge.requestNewAllocatedSlot(new SlotRequestId(), ResourceProfile.UNKNOWN, Time.milliseconds(5)), mainThreadExecutor).get();
        // waiting for the timeout
        assertThat(allocationFuture, FlinkMatchers.futureWillCompleteExceptionally(Duration.ofMinutes(1)));
        // when the allocation fails the requirements should be reduced (it is the users
        // responsibility to retry)
        CompletableFuture.runAsync(() -> assertThat(requirementListener.getRequirements().getResourceCount(ResourceProfile.UNKNOWN), is(0)), mainThreadExecutor).join();
    } finally {
        scheduledExecutorService.shutdown();
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ComponentMainThreadExecutor(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor) 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