use of org.apache.flink.runtime.jobgraph.OperatorID in project flink by apache.
the class TestProcessingTimeServiceTest method testCustomTimeServiceProvider.
@Test
public void testCustomTimeServiceProvider() throws Throwable {
final TestProcessingTimeService tp = new TestProcessingTimeService();
final OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>((env) -> new OneInputStreamTask<>(env, tp), BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
testHarness.setupOutputForSingletonOperatorChain();
StreamConfig streamConfig = testHarness.getStreamConfig();
StreamMap<String, String> mapOperator = new StreamMap<>(new StreamTaskTimerTest.DummyMapFunction<>());
streamConfig.setStreamOperator(mapOperator);
streamConfig.setOperatorID(new OperatorID());
testHarness.invoke();
testHarness.waitForTaskRunning();
ProcessingTimeService processingTimeService = ((StreamMap<?, ?>) testHarness.getHeadOperator()).getProcessingTimeService();
assertEquals(Long.MIN_VALUE, processingTimeService.getCurrentProcessingTime());
tp.setCurrentTime(11);
assertEquals(processingTimeService.getCurrentProcessingTime(), 11);
tp.setCurrentTime(15);
tp.setCurrentTime(16);
assertEquals(processingTimeService.getCurrentProcessingTime(), 16);
// register 2 tasks
processingTimeService.registerTimer(30, timestamp -> {
});
processingTimeService.registerTimer(40, timestamp -> {
});
assertEquals(2, tp.getNumActiveTimers());
tp.setCurrentTime(35);
assertEquals(1, tp.getNumActiveTimers());
tp.setCurrentTime(40);
assertEquals(0, tp.getNumActiveTimers());
tp.shutdownService();
}
use of org.apache.flink.runtime.jobgraph.OperatorID in project flink by apache.
the class AdaptiveSchedulerTest method testDeliverCoordinationRequestToCoordinatorFailsInIllegalState.
@Test
public void testDeliverCoordinationRequestToCoordinatorFailsInIllegalState() throws Exception {
final AdaptiveScheduler scheduler = new AdaptiveSchedulerBuilder(createJobGraph(), mainThreadExecutor).build();
assertThat(scheduler.deliverCoordinationRequestToCoordinator(new OperatorID(), new CoordinationRequest() {
})).failsWithin(1, TimeUnit.MILLISECONDS).withThrowableOfType(ExecutionException.class).withCauseInstanceOf(FlinkException.class);
}
use of org.apache.flink.runtime.jobgraph.OperatorID in project flink by apache.
the class StreamTaskTest method testTaskAvoidHangingAfterSnapshotStateThrownException.
@Test
public void testTaskAvoidHangingAfterSnapshotStateThrownException() throws Exception {
// given: Configured SourceStreamTask with source which fails on checkpoint.
Configuration taskManagerConfig = new Configuration();
taskManagerConfig.setString(STATE_BACKEND, TestMemoryStateBackendFactory.class.getName());
StreamConfig cfg = new StreamConfig(new Configuration());
cfg.setStateKeySerializer(mock(TypeSerializer.class));
cfg.setOperatorID(new OperatorID(4712L, 43L));
FailedSource failedSource = new FailedSource();
cfg.setStreamOperator(new TestStreamSource<String, FailedSource>(failedSource));
cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime);
try (NettyShuffleEnvironment shuffleEnvironment = new NettyShuffleEnvironmentBuilder().build()) {
Task task = createTask(SourceStreamTask.class, shuffleEnvironment, cfg, taskManagerConfig);
// when: Task starts
task.startTaskThread();
// wait for the task starts doing the work.
failedSource.awaitRunning();
// and: Checkpoint is triggered which should lead to exception in Source.
task.triggerCheckpointBarrier(42L, 1L, CheckpointOptions.forCheckpointWithDefaultLocation());
// wait for clean termination.
task.getExecutingThread().join();
// then: The task doesn't hang but finished with FAILED state.
assertEquals(ExecutionState.FAILED, task.getExecutionState());
}
}
use of org.apache.flink.runtime.jobgraph.OperatorID in project flink by apache.
the class StreamTaskTest method testThreadInvariants.
/**
* Tests that some StreamTask methods are called only in the main task's thread. Currently, the
* main task's thread is the thread that creates the task.
*/
@Test
public void testThreadInvariants() throws Throwable {
Configuration taskConfiguration = new Configuration();
StreamConfig streamConfig = new StreamConfig(taskConfiguration);
streamConfig.setStreamOperator(new StreamMap<>(value -> value));
streamConfig.setOperatorID(new OperatorID());
try (MockEnvironment mockEnvironment = new MockEnvironmentBuilder().setTaskConfiguration(taskConfiguration).build()) {
ClassLoader taskClassLoader = new TestUserCodeClassLoader();
RunningTask<ThreadInspectingTask> runningTask = runTask(() -> {
Thread.currentThread().setContextClassLoader(taskClassLoader);
return new ThreadInspectingTask(mockEnvironment);
});
runningTask.invocationFuture.get();
assertThat(runningTask.streamTask.getTaskClassLoader(), is(sameInstance(taskClassLoader)));
}
}
use of org.apache.flink.runtime.jobgraph.OperatorID in project flink by apache.
the class RestoreStreamTaskTest method testRestore.
@Test
public void testRestore() throws Exception {
OperatorID headOperatorID = new OperatorID(42L, 42L);
OperatorID tailOperatorID = new OperatorID(44L, 44L);
JobManagerTaskRestore restore = createRunAndCheckpointOperatorChain(headOperatorID, new CounterOperator(), tailOperatorID, new CounterOperator(), Optional.empty());
TaskStateSnapshot stateHandles = restore.getTaskStateSnapshot();
assertEquals(2, stateHandles.getSubtaskStateMappings().size());
createRunAndCheckpointOperatorChain(headOperatorID, new CounterOperator(), tailOperatorID, new CounterOperator(), Optional.of(restore));
assertEquals(new HashSet<>(Arrays.asList(headOperatorID, tailOperatorID)), RESTORED_OPERATORS.keySet());
assertThat(new HashSet<>(RESTORED_OPERATORS.values()), contains(restore.getRestoreCheckpointId()));
}
Aggregations