use of org.apache.flink.api.java.functions.NullByteKeySelector in project flink by apache.
the class CEPMigration11to13Test method testNonKeyedCEPFunctionMigration.
@Test
public void testNonKeyedCEPFunctionMigration() throws Exception {
final Event startEvent = new Event(42, "start", 1.0);
final SubEvent middleEvent = new SubEvent(42, "foo", 1.0, 10.0);
final Event endEvent = new Event(42, "end", 1.0);
// uncomment these lines for regenerating the snapshot on Flink 1.1
/*
OneInputStreamOperatorTestHarness<Event, Map<String, Event>> harness = new OneInputStreamOperatorTestHarness<>(
new CEPPatternOperator<>(
Event.createTypeSerializer(),
false,
new NFAFactory()));
harness.open();
harness.processElement(new StreamRecord<Event>(startEvent, 1));
harness.processElement(new StreamRecord<Event>(new Event(42, "foobar", 1.0), 2));
harness.processElement(new StreamRecord<Event>(new SubEvent(42, "barfoo", 1.0, 5.0), 3));
harness.processWatermark(new Watermark(2));
// simulate snapshot/restore with empty element queue but NFA state
StreamTaskState snapshot = harness.snapshot(1, 1);
FileOutputStream out = new FileOutputStream(
"src/test/resources/cep-non-keyed-snapshot-1.1");
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(snapshot);
out.close();
harness.close();
*/
NullByteKeySelector keySelector = new NullByteKeySelector();
OneInputStreamOperatorTestHarness<Event, Map<String, Event>> harness = new KeyedOneInputStreamOperatorTestHarness<>(new KeyedCEPPatternOperator<>(Event.createTypeSerializer(), false, keySelector, ByteSerializer.INSTANCE, new NFAFactory(), false), keySelector, BasicTypeInfo.BYTE_TYPE_INFO);
harness.setup();
harness.initializeStateFromLegacyCheckpoint(getResourceFilename("cep-non-keyed-snapshot-1.1"));
harness.open();
harness.processElement(new StreamRecord<Event>(middleEvent, 3));
harness.processElement(new StreamRecord<>(new Event(42, "start", 1.0), 4));
harness.processElement(new StreamRecord<>(endEvent, 5));
harness.processWatermark(new Watermark(Long.MAX_VALUE));
ConcurrentLinkedQueue<Object> result = harness.getOutput();
// watermark and the result
assertEquals(2, result.size());
Object resultObject = result.poll();
assertTrue(resultObject instanceof StreamRecord);
StreamRecord<?> resultRecord = (StreamRecord<?>) resultObject;
assertTrue(resultRecord.getValue() instanceof Map);
@SuppressWarnings("unchecked") Map<String, Event> patternMap = (Map<String, Event>) resultRecord.getValue();
assertEquals(startEvent, patternMap.get("start"));
assertEquals(middleEvent, patternMap.get("middle"));
assertEquals(endEvent, patternMap.get("end"));
harness.close();
}
Aggregations