Java Code Examples for org.apache.flink.util.OutputTag

The following examples show how to use org.apache.flink.util.OutputTag. These examples are extracted from open source projects. 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 Project: flink   Source File: SingleOutputStreamOperator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link DataStream} that contains the elements that are emitted from an operation
 * into the side output with the given {@link OutputTag}.
 *
 * @see org.apache.flink.streaming.api.functions.ProcessFunction.Context#output(OutputTag, Object)
 */
public <X> DataStream<X> getSideOutput(OutputTag<X> sideOutputTag) {
	if (wasSplitApplied) {
		throw new UnsupportedOperationException("getSideOutput() and split() may not be called on the same DataStream. " +
			"As a work-around, please add a no-op map function before the split() call.");
	}

	sideOutputTag = clean(requireNonNull(sideOutputTag));

	// make a defensive copy
	sideOutputTag = new OutputTag<X>(sideOutputTag.getId(), sideOutputTag.getTypeInfo());

	TypeInformation<?> type = requestedSideOutputs.get(sideOutputTag);
	if (type != null && !type.equals(sideOutputTag.getTypeInfo())) {
		throw new UnsupportedOperationException("A side output with a matching id was " +
				"already requested with a different type. This is not allowed, side output " +
				"ids need to be unique.");
	}

	requestedSideOutputs.put(sideOutputTag, sideOutputTag.getTypeInfo());

	SideOutputTransformation<X> sideOutputTransformation = new SideOutputTransformation<>(this.getTransformation(), sideOutputTag);
	return new DataStream<>(this.getExecutionEnvironment(), sideOutputTransformation);
}
 
Example 2
Source Project: flink   Source File: CepOperator.java    License: Apache License 2.0 6 votes vote down vote up
public CepOperator(
		final TypeSerializer<IN> inputSerializer,
		final boolean isProcessingTime,
		final NFACompiler.NFAFactory<IN> nfaFactory,
		@Nullable final EventComparator<IN> comparator,
		@Nullable final AfterMatchSkipStrategy afterMatchSkipStrategy,
		final PatternProcessFunction<IN, OUT> function,
		@Nullable final OutputTag<IN> lateDataOutputTag) {
	super(function);

	this.inputSerializer = Preconditions.checkNotNull(inputSerializer);
	this.nfaFactory = Preconditions.checkNotNull(nfaFactory);

	this.isProcessingTime = isProcessingTime;
	this.comparator = comparator;
	this.lateDataOutputTag = lateDataOutputTag;

	if (afterMatchSkipStrategy == null) {
		this.afterMatchSkipStrategy = AfterMatchSkipStrategy.noSkip();
	} else {
		this.afterMatchSkipStrategy = afterMatchSkipStrategy;
	}
}
 
Example 3
Source Project: flink   Source File: SingleOutputStreamOperator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link DataStream} that contains the elements that are emitted from an operation
 * into the side output with the given {@link OutputTag}.
 *
 * @see org.apache.flink.streaming.api.functions.ProcessFunction.Context#output(OutputTag, Object)
 */
public <X> DataStream<X> getSideOutput(OutputTag<X> sideOutputTag) {
	if (wasSplitApplied) {
		throw new UnsupportedOperationException("getSideOutput() and split() may not be called on the same DataStream. " +
			"As a work-around, please add a no-op map function before the split() call.");
	}

	sideOutputTag = clean(requireNonNull(sideOutputTag));

	// make a defensive copy
	sideOutputTag = new OutputTag<X>(sideOutputTag.getId(), sideOutputTag.getTypeInfo());

	TypeInformation<?> type = requestedSideOutputs.get(sideOutputTag);
	if (type != null && !type.equals(sideOutputTag.getTypeInfo())) {
		throw new UnsupportedOperationException("A side output with a matching id was " +
				"already requested with a different type. This is not allowed, side output " +
				"ids need to be unique.");
	}

	requestedSideOutputs.put(sideOutputTag, sideOutputTag.getTypeInfo());

	SideOutputTransformation<X> sideOutputTransformation = new SideOutputTransformation<>(this.getTransformation(), sideOutputTag);
	return new DataStream<>(this.getExecutionEnvironment(), sideOutputTransformation);
}
 
