/** * Invoke the Task. This resets the output of any previous invocation. This will start a new * Thread to execute the Task in. Use {@link #waitForTaskCompletion()} to wait for the * Task thread to finish running. * */ public void invoke() throws Exception { invoke(createEnvironment()); }
testHarness.invoke(); testHarness.waitForTaskRunning();
/** * This test checks that tasks emit a proper cancel checkpoint barrier, if a "trigger checkpoint" message * comes before they are ready. */ @Test public void testEmitCancellationBarrierWhenNotReady() throws Exception { StreamTaskTestHarness<String> testHarness = new StreamTaskTestHarness<>( InitBlockingTask::new, BasicTypeInfo.STRING_TYPE_INFO); testHarness.setupOutputForSingletonOperatorChain(); // start the test - this cannot succeed across the 'init()' method testHarness.invoke(); StreamTask<String, ?> task = testHarness.getTask(); // tell the task to commence a checkpoint boolean result = task.triggerCheckpoint(new CheckpointMetaData(41L, System.currentTimeMillis()), CheckpointOptions.forCheckpointWithDefaultLocation()); assertFalse("task triggered checkpoint though not ready", result); // a cancellation barrier should be downstream Object emitted = testHarness.getOutput().poll(); assertNotNull("nothing emitted", emitted); assertTrue("wrong type emitted", emitted instanceof CancelCheckpointMarker); assertEquals("wrong checkpoint id", 41L, ((CancelCheckpointMarker) emitted).getCheckpointId()); }
@Test public void testIterationHeadWatermarkEmission() throws Exception { StreamTaskTestHarness<Integer> harness = new StreamTaskTestHarness<>( StreamIterationHead::new, BasicTypeInfo.INT_TYPE_INFO); harness.setupOutputForSingletonOperatorChain(); harness.getStreamConfig().setIterationId("1"); harness.getStreamConfig().setIterationWaitTime(1); harness.invoke(); harness.waitForTaskCompletion(); assertEquals(1, harness.getOutput().size()); assertEquals(new Watermark(Long.MAX_VALUE), harness.getOutput().peek()); } }
/** * This test verifies that open() and close() are correctly called by the StreamTask. */ @Test @SuppressWarnings("unchecked") public void testOpenClose() throws Exception { final StreamTaskTestHarness<String> testHarness = new StreamTaskTestHarness<>( SourceStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO); testHarness.setupOutputForSingletonOperatorChain(); StreamConfig streamConfig = testHarness.getStreamConfig(); StreamSource<String, ?> sourceOperator = new StreamSource<>(new OpenCloseTestSource()); streamConfig.setStreamOperator(sourceOperator); streamConfig.setOperatorID(new OperatorID()); testHarness.invoke(); testHarness.waitForTaskCompletion(); Assert.assertTrue("RichFunction methods where not called.", OpenCloseTestSource.closeCalled); List<String> resultElements = TestHarnessUtil.getRawElementsFromOutput(testHarness.getOutput()); Assert.assertEquals(10, resultElements.size()); }
testHarness.invoke();