Search in sources :

Example 81 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class TaskAsyncCallTest method createTask.

private Task createTask(Class<? extends AbstractInvokable> invokableClass) throws Exception {
    final TestingClassLoaderLease classLoaderHandle = TestingClassLoaderLease.newBuilder().setGetOrResolveClassLoaderFunction((permanentBlobKeys, urls) -> TestingUserCodeClassLoader.newBuilder().setClassLoader(new TestUserCodeClassLoader()).build()).build();
    ResultPartitionConsumableNotifier consumableNotifier = new NoOpResultPartitionConsumableNotifier();
    PartitionProducerStateChecker partitionProducerStateChecker = mock(PartitionProducerStateChecker.class);
    Executor executor = mock(Executor.class);
    TaskMetricGroup taskMetricGroup = UnregisteredMetricGroups.createUnregisteredTaskMetricGroup();
    JobInformation jobInformation = new JobInformation(new JobID(), "Job Name", new SerializedValue<>(new ExecutionConfig()), new Configuration(), Collections.emptyList(), Collections.emptyList());
    TaskInformation taskInformation = new TaskInformation(new JobVertexID(), "Test Task", 1, 1, invokableClass.getName(), new Configuration());
    return new Task(jobInformation, taskInformation, new ExecutionAttemptID(), new AllocationID(), 0, 0, Collections.<ResultPartitionDeploymentDescriptor>emptyList(), Collections.<InputGateDeploymentDescriptor>emptyList(), mock(MemoryManager.class), mock(IOManager.class), shuffleEnvironment, new KvStateService(new KvStateRegistry(), null, null), mock(BroadcastVariableManager.class), new TaskEventDispatcher(), ExternalResourceInfoProvider.NO_EXTERNAL_RESOURCES, new TestTaskStateManager(), mock(TaskManagerActions.class), mock(InputSplitProvider.class), mock(CheckpointResponder.class), new NoOpTaskOperatorEventGateway(), new TestGlobalAggregateManager(), classLoaderHandle, mock(FileCache.class), new TestingTaskManagerRuntimeInfo(), taskMetricGroup, consumableNotifier, partitionProducerStateChecker, executor);
}
Also used : CheckpointMetricsBuilder(org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder) ShuffleEnvironment(org.apache.flink.runtime.shuffle.ShuffleEnvironment) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) InputSplitProvider(org.apache.flink.runtime.jobgraph.tasks.InputSplitProvider) Assert.assertThat(org.junit.Assert.assertThat) TestTaskStateManager(org.apache.flink.runtime.state.TestTaskStateManager) Future(java.util.concurrent.Future) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) JobInformation(org.apache.flink.runtime.executiongraph.JobInformation) KvStateService(org.apache.flink.runtime.taskexecutor.KvStateService) After(org.junit.After) TestGlobalAggregateManager(org.apache.flink.runtime.taskexecutor.TestGlobalAggregateManager) TestLogger(org.apache.flink.util.TestLogger) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) ResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.ResultPartitionConsumableNotifier) Matchers.isOneOf(org.hamcrest.Matchers.isOneOf) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) BroadcastVariableManager(org.apache.flink.runtime.broadcast.BroadcastVariableManager) SerializedValue(org.apache.flink.util.SerializedValue) ResultPartitionDeploymentDescriptor(org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor) Assert.assertFalse(org.junit.Assert.assertFalse) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) InputGateDeploymentDescriptor(org.apache.flink.runtime.deployment.InputGateDeploymentDescriptor) Environment(org.apache.flink.runtime.execution.Environment) Mockito.mock(org.mockito.Mockito.mock) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) CompletableFuture(java.util.concurrent.CompletableFuture) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) TestingClassLoaderLease(org.apache.flink.runtime.execution.librarycache.TestingClassLoaderLease) ExternalResourceInfoProvider(org.apache.flink.runtime.externalresource.ExternalResourceInfoProvider) Before(org.junit.Before) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) Executor(java.util.concurrent.Executor) Configuration(org.apache.flink.configuration.Configuration) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) FileCache(org.apache.flink.runtime.filecache.FileCache) Test(org.junit.Test) PartitionProducerStateChecker(org.apache.flink.runtime.taskexecutor.PartitionProducerStateChecker) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) JobID(org.apache.flink.api.common.JobID) NoOpResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.NoOpResultPartitionConsumableNotifier) UnregisteredMetricGroups(org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups) TestingUserCodeClassLoader(org.apache.flink.runtime.util.TestingUserCodeClassLoader) TaskInformation(org.apache.flink.runtime.executiongraph.TaskInformation) Collections(java.util.Collections) KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) Configuration(org.apache.flink.configuration.Configuration) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KvStateService(org.apache.flink.runtime.taskexecutor.KvStateService) Executor(java.util.concurrent.Executor) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) BroadcastVariableManager(org.apache.flink.runtime.broadcast.BroadcastVariableManager) PartitionProducerStateChecker(org.apache.flink.runtime.taskexecutor.PartitionProducerStateChecker) ResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.ResultPartitionConsumableNotifier) NoOpResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.NoOpResultPartitionConsumableNotifier) InputSplitProvider(org.apache.flink.runtime.jobgraph.tasks.InputSplitProvider) JobInformation(org.apache.flink.runtime.executiongraph.JobInformation) TaskInformation(org.apache.flink.runtime.executiongraph.TaskInformation) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) NoOpResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.NoOpResultPartitionConsumableNotifier) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) TestGlobalAggregateManager(org.apache.flink.runtime.taskexecutor.TestGlobalAggregateManager) FileCache(org.apache.flink.runtime.filecache.FileCache) TestTaskStateManager(org.apache.flink.runtime.state.TestTaskStateManager) TestingClassLoaderLease(org.apache.flink.runtime.execution.librarycache.TestingClassLoaderLease) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) JobID(org.apache.flink.api.common.JobID)

