Search in sources :

Example 16 with JobMasterId

use of org.apache.flink.runtime.jobmaster.JobMasterId 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)

Aggregations

JobMasterId (org.apache.flink.runtime.jobmaster.JobMasterId)16 Test (org.junit.Test)13 JobID (org.apache.flink.api.common.JobID)12 Time (org.apache.flink.api.common.time.Time)10 IOException (java.io.IOException)7 Collection (java.util.Collection)7 Collections (java.util.Collections)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 TestLogger (org.apache.flink.util.TestLogger)7 List (java.util.List)6 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)6 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)6 CoreMatchers.is (org.hamcrest.CoreMatchers.is)6 ExecutionException (java.util.concurrent.ExecutionException)5 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)5 Duration (java.time.Duration)4 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)4 Configuration (org.apache.flink.configuration.Configuration)4 TaskDeploymentDescriptor (org.apache.flink.runtime.deployment.TaskDeploymentDescriptor)4 Environment (org.apache.flink.runtime.execution.Environment)4