Example 4
Source Project: flink   Source File: StreamEdge.java    License: Apache License 2.0 6 votes vote down vote up
public StreamEdge(StreamNode sourceVertex, StreamNode targetVertex, int typeNumber,
		List<String> selectedNames, StreamPartitioner<?> outputPartitioner, OutputTag outputTag,
		ShuffleMode shuffleMode) {
	this.sourceId = sourceVertex.getId();
	this.targetId = targetVertex.getId();
	this.typeNumber = typeNumber;
	this.selectedNames = selectedNames;
	this.outputPartitioner = outputPartitioner;
	this.outputTag = outputTag;
	this.sourceOperatorName = sourceVertex.getOperatorName();
	this.targetOperatorName = targetVertex.getOperatorName();
	this.shuffleMode = checkNotNull(shuffleMode);

	this.edgeId = sourceVertex + "_" + targetVertex + "_" + typeNumber + "_" + selectedNames
			+ "_" + outputPartitioner;
}
 
Example 5
Source Project: flink   Source File: EvictingWindowOperator.java    License: Apache License 2.0 6 votes vote down vote up
public EvictingWindowOperator(WindowAssigner<? super IN, W> windowAssigner,
		TypeSerializer<W> windowSerializer,
		KeySelector<IN, K> keySelector,
		TypeSerializer<K> keySerializer,
		StateDescriptor<? extends ListState<StreamRecord<IN>>, ?> windowStateDescriptor,
		InternalWindowFunction<Iterable<IN>, OUT, K, W> windowFunction,
		Trigger<? super IN, ? super W> trigger,
		Evictor<? super IN, ? super W> evictor,
		long allowedLateness,
		OutputTag<IN> lateDataOutputTag) {

	super(windowAssigner, windowSerializer, keySelector,
		keySerializer, null, windowFunction, trigger, allowedLateness, lateDataOutputTag);

	this.evictor = checkNotNull(evictor);
	this.evictingWindowStateDescriptor = checkNotNull(windowStateDescriptor);
}
 
Example 6
Source Project: flink   Source File: RecordWriterOutput.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public RecordWriterOutput(
		RecordWriter<SerializationDelegate<StreamRecord<OUT>>> recordWriter,
		TypeSerializer<OUT> outSerializer,
		OutputTag outputTag,
		StreamStatusProvider streamStatusProvider) {

	checkNotNull(recordWriter);
	this.outputTag = outputTag;
	// generic hack: cast the writer to generic Object type so we can use it
	// with multiplexed records and watermarks
	this.recordWriter = (RecordWriter<SerializationDelegate<StreamElement>>)
			(RecordWriter<?>) recordWriter;

	TypeSerializer<StreamElement> outRecordSerializer =
			new StreamElementSerializer<>(outSerializer);

	if (outSerializer != null) {
		serializationDelegate = new SerializationDelegate<StreamElement>(outRecordSerializer);
	}

	this.streamStatusProvider = checkNotNull(streamStatusProvider);
}
 
Example 7
Source Project: flink   Source File: EvictingWindowOperatorContractTest.java    License: Apache License 2.0 5 votes vote down vote up
protected <W extends Window, OUT> KeyedOneInputStreamOperatorTestHarness<Integer, Integer, OUT> createWindowOperator(
		WindowAssigner<Integer, W> assigner,
		Trigger<Integer, W> trigger,
		long allowedLatenss,
		InternalWindowFunction<Iterable<Integer>, OUT, Integer, W> windowFunction,
		OutputTag<Integer> lateOutputTag) throws Exception {

	KeySelector<Integer, Integer> keySelector = new KeySelector<Integer, Integer>() {
		private static final long serialVersionUID = 1L;

		@Override
		public Integer getKey(Integer value) throws Exception {
			return value;
		}
	};

	ListStateDescriptor<StreamRecord<Integer>> intListDescriptor =
			new ListStateDescriptor<>(
					"int-list",
					(TypeSerializer<StreamRecord<Integer>>) new StreamElementSerializer(IntSerializer.INSTANCE));

	@SuppressWarnings("unchecked")
	EvictingWindowOperator<Integer, Integer, OUT, W> operator = new EvictingWindowOperator<>(
			assigner,
			assigner.getWindowSerializer(new ExecutionConfig()),
			keySelector,
			IntSerializer.INSTANCE,
			intListDescriptor,
			windowFunction,
			trigger,
			CountEvictor.<W>of(100),
			allowedLatenss,
			lateOutputTag);

	return new KeyedOneInputStreamOperatorTestHarness<>(
			operator,
			keySelector,
			BasicTypeInfo.INT_TYPE_INFO);
}
 
