@Test public void testInitializeAfterOpenning() throws Throwable { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(containsString("TestHarness has already been initialized.")); AbstractStreamOperatorTestHarness<Integer> result; result = new AbstractStreamOperatorTestHarness<>( new AbstractStreamOperator<Integer>() { }, 1, 1, 0); result.setup(); result.open(); result.initializeState(new OperatorSubtaskState()); } }
new AbstractStreamOperatorTestHarness<>(consumerOperator, 1, 1, 0); testHarness.setTimeCharacteristic(TimeCharacteristic.ProcessingTime); testHarness.setup(); testHarness.open(); synchronized (testHarness.getCheckpointLock()) { snapshot = testHarness.snapshot(0L, 0L);
/** * Calls {@link StreamOperator#open()}. This also * calls {@link StreamOperator#setup(StreamTask, StreamConfig, Output)} * if it was not called before. */ public void open() throws Exception { if (!initializeCalled) { initializeEmptyState(); } operator.open(); }
private static <T> AbstractStreamOperatorTestHarness<T> createTestHarness( SourceFunction<T> source, int numSubtasks, int subtaskIndex) throws Exception { AbstractStreamOperatorTestHarness<T> testHarness = new AbstractStreamOperatorTestHarness<>( new StreamSource<>(source), Short.MAX_VALUE / 2, numSubtasks, subtaskIndex); testHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); return testHarness; }
private static void testUDF(TestUserFunction userFunction) throws Exception { OperatorSubtaskState snapshot; try (AbstractStreamOperatorTestHarness<Integer> testHarness = createTestHarness(userFunction)) { testHarness.open(); snapshot = testHarness.snapshot(0L, 0L); assertFalse(userFunction.isRestored()); } try (AbstractStreamOperatorTestHarness<Integer> testHarness = createTestHarness(userFunction)) { testHarness.initializeState(snapshot); testHarness.open(); assertTrue(userFunction.isRestored()); } }
WindowedValue<ValueWithRecordId<KV<Integer, Integer>>>> testHarness = new AbstractStreamOperatorTestHarness<>( sourceOperator, testHarness.getExecutionConfig().setLatencyTrackingInterval(0); testHarness.getExecutionConfig().setAutoWatermarkInterval(1); testHarness.setProcessingTime(Long.MIN_VALUE); testHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); testHarness.open(); try { sourceOperator.run( testHarness.getCheckpointLock(), new TestStreamStatusMaintainer(), new Output< synchronized (testHarness.getCheckpointLock()) { testHarness.setProcessingTime(0); synchronized (testHarness.getCheckpointLock()) { testHarness.setProcessingTime(Long.MAX_VALUE);
new AbstractStreamOperatorTestHarness<>( sourceOperator, testHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); testHarness.open(); sourceOperator.run( checkpointLock, OperatorSubtaskState snapshot = testHarness.snapshot(0, 0); testHarness.notifyOfCompletedCheckpoint(0); new AbstractStreamOperatorTestHarness<>( restoredSourceOperator, 0 /* subtask index */); restoredTestHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); restoredTestHarness.initializeState(snapshot); restoredTestHarness.open(); restoredSourceOperator.run( checkpointLock,
testHarnesses[i].initializeEmptyState(); testHarnesses[i].open(); state[i] = testHarnesses[i].snapshot(0, 0); OperatorSubtaskState mergedState = AbstractStreamOperatorTestHarness.repackageState(state); restoredTestHarnesses[i].initializeState(mergedState); restoredTestHarnesses[i].open();
new AbstractStreamOperatorTestHarness<>( sourceOperator, testHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); testHarness.open(); sourceOperator.run(checkpointLock, new TestStreamStatusMaintainer(),
new AbstractStreamOperatorTestHarness<>( sourceOperator, testHarness.setProcessingTime(Instant.now().getMillis()); testHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); testHarness.setProcessingTime(Instant.now().getMillis());
mergedSnapshot = AbstractStreamOperatorTestHarness.repackageState( testHarness1.snapshot(1L, 0L), testHarness2.snapshot(1L, 0L)
/** * Calls {@link org.apache.flink.streaming.api.operators.StreamOperator#initializeState()}. * Calls {@link org.apache.flink.streaming.api.operators.StreamOperator#setup(StreamTask, StreamConfig, Output)} * if it was not called before. * * <p>This will reshape the state handles to include only those key-group states * in the local key-group range and the operator states that would be assigned to the local * subtask. */ public void initializeState(OperatorSubtaskState operatorStateHandles) throws Exception { initializeState(operatorStateHandles, null); }
private static AbstractStreamOperatorTestHarness<Integer> createTestHarness(TestUserFunction userFunction) throws Exception { return new AbstractStreamOperatorTestHarness<>( new StreamMap<>(userFunction), 1, 1, 0); }
@Override public void run() { try { testHarness.open(); sourceOperator.run(checkpointLock, new TestStreamStatusMaintainer(),
@Override public void run() { while (true) { try { testHarness.setProcessingTime(System.currentTimeMillis()); Thread.sleep(100); } catch (InterruptedException e) { // this is ok break; } catch (Exception e) { LOG.error("Unexpected error advancing processing time", e); break; } } } };
new AbstractStreamOperatorTestHarness<>( sourceOperator, testHarness.setProcessingTime(System.currentTimeMillis()); processingTimeUpdateThread.start(); testHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); testHarness.open(); sourceOperator.run( testHarness.getCheckpointLock(), new TestStreamStatusMaintainer(), new Output<StreamRecord<WindowedValue<ValueWithRecordId<KV<Integer, Integer>>>>>() {
new AbstractStreamOperatorTestHarness<>( sourceOperator, testHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); testHarness.open(); sourceOperator.run( checkpointLock, OperatorSubtaskState snapshot = testHarness.snapshot(0, 0); testHarness.notifyOfCompletedCheckpoint(0); new AbstractStreamOperatorTestHarness<>( restoredSourceOperator, 0 /* subtask index */); restoredTestHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); restoredTestHarness.initializeState(snapshot); restoredTestHarness.open(); restoredSourceOperator.run( checkpointLock,
testHarness2.processElement2(new StreamRecord<>(3)); mergedSnapshot = AbstractStreamOperatorTestHarness.repackageState( testHarness1.snapshot(0L, 0L), testHarness2.snapshot(0L, 0L)
public void initializeEmptyState() throws Exception { initializeState((OperatorSubtaskState) null); }
@Override public void run() { while (true) { try { testHarness.setProcessingTime(System.currentTimeMillis()); Thread.sleep(1000); } catch (InterruptedException e) { // this is ok break; } catch (Exception e) { LOG.error("Unexpected error advancing processing time", e); break; } } } };