Example 82 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class TaskSlotTableImplTest method testInconsistentStaticSlotAllocation.

/**
 * Tests that inconsistent static slot allocation with the same AllocationID to a different slot
 * is rejected.
 */
@Test
public void testInconsistentStaticSlotAllocation() throws Exception {
    try (final TaskSlotTable<TaskSlotPayload> taskSlotTable = createTaskSlotTableAndStart(2)) {
        final JobID jobId = new JobID();
        final AllocationID allocationId1 = new AllocationID();
        final AllocationID allocationId2 = new AllocationID();
        assertThat(taskSlotTable.allocateSlot(0, jobId, allocationId1, SLOT_TIMEOUT), is(true));
        assertThat(taskSlotTable.allocateSlot(1, jobId, allocationId1, SLOT_TIMEOUT), is(false));
        assertThat(taskSlotTable.allocateSlot(0, jobId, allocationId2, SLOT_TIMEOUT), is(false));
        assertThat(taskSlotTable.isAllocated(0, jobId, allocationId1), is(true));
        assertThat(taskSlotTable.isSlotFree(1), is(true));
        Iterator<TaskSlot<TaskSlotPayload>> allocatedSlots = taskSlotTable.getAllocatedSlots(jobId);
        assertThat(allocatedSlots.next().getIndex(), is(0));
        assertThat(allocatedSlots.hasNext(), is(false));
    }
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 83 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class TaskSlotTableImplTest method testRemoveTaskCallsFreeSlotAction.

@Test(timeout = 10000)
public void testRemoveTaskCallsFreeSlotAction() throws Exception {
    final JobID jobId = new JobID();
    final ExecutionAttemptID executionAttemptId = new ExecutionAttemptID();
    final AllocationID allocationId = new AllocationID();
    CompletableFuture<AllocationID> freeSlotFuture = new CompletableFuture<>();
    SlotActions slotActions = new TestingSlotActions(freeSlotFuture::complete, (aid, uid) -> {
    });
    TaskSlotPayload task = new TestingTaskSlotPayload(jobId, executionAttemptId, allocationId).terminate();
    try (final TaskSlotTable<TaskSlotPayload> taskSlotTable = createTaskSlotTableWithStartedTask(task, slotActions)) {
        // we have to initiate closing of the slot externally
        // to enable that the last remaining finished task does the final slot freeing
        taskSlotTable.freeSlot(allocationId);
        taskSlotTable.removeTask(executionAttemptId);
        assertThat(freeSlotFuture.get(), is(allocationId));
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 84 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class TaskSlotTableImplTest method runDeactivateSlotTimeoutTest.

private void runDeactivateSlotTimeoutTest(TriFunctionWithException<TaskSlotTable<TaskSlotPayload>, JobID, AllocationID, Boolean, SlotNotFoundException> taskSlotTableAction) throws Exception {
    final CompletableFuture<AllocationID> timeoutCancellationFuture = new CompletableFuture<>();
    final TimerService<AllocationID> testingTimerService = new TestingTimerServiceBuilder<AllocationID>().setUnregisterTimeoutConsumer(timeoutCancellationFuture::complete).createTestingTimerService();
    try (final TaskSlotTableImpl<TaskSlotPayload> taskSlotTable = createTaskSlotTableAndStart(1, testingTimerService)) {
        final AllocationID allocationId = new AllocationID();
        final long timeout = 50L;
        final JobID jobId = new JobID();
        assertThat(taskSlotTable.allocateSlot(0, jobId, allocationId, Time.milliseconds(timeout)), is(true));
        assertThat(taskSlotTableAction.apply(taskSlotTable, jobId, allocationId), is(true));
        timeoutCancellationFuture.get();
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) JobID(org.apache.flink.api.common.JobID)

Example 85 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class TaskSlotTableImplTest method testDuplicateStaticSlotAllocation.

@Test
public void testDuplicateStaticSlotAllocation() throws Exception {
    try (final TaskSlotTable<TaskSlotPayload> taskSlotTable = createTaskSlotTableAndStart(2)) {
        final JobID jobId = new JobID();
        final AllocationID allocationId = new AllocationID();
        assertThat(taskSlotTable.allocateSlot(0, jobId, allocationId, ResourceProfile.UNKNOWN, SLOT_TIMEOUT), is(true));
        assertThat(taskSlotTable.allocateSlot(0, jobId, allocationId, ResourceProfile.UNKNOWN, SLOT_TIMEOUT), is(true));
        assertThat(taskSlotTable.isAllocated(0, jobId, allocationId), is(true));
        assertThat(taskSlotTable.isSlotFree(1), is(true));
        Iterator<TaskSlot<TaskSlotPayload>> allocatedSlots = taskSlotTable.getAllocatedSlots(jobId);
        assertThat(allocatedSlots.next().getIndex(), is(0));
        assertThat(allocatedSlots.hasNext(), is(false));
    }
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)194 Test (org.junit.Test)137 JobID (org.apache.flink.api.common.JobID)106 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)60 CompletableFuture (java.util.concurrent.CompletableFuture)56 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)56 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)53 ArrayList (java.util.ArrayList)39 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)36 Collection (java.util.Collection)35 Time (org.apache.flink.api.common.time.Time)35 Configuration (org.apache.flink.configuration.Configuration)34 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)34 SlotOffer (org.apache.flink.runtime.taskexecutor.slot.SlotOffer)34 List (java.util.List)32 TestLogger (org.apache.flink.util.TestLogger)32 FlinkException (org.apache.flink.util.FlinkException)31 Matchers.is (org.hamcrest.Matchers.is)31 Assert.assertThat (org.junit.Assert.assertThat)31 Arrays (java.util.Arrays)30