Example 8
Source Project: flink   Source File: CepProcessFunctionContextTest.java    License: Apache License 2.0 5 votes vote down vote up
AccessContextWithNamesWithTimedOut(
		int stateCount,
		OutputTag<String> outputTag,
		Function<Context, String> contextAccessor) {
	super(stateCount, contextAccessor);
	this.outputTag = outputTag;
}
 
Example 9
Source Project: Flink-CEPplus   Source File: SideOutputITCase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test ProcessFunction side outputs with wrong {@code OutputTag}.
 */
@Test
public void testProcessFunctionSideOutputWithWrongTag() throws Exception {
	final OutputTag<String> sideOutputTag1 = new OutputTag<String>("side"){};
	final OutputTag<String> sideOutputTag2 = new OutputTag<String>("other-side"){};

	TestListResultSink<String> sideOutputResultSink = new TestListResultSink<>();

	StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment();
	see.setParallelism(3);

	DataStream<Integer> dataStream = see.fromCollection(elements);

	dataStream
			.process(new ProcessFunction<Integer, Integer>() {
				private static final long serialVersionUID = 1L;

				@Override
				public void processElement(
						Integer value, Context ctx, Collector<Integer> out) throws Exception {
					out.collect(value);
					ctx.output(sideOutputTag2, "sideout-" + String.valueOf(value));
				}
			}).getSideOutput(sideOutputTag1).addSink(sideOutputResultSink);

	see.execute();

	assertEquals(Arrays.asList(), sideOutputResultSink.getSortedResult());
}
 
Example 10
Source Project: flink   Source File: CepOperator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> void output(final OutputTag<X> outputTag, final X value) {
	final StreamRecord<X> record;
	if (isProcessingTime) {
		record = new StreamRecord<>(value);
	} else {
		record = new StreamRecord<>(value, timestamp());
	}
	output.collect(outputTag, record);
}
 
Example 11
Source Project: flink   Source File: SideOutputITCase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test ProcessFunction side outputs with wrong {@code OutputTag}.
 */
@Test
public void testProcessFunctionSideOutputWithWrongTag() throws Exception {
	final OutputTag<String> sideOutputTag1 = new OutputTag<String>("side"){};
	final OutputTag<String> sideOutputTag2 = new OutputTag<String>("other-side"){};

	TestListResultSink<String> sideOutputResultSink = new TestListResultSink<>();

	StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment();
	see.setParallelism(3);

	DataStream<Integer> dataStream = see.fromCollection(elements);

	dataStream
			.process(new ProcessFunction<Integer, Integer>() {
				private static final long serialVersionUID = 1L;

				@Override
				public void processElement(
						Integer value, Context ctx, Collector<Integer> out) throws Exception {
					out.collect(value);
					ctx.output(sideOutputTag2, "sideout-" + String.valueOf(value));
				}
			}).getSideOutput(sideOutputTag1).addSink(sideOutputResultSink);

	see.execute();

	assertEquals(Arrays.asList(), sideOutputResultSink.getSortedResult());
}
 
Example 12
Source Project: flink   Source File: WindowOperator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> void output(OutputTag<X> outputTag, X value) {
	if (outputTag == null) {
		throw new IllegalArgumentException("OutputTag must not be null.");
	}
	output.collect(outputTag, new StreamRecord<>(value, window.maxTimestamp()));
}
 
Example 13
FlatTimeoutSelectBuilder(
		final PatternFlatSelectFunction<IN, OUT> flatSelectFunction,
		final PatternFlatTimeoutFunction<IN, TIMED_OUT> timeoutHandler,
		final OutputTag<TIMED_OUT> outputTag) {
	this.flatSelectFunction = checkNotNull(flatSelectFunction);
	this.timeoutHandler = checkNotNull(timeoutHandler);
	this.outputTag = checkNotNull(outputTag);
}
 
