org.apache.flink.runtime.taskmanager.Task Java Examples
The following examples show how to use
org.apache.flink.runtime.taskmanager.Task.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamTaskTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testCancellationNotBlockedOnLock() throws Exception { syncLatch = new OneShotLatch(); StreamConfig cfg = new StreamConfig(new Configuration()); Task task = createTask(CancelLockingTask.class, cfg, new Configuration()); // start the task and wait until it runs // execution state RUNNING is not enough, we need to wait until the stream task's run() method // is entered task.startTaskThread(); syncLatch.await(); // cancel the execution - this should lead to smooth shutdown task.cancelExecution(); task.getExecutingThread().join(); assertEquals(ExecutionState.CANCELED, task.getExecutionState()); }
Example #2
Source File: TaskExecutor.java From flink with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Acknowledge> cancelTask(ExecutionAttemptID executionAttemptID, Time timeout) { final Task task = taskSlotTable.getTask(executionAttemptID); if (task != null) { try { task.cancelExecution(); return CompletableFuture.completedFuture(Acknowledge.get()); } catch (Throwable t) { return FutureUtils.completedExceptionally( new TaskException("Cannot cancel task for execution " + executionAttemptID + '.', t)); } } else { final String message = "Cannot find task to stop for execution " + executionAttemptID + '.'; log.debug(message); return FutureUtils.completedExceptionally(new TaskException(message)); } }
Example #3
Source File: TaskExecutor.java From flink with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<StackTraceSampleResponse> requestStackTraceSample( final ExecutionAttemptID executionAttemptId, final int sampleId, final int numSamples, final Time delayBetweenSamples, final int maxStackTraceDepth, final Time timeout) { final Task task = taskSlotTable.getTask(executionAttemptId); if (task == null) { return FutureUtils.completedExceptionally( new IllegalStateException(String.format("Cannot sample task %s. " + "Task is not known to the task manager.", executionAttemptId))); } final CompletableFuture<List<StackTraceElement[]>> stackTracesFuture = stackTraceSampleService.requestStackTraceSample( TaskStackTraceSampleableTaskAdapter.fromTask(task), numSamples, delayBetweenSamples, maxStackTraceDepth); return stackTracesFuture.thenApply(stackTraces -> new StackTraceSampleResponse(sampleId, executionAttemptId, stackTraces)); }
Example #4
Source File: NetworkEnvironment.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public void registerTask(Task task) throws IOException { final ResultPartition[] producedPartitions = task.getProducedPartitions(); synchronized (lock) { if (isShutdown) { throw new IllegalStateException("NetworkEnvironment is shut down"); } for (final ResultPartition partition : producedPartitions) { setupPartition(partition); } // Setup the buffer pool for each buffer reader final SingleInputGate[] inputGates = task.getAllInputGates(); for (SingleInputGate gate : inputGates) { setupInputGate(gate); } } }
Example #5
Source File: TaskCheckpointingBehaviourTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testBlockingNonInterruptibleCheckpoint() throws Exception { StateBackend lockingStateBackend = new BackendForTestStream(LockingOutputStream::new); Task task = createTask(new TestOperator(), lockingStateBackend, mock(CheckpointResponder.class), true); // start the task and wait until it is in "restore" task.startTaskThread(); IN_CHECKPOINT_LATCH.await(); // cancel the task and wait. unless cancellation properly closes // the streams, this will never terminate task.cancelExecution(); task.getExecutingThread().join(); assertEquals(ExecutionState.CANCELED, task.getExecutionState()); assertNull(task.getFailureCause()); }
Example #6
Source File: TaskExecutor.java From flink with Apache License 2.0 | 6 votes |
@Override public AccumulatorReport retrievePayload(ResourceID resourceID) { validateRunsInMainThread(); JobManagerConnection jobManagerConnection = jobManagerConnections.get(resourceID); if (jobManagerConnection != null) { JobID jobId = jobManagerConnection.getJobID(); List<AccumulatorSnapshot> accumulatorSnapshots = new ArrayList<>(16); Iterator<Task> allTasks = taskSlotTable.getTasks(jobId); while (allTasks.hasNext()) { Task task = allTasks.next(); accumulatorSnapshots.add(task.getAccumulatorRegistry().getSnapshot()); } return new AccumulatorReport(accumulatorSnapshots); } else { return new AccumulatorReport(Collections.emptyList()); } }
Example #7
Source File: TaskExecutor.java From flink with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Acknowledge> abortCheckpoint( ExecutionAttemptID executionAttemptID, long checkpointId, long checkpointTimestamp) { log.debug("Abort checkpoint {}@{} for {}.", checkpointId, checkpointTimestamp, executionAttemptID); final Task task = taskSlotTable.getTask(executionAttemptID); if (task != null) { task.notifyCheckpointAborted(checkpointId); return CompletableFuture.completedFuture(Acknowledge.get()); } else { final String message = "TaskManager received an aborted checkpoint for unknown task " + executionAttemptID + '.'; log.debug(message); return FutureUtils.completedExceptionally(new CheckpointException(message, CheckpointFailureReason.UNKNOWN_TASK_CHECKPOINT_NOTIFICATION_FAILURE)); } }
Example #8
Source File: TaskCheckpointingBehaviourTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testBlockingNonInterruptibleCheckpoint() throws Exception { StateBackend lockingStateBackend = new BackendForTestStream(LockingOutputStream::new); Task task = createTask(new TestOperator(), lockingStateBackend, mock(CheckpointResponder.class)); // start the task and wait until it is in "restore" task.startTaskThread(); IN_CHECKPOINT_LATCH.await(); // cancel the task and wait. unless cancellation properly closes // the streams, this will never terminate task.cancelExecution(); task.getExecutingThread().join(); assertEquals(ExecutionState.CANCELED, task.getExecutionState()); assertNull(task.getFailureCause()); }
Example #9
Source File: TaskExecutor.java From flink with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Acknowledge> confirmCheckpoint( ExecutionAttemptID executionAttemptID, long checkpointId, long checkpointTimestamp) { log.debug("Confirm checkpoint {}@{} for {}.", checkpointId, checkpointTimestamp, executionAttemptID); final Task task = taskSlotTable.getTask(executionAttemptID); if (task != null) { task.notifyCheckpointComplete(checkpointId); return CompletableFuture.completedFuture(Acknowledge.get()); } else { final String message = "TaskManager received a checkpoint confirmation for unknown task " + executionAttemptID + '.'; log.debug(message); return FutureUtils.completedExceptionally(new CheckpointException(message, CheckpointFailureReason.UNKNOWN_TASK_CHECKPOINT_NOTIFICATION_FAILURE)); } }
Example #10
Source File: TaskSlotTable.java From flink with Apache License 2.0 | 6 votes |
/** * Add the given task to the slot identified by the task's allocation id. * * @param task to add to the task slot with the respective allocation id * @throws SlotNotFoundException if there was no slot for the given allocation id * @throws SlotNotActiveException if there was no slot active for task's job and allocation id * @return True if the task could be added to the task slot; otherwise false */ public boolean addTask(Task task) throws SlotNotFoundException, SlotNotActiveException { Preconditions.checkNotNull(task); TaskSlot taskSlot = getTaskSlot(task.getAllocationId()); if (taskSlot != null) { if (taskSlot.isActive(task.getJobID(), task.getAllocationId())) { if (taskSlot.add(task)) { taskSlotMappings.put(task.getExecutionId(), new TaskSlotMapping(task, taskSlot)); return true; } else { return false; } } else { throw new SlotNotActiveException(task.getJobID(), task.getAllocationId()); } } else { throw new SlotNotFoundException(task.getAllocationId()); } }
Example #11
Source File: TaskSlot.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Add the given task to the task slot. This is only possible if there is not already another * task with the same execution attempt id added to the task slot. In this case, the method * returns true. Otherwise the task slot is left unchanged and false is returned. * * <p>In case that the task slot state is not active an {@link IllegalStateException} is thrown. * In case that the task's job id and allocation id don't match with the job id and allocation * id for which the task slot has been allocated, an {@link IllegalArgumentException} is thrown. * * @param task to be added to the task slot * @throws IllegalStateException if the task slot is not in state active * @return true if the task was added to the task slot; otherwise false */ public boolean add(Task task) { // Check that this slot has been assigned to the job sending this task Preconditions.checkArgument(task.getJobID().equals(jobId), "The task's job id does not match the " + "job id for which the slot has been allocated."); Preconditions.checkArgument(task.getAllocationId().equals(allocationId), "The task's allocation " + "id does not match the allocation id for which the slot has been allocated."); Preconditions.checkState(TaskSlotState.ACTIVE == state, "The task slot is not in state active."); Task oldTask = tasks.put(task.getExecutionId(), task); if (oldTask != null) { tasks.put(task.getExecutionId(), oldTask); return false; } else { return true; } }
Example #12
Source File: TaskCheckpointingBehaviourTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testBlockingNonInterruptibleCheckpoint() throws Exception { StateBackend lockingStateBackend = new BackendForTestStream(LockingOutputStream::new); Task task = createTask(new TestOperator(), lockingStateBackend, mock(CheckpointResponder.class)); // start the task and wait until it is in "restore" task.startTaskThread(); IN_CHECKPOINT_LATCH.await(); // cancel the task and wait. unless cancellation properly closes // the streams, this will never terminate task.cancelExecution(); task.getExecutingThread().join(); assertEquals(ExecutionState.CANCELED, task.getExecutionState()); assertNull(task.getFailureCause()); }
Example #13
Source File: TaskExecutorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTaskSlotTableTerminationOnShutdown() throws Exception { CompletableFuture<Void> taskSlotTableClosingFuture = new CompletableFuture<>(); TaskExecutorTestingContext submissionContext = createTaskExecutorTestingContext( TestingTaskSlotTable.<Task>newBuilder().closeAsyncReturns(taskSlotTableClosingFuture).build()); final CompletableFuture<Void> taskExecutorTerminationFuture; try { submissionContext.start(); } finally { taskExecutorTerminationFuture = submissionContext.taskExecutor.closeAsync(); } // check task executor is waiting for the task completion and has not terminated yet assertThat(taskExecutorTerminationFuture.isDone(), is(false)); // check task executor has exited after task slot table termination taskSlotTableClosingFuture.complete(null); taskExecutorTerminationFuture.get(); }
Example #14
Source File: TaskSlotTable.java From flink with Apache License 2.0 | 6 votes |
@Override public Task next() { while ((currentTasks == null || !currentTasks.hasNext())) { TaskSlot taskSlot; try { taskSlot = taskSlotIterator.next(); } catch (NoSuchElementException e) { throw new NoSuchElementException("No more tasks."); } currentTasks = taskSlot.getTasks(); } return currentTasks.next(); }
Example #15
Source File: TaskExecutor.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Acknowledge> confirmCheckpoint( ExecutionAttemptID executionAttemptID, long checkpointId, long checkpointTimestamp) { log.debug("Confirm checkpoint {}@{} for {}.", checkpointId, checkpointTimestamp, executionAttemptID); final Task task = taskSlotTable.getTask(executionAttemptID); if (task != null) { task.notifyCheckpointComplete(checkpointId); return CompletableFuture.completedFuture(Acknowledge.get()); } else { final String message = "TaskManager received a checkpoint confirmation for unknown task " + executionAttemptID + '.'; log.debug(message); return FutureUtils.completedExceptionally(new CheckpointException(message)); } }
Example #16
Source File: AbstractUdfStreamOperatorLifecycleTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testLifeCycleFull() throws Exception { ACTUAL_ORDER_TRACKING.clear(); Configuration taskManagerConfig = new Configuration(); StreamConfig cfg = new StreamConfig(new Configuration()); MockSourceFunction srcFun = new MockSourceFunction(); cfg.setStreamOperator(new LifecycleTrackingStreamSource<>(srcFun, true)); cfg.setOperatorID(new OperatorID()); cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime); Task task = StreamTaskTest.createTask(SourceStreamTask.class, cfg, taskManagerConfig); task.startTaskThread(); LifecycleTrackingStreamSource.runStarted.await(); // wait for clean termination task.getExecutingThread().join(); assertEquals(ExecutionState.FINISHED, task.getExecutionState()); assertEquals(EXPECTED_CALL_ORDER_FULL, ACTUAL_ORDER_TRACKING); }
Example #17
Source File: AbstractUdfStreamOperatorLifecycleTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testLifeCycleFull() throws Exception { ACTUAL_ORDER_TRACKING.clear(); Configuration taskManagerConfig = new Configuration(); StreamConfig cfg = new StreamConfig(new Configuration()); MockSourceFunction srcFun = new MockSourceFunction(); cfg.setStreamOperator(new LifecycleTrackingStreamSource<>(srcFun, true)); cfg.setOperatorID(new OperatorID()); cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime); Task task = StreamTaskTest.createTask(SourceStreamTask.class, cfg, taskManagerConfig); task.startTaskThread(); LifecycleTrackingStreamSource.runStarted.await(); // wait for clean termination task.getExecutingThread().join(); assertEquals(ExecutionState.FINISHED, task.getExecutionState()); assertEquals(EXPECTED_CALL_ORDER_FULL, ACTUAL_ORDER_TRACKING); }
Example #18
Source File: AbstractUdfStreamOperatorLifecycleTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testLifeCycleCancel() throws Exception { ACTUAL_ORDER_TRACKING.clear(); Configuration taskManagerConfig = new Configuration(); StreamConfig cfg = new StreamConfig(new Configuration()); MockSourceFunction srcFun = new MockSourceFunction(); cfg.setStreamOperator(new LifecycleTrackingStreamSource<>(srcFun, false)); cfg.setOperatorID(new OperatorID()); cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime); Task task = StreamTaskTest.createTask(SourceStreamTask.class, cfg, taskManagerConfig); task.startTaskThread(); LifecycleTrackingStreamSource.runStarted.await(); // this should cancel the task even though it is blocked on runFinished task.cancelExecution(); // wait for clean termination task.getExecutingThread().join(); assertEquals(ExecutionState.CANCELED, task.getExecutionState()); assertEquals(EXPECTED_CALL_ORDER_CANCEL_RUNNING, ACTUAL_ORDER_TRACKING); }
Example #19
Source File: TaskExecutor.java From flink with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Acknowledge> cancelTask(ExecutionAttemptID executionAttemptID, Time timeout) { final Task task = taskSlotTable.getTask(executionAttemptID); if (task != null) { try { task.cancelExecution(); return CompletableFuture.completedFuture(Acknowledge.get()); } catch (Throwable t) { return FutureUtils.completedExceptionally( new TaskException("Cannot cancel task for execution " + executionAttemptID + '.', t)); } } else { final String message = "Cannot find task to stop for execution " + executionAttemptID + '.'; log.debug(message); return FutureUtils.completedExceptionally(new TaskException(message)); } }
Example #20
Source File: TaskExecutor.java From flink with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Acknowledge> sendOperatorEventToTask( ExecutionAttemptID executionAttemptID, OperatorID operatorId, SerializedValue<OperatorEvent> evt) { log.debug("Operator event for {} - {}", executionAttemptID, operatorId); final Task task = taskSlotTable.getTask(executionAttemptID); if (task == null) { return FutureUtils.completedExceptionally(new TaskNotRunningException( "Task " + executionAttemptID.toHexString() + " not running on TaskManager")); } try { task.deliverOperatorEvent(operatorId, evt); return CompletableFuture.completedFuture(Acknowledge.get()); } catch (Throwable t) { ExceptionUtils.rethrowIfFatalError(t); return FutureUtils.completedExceptionally(t); } }
Example #21
Source File: TaskExecutor.java From flink with Apache License 2.0 | 6 votes |
@Override public AccumulatorReport retrievePayload(ResourceID resourceID) { validateRunsInMainThread(); return jobTable.getConnection(resourceID).map( jobManagerConnection -> { JobID jobId = jobManagerConnection.getJobId(); List<AccumulatorSnapshot> accumulatorSnapshots = new ArrayList<>(16); Iterator<Task> allTasks = taskSlotTable.getTasks(jobId); while (allTasks.hasNext()) { Task task = allTasks.next(); accumulatorSnapshots.add(task.getAccumulatorRegistry().getSnapshot()); } return new AccumulatorReport(accumulatorSnapshots); } ).orElseGet(() -> new AccumulatorReport(Collections.emptyList())); }
Example #22
Source File: TaskExecutorTest.java From flink with Apache License 2.0 | 6 votes |
private TaskExecutorTestingContext createTaskExecutorTestingContext(final TaskSlotTable<Task> taskSlotTable) throws IOException { final OneShotLatch offerSlotsLatch = new OneShotLatch(); final TestingJobMasterGateway jobMasterGateway = new TestingJobMasterGatewayBuilder() .setOfferSlotsFunction((resourceID, slotOffers) -> { offerSlotsLatch.trigger(); return CompletableFuture.completedFuture(slotOffers); }).build(); rpc.registerGateway(jobMasterGateway.getAddress(), jobMasterGateway); final JobLeaderService jobLeaderService = new DefaultJobLeaderService( unresolvedTaskManagerLocation, RetryingRegistrationConfiguration.defaultConfiguration()); TaskExecutorLocalStateStoresManager stateStoresManager = createTaskExecutorLocalStateStoresManager(); final TestingTaskExecutor taskExecutor = createTestingTaskExecutor(new TaskManagerServicesBuilder() .setTaskSlotTable(taskSlotTable) .setJobLeaderService(jobLeaderService) .setTaskStateManager(stateStoresManager) .build()); jobManagerLeaderRetriever.notifyListener(jobMasterGateway.getAddress(), jobMasterGateway.getFencingToken().toUUID()); return new TaskExecutorTestingContext(jobMasterGateway, taskSlotTable, taskExecutor); }
Example #23
Source File: TaskExecutor.java From flink with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<Acknowledge> triggerCheckpoint( ExecutionAttemptID executionAttemptID, long checkpointId, long checkpointTimestamp, CheckpointOptions checkpointOptions, boolean advanceToEndOfEventTime) { log.debug("Trigger checkpoint {}@{} for {}.", checkpointId, checkpointTimestamp, executionAttemptID); final CheckpointType checkpointType = checkpointOptions.getCheckpointType(); if (advanceToEndOfEventTime && !(checkpointType.isSynchronous() && checkpointType.isSavepoint())) { throw new IllegalArgumentException("Only synchronous savepoints are allowed to advance the watermark to MAX."); } final Task task = taskSlotTable.getTask(executionAttemptID); if (task != null) { task.triggerCheckpointBarrier(checkpointId, checkpointTimestamp, checkpointOptions, advanceToEndOfEventTime); return CompletableFuture.completedFuture(Acknowledge.get()); } else { final String message = "TaskManager received a checkpoint request for unknown task " + executionAttemptID + '.'; log.debug(message); return FutureUtils.completedExceptionally(new CheckpointException(message, CheckpointFailureReason.TASK_CHECKPOINT_FAILURE)); } }
Example #24
Source File: InterruptSensitiveRestoreTest.java From flink with Apache License 2.0 | 5 votes |
private void testRestoreWithInterrupt(int mode) throws Exception { IN_RESTORE_LATCH.reset(); Configuration taskConfig = new Configuration(); StreamConfig cfg = new StreamConfig(taskConfig); cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime); switch (mode) { case OPERATOR_MANAGED: case OPERATOR_RAW: case KEYED_MANAGED: case KEYED_RAW: cfg.setStateKeySerializer(IntSerializer.INSTANCE); cfg.setStreamOperator(new StreamSource<>(new TestSource(mode))); break; default: throw new IllegalArgumentException(); } StreamStateHandle lockingHandle = new InterruptLockingStateHandle(); Task task = createTask(cfg, taskConfig, lockingHandle, mode); // start the task and wait until it is in "restore" task.startTaskThread(); IN_RESTORE_LATCH.await(); // trigger cancellation and signal to continue task.cancelExecution(); task.getExecutingThread().join(30000); if (task.getExecutionState() == ExecutionState.CANCELING) { fail("Task is stuck and not canceling"); } assertEquals(ExecutionState.CANCELED, task.getExecutionState()); assertNull(task.getFailureCause()); }
Example #25
Source File: TaskCheckpointingBehaviourTest.java From flink with Apache License 2.0 | 5 votes |
private void runTaskExpectCheckpointDeclined(Task task, TestDeclinedCheckpointResponder checkpointResponder) throws Exception{ // start the task and wait until it is in "restore" task.startTaskThread(); checkpointResponder.declinedLatch.await(); Assert.assertEquals(ExecutionState.RUNNING, task.getExecutionState()); task.cancelExecution(); task.getExecutingThread().join(); }
Example #26
Source File: StreamTaskTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testStateBackendLoadingAndClosing() throws Exception { Configuration taskManagerConfig = new Configuration(); taskManagerConfig.setString(CheckpointingOptions.STATE_BACKEND, TestMemoryStateBackendFactory.class.getName()); StreamConfig cfg = new StreamConfig(new Configuration()); cfg.setStateKeySerializer(mock(TypeSerializer.class)); cfg.setOperatorID(new OperatorID(4711L, 42L)); TestStreamSource<Long, MockSourceFunction> streamSource = new TestStreamSource<>(new MockSourceFunction()); cfg.setStreamOperator(streamSource); cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime); Task task = createTask(StateBackendTestSource.class, cfg, taskManagerConfig); StateBackendTestSource.fail = false; task.startTaskThread(); // wait for clean termination task.getExecutingThread().join(); // ensure that the state backends and stream iterables are closed ... verify(TestStreamSource.operatorStateBackend).close(); verify(TestStreamSource.keyedStateBackend).close(); verify(TestStreamSource.rawOperatorStateInputs).close(); verify(TestStreamSource.rawKeyedStateInputs).close(); // ... and disposed verify(TestStreamSource.operatorStateBackend).dispose(); verify(TestStreamSource.keyedStateBackend).dispose(); assertEquals(ExecutionState.FINISHED, task.getExecutionState()); }
Example #27
Source File: TaskExecutor.java From flink with Apache License 2.0 | 5 votes |
private void unregisterTaskAndNotifyFinalState( final JobMasterGateway jobMasterGateway, final ExecutionAttemptID executionAttemptID) { Task task = taskSlotTable.removeTask(executionAttemptID); if (task != null) { if (!task.getExecutionState().isTerminal()) { try { task.failExternally(new IllegalStateException("Task is being remove from TaskManager.")); } catch (Exception e) { log.error("Could not properly fail task.", e); } } log.info("Un-registering task and sending final execution state {} to JobManager for task {} {}.", task.getExecutionState(), task.getTaskInfo().getTaskNameWithSubtasks(), task.getExecutionId()); AccumulatorSnapshot accumulatorSnapshot = task.getAccumulatorRegistry().getSnapshot(); updateTaskExecutionState( jobMasterGateway, new TaskExecutionState( task.getJobID(), task.getExecutionId(), task.getExecutionState(), task.getFailureCause(), accumulatorSnapshot, task.getMetricGroup().getIOMetricGroup().createSnapshot())); } else { log.error("Cannot find task with ID {} to unregister.", executionAttemptID); } }
Example #28
Source File: StreamTaskTest.java From flink with Apache License 2.0 | 5 votes |
public static Task createTask( Class<? extends AbstractInvokable> invokable, StreamConfig taskConfig, Configuration taskManagerConfig, TaskManagerActions taskManagerActions) throws Exception { return createTask(invokable, taskConfig, taskManagerConfig, new TestTaskStateManager(), taskManagerActions); }
Example #29
Source File: StreamTaskTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testStateBackendClosingOnFailure() throws Exception { Configuration taskManagerConfig = new Configuration(); taskManagerConfig.setString(CheckpointingOptions.STATE_BACKEND, TestMemoryStateBackendFactory.class.getName()); StreamConfig cfg = new StreamConfig(new Configuration()); cfg.setStateKeySerializer(mock(TypeSerializer.class)); cfg.setOperatorID(new OperatorID(4711L, 42L)); TestStreamSource<Long, MockSourceFunction> streamSource = new TestStreamSource<>(new MockSourceFunction()); cfg.setStreamOperator(streamSource); cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime); Task task = createTask(StateBackendTestSource.class, cfg, taskManagerConfig); StateBackendTestSource.fail = true; task.startTaskThread(); // wait for clean termination task.getExecutingThread().join(); // ensure that the state backends and stream iterables are closed ... verify(TestStreamSource.operatorStateBackend).close(); verify(TestStreamSource.keyedStateBackend).close(); verify(TestStreamSource.rawOperatorStateInputs).close(); verify(TestStreamSource.rawKeyedStateInputs).close(); // ... and disposed verify(TestStreamSource.operatorStateBackend).dispose(); verify(TestStreamSource.keyedStateBackend).dispose(); assertEquals(ExecutionState.FAILED, task.getExecutionState()); }
Example #30
Source File: StreamTaskTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testStateBackendLoadingAndClosing() throws Exception { Configuration taskManagerConfig = new Configuration(); taskManagerConfig.setString(CheckpointingOptions.STATE_BACKEND, TestMemoryStateBackendFactory.class.getName()); StreamConfig cfg = new StreamConfig(new Configuration()); cfg.setStateKeySerializer(mock(TypeSerializer.class)); cfg.setOperatorID(new OperatorID(4711L, 42L)); TestStreamSource<Long, MockSourceFunction> streamSource = new TestStreamSource<>(new MockSourceFunction()); cfg.setStreamOperator(streamSource); cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime); Task task = createTask(StateBackendTestSource.class, cfg, taskManagerConfig); StateBackendTestSource.fail = false; task.startTaskThread(); // wait for clean termination task.getExecutingThread().join(); // ensure that the state backends and stream iterables are closed ... verify(TestStreamSource.operatorStateBackend).close(); verify(TestStreamSource.keyedStateBackend).close(); verify(TestStreamSource.rawOperatorStateInputs).close(); verify(TestStreamSource.rawKeyedStateInputs).close(); // ... and disposed verify(TestStreamSource.operatorStateBackend).dispose(); verify(TestStreamSource.keyedStateBackend).dispose(); assertEquals(ExecutionState.FINISHED, task.getExecutionState()); }