Example 14
Source Project: flink   Source File: SideOutputITCase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test ProcessFunction side outputs with wrong {@code OutputTag}.
 */
@Test
public void testProcessFunctionSideOutputWithWrongTag() throws Exception {
	final OutputTag<String> sideOutputTag1 = new OutputTag<String>("side"){};
	final OutputTag<String> sideOutputTag2 = new OutputTag<String>("other-side"){};

	TestListResultSink<String> sideOutputResultSink = new TestListResultSink<>();

	StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment();
	see.setParallelism(3);

	DataStream<Integer> dataStream = see.fromCollection(elements);

	dataStream
			.process(new ProcessFunction<Integer, Integer>() {
				private static final long serialVersionUID = 1L;

				@Override
				public void processElement(
						Integer value, Context ctx, Collector<Integer> out) throws Exception {
					out.collect(value);
					ctx.output(sideOutputTag2, "sideout-" + String.valueOf(value));
				}
			}).getSideOutput(sideOutputTag1).addSink(sideOutputResultSink);

	see.execute();

	assertEquals(Arrays.asList(), sideOutputResultSink.getSortedResult());
}
 
Example 15
Source Project: flink   Source File: SideOutputITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSideOutputNameClash() throws Exception {
	final OutputTag<String> sideOutputTag1 = new OutputTag<String>("side"){};
	final OutputTag<Integer> sideOutputTag2 = new OutputTag<Integer>("side"){};

	TestListResultSink<String> sideOutputResultSink1 = new TestListResultSink<>();
	TestListResultSink<Integer> sideOutputResultSink2 = new TestListResultSink<>();

	StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment();
	see.setParallelism(3);

	DataStream<Integer> dataStream = see.fromCollection(elements);

	SingleOutputStreamOperator<Integer> passThroughtStream = dataStream
			.process(new ProcessFunction<Integer, Integer>() {
				private static final long serialVersionUID = 1L;

				@Override
				public void processElement(
						Integer value, Context ctx, Collector<Integer> out) throws Exception {
					out.collect(value);
					ctx.output(sideOutputTag1, "sideout-" + String.valueOf(value));
					ctx.output(sideOutputTag2, 13);
				}
			});

	passThroughtStream.getSideOutput(sideOutputTag1).addSink(sideOutputResultSink1);

	expectedException.expect(UnsupportedOperationException.class);
	passThroughtStream.getSideOutput(sideOutputTag2).addSink(sideOutputResultSink2);
}
 
Example 16
Source Project: flink   Source File: KeyedCoProcessOperator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> void output(OutputTag<X> outputTag, X value) {
	if (outputTag == null) {
		throw new IllegalArgumentException("OutputTag must not be null.");
	}

	output.collect(outputTag, new StreamRecord<>(value, timer.getTimestamp()));
}
 
Example 17
@Test
public void testTimestampPassingForTimedOutInEventTime() throws Exception {

	OutputTag<String> timedOut = new OutputTag<String>("timedOut") {};

	try (
		OneInputStreamOperatorTestHarness<Event, String> harness = getCepTestHarness(
			createCepOperator(
				extractTimestampAndNames(2, timedOut),
				new NFATimingOutFactory(),
				EVENT_TIME))) {
		harness.open();

		// events out of order to test if internal sorting does not mess up the timestamps
		harness.processElement(event().withName("A").withTimestamp(5).asStreamRecord());
		harness.processElement(event().withName("C").withTimestamp(20).asStreamRecord());
		harness.processElement(event().withName("B").withTimestamp(3).asStreamRecord());

		harness.processWatermark(22);

		assertOutput(harness.getOutput())
			.nextElementEquals("5:B:A")
			.watermarkEquals(22)
			.hasNoMoreElements();

		assertOutput(harness.getSideOutput(timedOut))
			.nextElementEquals("15:A")
			.hasNoMoreElements();
	}
}
 
Example 18
Source Project: Flink-CEPplus   Source File: WindowOperator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@code WindowOperator} based on the given policies and user functions.
 */
public WindowOperator(
		WindowAssigner<? super IN, W> windowAssigner,
		TypeSerializer<W> windowSerializer,
		KeySelector<IN, K> keySelector,
		TypeSerializer<K> keySerializer,
		StateDescriptor<? extends AppendingState<IN, ACC>, ?> windowStateDescriptor,
		InternalWindowFunction<ACC, OUT, K, W> windowFunction,
		Trigger<? super IN, ? super W> trigger,
		long allowedLateness,
		OutputTag<IN> lateDataOutputTag) {

	super(windowFunction);

	checkArgument(!(windowAssigner instanceof BaseAlignedWindowAssigner),
		"The " + windowAssigner.getClass().getSimpleName() + " cannot be used with a WindowOperator. " +
			"This assigner is only used with the AccumulatingProcessingTimeWindowOperator and " +
			"the AggregatingProcessingTimeWindowOperator");

	checkArgument(allowedLateness >= 0);

	checkArgument(windowStateDescriptor == null || windowStateDescriptor.isSerializerInitialized(),
			"window state serializer is not properly initialized");

	this.windowAssigner = checkNotNull(windowAssigner);
	this.windowSerializer = checkNotNull(windowSerializer);
	this.keySelector = checkNotNull(keySelector);
	this.keySerializer = checkNotNull(keySerializer);
	this.windowStateDescriptor = windowStateDescriptor;
	this.trigger = checkNotNull(trigger);
	this.allowedLateness = allowedLateness;
	this.lateDataOutputTag = lateDataOutputTag;

	setChainingStrategy(ChainingStrategy.ALWAYS);
}
 
Example 19
@Test
public void testCurrentProcessingTimeForTimedOutInEventTime() throws Exception {

	OutputTag<String> sideOutputTag = new OutputTag<String>("timedOut") {};

	try (
		OneInputStreamOperatorTestHarness<Event, String> harness = getCepTestHarness(
			createCepOperator(
				extractCurrentProcessingTimeAndNames(2, sideOutputTag),
				new NFATimingOutFactory(),
				EVENT_TIME))) {
		harness.open();

		// events out of order to test if internal sorting does not mess up the timestamps
		harness.processElement(event().withName("A").withTimestamp(5).asStreamRecord());
		harness.processElement(event().withName("B").withTimestamp(20).asStreamRecord());
		harness.processElement(event().withName("C").withTimestamp(3).asStreamRecord());

		harness.setProcessingTime(100);
		harness.processWatermark(22);

		assertOutput(harness.getOutput())
			.nextElementEquals("100:C:A")
			.watermarkEquals(22)
			.hasNoMoreElements();

		assertOutput(harness.getSideOutput(sideOutputTag))
			.nextElementEquals("100:A")
			.hasNoMoreElements();
	}
}
 
Example 20
Source Project: flink   Source File: CepOperatorBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private CepOperatorBuilder(
	boolean isProcessingTime,
	NFACompiler.NFAFactory<Event> nfaFactory,
	EventComparator<Event> comparator,
	AfterMatchSkipStrategy skipStrategy,
	PatternProcessFunction<Event, OUT> processFunction,
	OutputTag<Event> lateDataOutputTag) {
	this.isProcessingTime = isProcessingTime;
	this.nfaFactory = nfaFactory;
	this.comparator = comparator;
	this.skipStrategy = skipStrategy;
	function = processFunction;
	this.lateDataOutputTag = lateDataOutputTag;
}
 
Example 21
Source Project: flink   Source File: RecordWriterOutput.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> void collect(OutputTag<X> outputTag, StreamRecord<X> record) {
	if (this.outputTag == null || !this.outputTag.equals(outputTag)) {
		// we are not responsible for emitting to the side-output specified by this
		// OutputTag.
		return;
	}

	pushToRecordWriter(record);
}
 
Example 22
Source Project: flink   Source File: OperatorChain.java    License: Apache License 2.0 5 votes vote down vote up
public CopyingChainingOutput(
		OneInputStreamOperator<T, ?> operator,
		TypeSerializer<T> serializer,
		OutputTag<T> outputTag,
		StreamStatusProvider streamStatusProvider) {
	super(operator, streamStatusProvider, outputTag);
	this.serializer = serializer;
}
 
Example 23
Source Project: flink   Source File: KeyedCoProcessOperator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> void output(OutputTag<X> outputTag, X value) {
	if (outputTag == null) {
		throw new IllegalArgumentException("OutputTag must not be null.");
	}

	output.collect(outputTag, new StreamRecord<>(value, element.getTimestamp()));
}
 
Example 24
Source Project: flink   Source File: OperatorChain.java    License: Apache License 2.0 5 votes vote down vote up
public CopyingChainingOutput(
		OneInputStreamOperator<T, ?> operator,
		TypeSerializer<T> serializer,
		OutputTag<T> outputTag,
		StreamStatusProvider streamStatusProvider) {
	super(operator, streamStatusProvider, outputTag);
	this.serializer = serializer;
}
 
Example 25
Source Project: flink-statefun   Source File: SideOutputTranslator.java    License: Apache License 2.0 5 votes vote down vote up
private static OutputTag<Object> outputTagFromId(
    EgressIdentifier<?> id, StaticallyRegisteredTypes types) {
  @SuppressWarnings("unchecked")
  EgressIdentifier<Object> casted = (EgressIdentifier<Object>) id;
  String name = String.format("%s.%s", id.namespace(), id.name());
  TypeInformation<Object> typeInformation = types.registerType(casted.consumedType());
  return new OutputTag<>(name, typeInformation);
}
 
Example 26
Source Project: flink   Source File: PatternTimeoutSelectAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PatternTimeoutSelectAdapter(
		final PatternSelectFunction<IN, OUT> selectFunction,
		final PatternTimeoutFunction<IN, T> timeoutFunction,
		final OutputTag<T> timedOutPartialMatchesTag) {
	super(selectFunction);
	this.timeoutFunction = checkNotNull(timeoutFunction);
	this.timedOutPartialMatchesTag = checkNotNull(timedOutPartialMatchesTag);
}
 
Example 27
Source Project: flink   Source File: PatternTimeoutFlatSelectAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PatternTimeoutFlatSelectAdapter(
		PatternFlatSelectFunction<IN, OUT> flatSelectFunction,
		PatternFlatTimeoutFunction<IN, T> flatTimeoutFunction,
		OutputTag<T> timedOutPartialMatchesTag) {
	super(flatSelectFunction);
	this.flatTimeoutFunction = checkNotNull(flatTimeoutFunction);
	this.timedOutPartialMatchesTag = checkNotNull(timedOutPartialMatchesTag);
}
 
Example 28
Source Project: flink   Source File: LegacyKeyedProcessOperator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> void output(OutputTag<X> outputTag, X value) {
	if (outputTag == null) {
		throw new IllegalArgumentException("OutputTag must not be null.");
	}

	output.collect(outputTag, new StreamRecord<>(value, timer.getTimestamp()));
}
 
Example 29
Source Project: flink   Source File: CepProcessFunctionContextTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCurrentProcessingTimeForTimedOutInEventTime() throws Exception {

	OutputTag<String> sideOutputTag = new OutputTag<String>("timedOut") {};

	try (
		OneInputStreamOperatorTestHarness<Event, String> harness = getCepTestHarness(
			createCepOperator(
				extractCurrentProcessingTimeAndNames(2, sideOutputTag),
				new NFATimingOutFactory(),
				EVENT_TIME))) {
		harness.open();

		// events out of order to test if internal sorting does not mess up the timestamps
		harness.processElement(event().withName("A").withTimestamp(5).asStreamRecord());
		harness.processElement(event().withName("B").withTimestamp(20).asStreamRecord());
		harness.processElement(event().withName("C").withTimestamp(3).asStreamRecord());

		harness.setProcessingTime(100);
		harness.processWatermark(22);

		assertOutput(harness.getOutput())
			.nextElementEquals("100:C:A")
			.watermarkEquals(22)
			.hasNoMoreElements();

		assertOutput(harness.getSideOutput(sideOutputTag))
			.nextElementEquals("100:A")
			.hasNoMoreElements();
	}
}
 
Example 30
Source Project: Flink-CEPplus   Source File: LegacyKeyedProcessOperator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> void output(OutputTag<X> outputTag, X value) {
	if (outputTag == null) {
		throw new IllegalArgumentException("OutputTag must not be null.");
	}

	output.collect(outputTag, new StreamRecord<>(value, element.getTimestamp()));
}