Java Code Examples for org.apache.flink.cep.utils.NFATestHarness#consumeRecords()

The following examples show how to use org.apache.flink.cep.utils.NFATestHarness#consumeRecords() . 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 File: NFATest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeoutWindowPruning() throws Exception {
	List<StreamRecord<Event>> streamEvents = new ArrayList<>();

	streamEvents.add(new StreamRecord<>(new Event(1, "start", 1.0), 1L));
	streamEvents.add(new StreamRecord<>(new Event(2, "bar", 2.0), 2L));
	streamEvents.add(new StreamRecord<>(new Event(3, "start", 3.0), 3L));
	streamEvents.add(new StreamRecord<>(new Event(4, "end", 4.0), 4L));

	List<Map<String, List<Event>>> expectedPatterns = new ArrayList<>();

	Map<String, List<Event>> secondPattern = new HashMap<>();
	secondPattern.put("start", Collections.singletonList(new Event(3, "start", 3.0)));
	secondPattern.put("end", Collections.singletonList(new Event(4, "end", 4.0)));

	expectedPatterns.add(secondPattern);

	NFA<Event> nfa = createStartEndNFA();
	NFATestHarness nfaTestHarness = NFATestHarness.forNFA(nfa).build();

	Collection<Map<String, List<Event>>> actualPatterns = nfaTestHarness.consumeRecords(streamEvents);

	assertEquals(expectedPatterns, actualPatterns);
}
 
Example 2
Source File: NFATest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that elements whose timestamp difference is exactly the window length are not matched.
 * The reason is that the right window side (later elements) is exclusive.
 */
@Test
public void testWindowBorders() throws Exception {
	List<StreamRecord<Event>> streamEvents = new ArrayList<>();

	streamEvents.add(new StreamRecord<>(new Event(1, "start", 1.0), 1L));
	streamEvents.add(new StreamRecord<>(new Event(2, "end", 2.0), 3L));

	List<Map<String, List<Event>>> expectedPatterns = Collections.emptyList();

	NFA<Event> nfa = createStartEndNFA();
	NFATestHarness nfaTestHarness = NFATestHarness.forNFA(nfa).build();

	Collection<Map<String, List<Event>>> actualPatterns = nfaTestHarness.consumeRecords(streamEvents);

	assertEquals(expectedPatterns, actualPatterns);
}
 
Example 3
Source File: NFATest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that pruning shared buffer elements and computations state use the same window border
 * semantics (left side inclusive and right side exclusive).
 */
@Test
public void testTimeoutWindowPruningWindowBorders() throws Exception {
	List<StreamRecord<Event>> streamEvents = new ArrayList<>();

	streamEvents.add(new StreamRecord<>(new Event(1, "start", 1.0), 1L));
	streamEvents.add(new StreamRecord<>(new Event(2, "start", 2.0), 2L));
	streamEvents.add(new StreamRecord<>(new Event(3, "foobar", 3.0), 3L));
	streamEvents.add(new StreamRecord<>(new Event(4, "end", 4.0), 3L));

	List<Map<String, List<Event>>> expectedPatterns = new ArrayList<>();

	Map<String, List<Event>> secondPattern = new HashMap<>();
	secondPattern.put("start", Collections.singletonList(new Event(2, "start", 2.0)));
	secondPattern.put("end", Collections.singletonList(new Event(4, "end", 4.0)));

	expectedPatterns.add(secondPattern);

	NFA<Event> nfa = createStartEndNFA();
	NFATestHarness nfaTestHarness = NFATestHarness.forNFA(nfa).build();

	Collection<Map<String, List<Event>>> actualPatterns = nfaTestHarness.consumeRecords(streamEvents);

	assertEquals(expectedPatterns, actualPatterns);
}
 
Example 4
Source File: NFATest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeoutWindowPruning() throws Exception {
	List<StreamRecord<Event>> streamEvents = new ArrayList<>();

	streamEvents.add(new StreamRecord<>(new Event(1, "start", 1.0), 1L));
	streamEvents.add(new StreamRecord<>(new Event(2, "bar", 2.0), 2L));
	streamEvents.add(new StreamRecord<>(new Event(3, "start", 3.0), 3L));
	streamEvents.add(new StreamRecord<>(new Event(4, "end", 4.0), 4L));

	List<Map<String, List<Event>>> expectedPatterns = new ArrayList<>();

	Map<String, List<Event>> secondPattern = new HashMap<>();
	secondPattern.put("start", Collections.singletonList(new Event(3, "start", 3.0)));
	secondPattern.put("end", Collections.singletonList(new Event(4, "end", 4.0)));

	expectedPatterns.add(secondPattern);

	NFA<Event> nfa = createStartEndNFA();
	NFATestHarness nfaTestHarness = NFATestHarness.forNFA(nfa).build();

	Collection<Map<String, List<Event>>> actualPatterns = nfaTestHarness.consumeRecords(streamEvents);

	assertEquals(expectedPatterns, actualPatterns);
}
 
Example 5
Source File: NFATest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that elements whose timestamp difference is exactly the window length are not matched.
 * The reason is that the right window side (later elements) is exclusive.
 */
@Test
public void testWindowBorders() throws Exception {
	List<StreamRecord<Event>> streamEvents = new ArrayList<>();

	streamEvents.add(new StreamRecord<>(new Event(1, "start", 1.0), 1L));
	streamEvents.add(new StreamRecord<>(new Event(2, "end", 2.0), 3L));

	List<Map<String, List<Event>>> expectedPatterns = Collections.emptyList();

	NFA<Event> nfa = createStartEndNFA();
	NFATestHarness nfaTestHarness = NFATestHarness.forNFA(nfa).build();

	Collection<Map<String, List<Event>>> actualPatterns = nfaTestHarness.consumeRecords(streamEvents);

	assertEquals(expectedPatterns, actualPatterns);
}
 
Example 6
Source File: NFATest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that pruning shared buffer elements and computations state use the same window border
 * semantics (left side inclusive and right side exclusive).
 */
@Test
public void testTimeoutWindowPruningWindowBorders() throws Exception {
	List<StreamRecord<Event>> streamEvents = new ArrayList<>();

	streamEvents.add(new StreamRecord<>(new Event(1, "start", 1.0), 1L));
	streamEvents.add(new StreamRecord<>(new Event(2, "start", 2.0), 2L));
	streamEvents.add(new StreamRecord<>(new Event(3, "foobar", 3.0), 3L));
	streamEvents.add(new StreamRecord<>(new Event(4, "end", 4.0), 3L));

	List<Map<String, List<Event>>> expectedPatterns = new ArrayList<>();

	Map<String, List<Event>> secondPattern = new HashMap<>();
	secondPattern.put("start", Collections.singletonList(new Event(2, "start", 2.0)));
	secondPattern.put("end", Collections.singletonList(new Event(4, "end", 4.0)));

	expectedPatterns.add(secondPattern);

	NFA<Event> nfa = createStartEndNFA();
	NFATestHarness nfaTestHarness = NFATestHarness.forNFA(nfa).build();

	Collection<Map<String, List<Event>>> actualPatterns = nfaTestHarness.consumeRecords(streamEvents);

	assertEquals(expectedPatterns, actualPatterns);
}
 
Example 7
Source File: NFATest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeoutWindowPruning() throws Exception {
	List<StreamRecord<Event>> streamEvents = new ArrayList<>();

	streamEvents.add(new StreamRecord<>(new Event(1, "start", 1.0), 1L));
	streamEvents.add(new StreamRecord<>(new Event(2, "bar", 2.0), 2L));
	streamEvents.add(new StreamRecord<>(new Event(3, "start", 3.0), 3L));
	streamEvents.add(new StreamRecord<>(new Event(4, "end", 4.0), 4L));

	List<Map<String, List<Event>>> expectedPatterns = new ArrayList<>();

	Map<String, List<Event>> secondPattern = new HashMap<>();
	secondPattern.put("start", Collections.singletonList(new Event(3, "start", 3.0)));
	secondPattern.put("end", Collections.singletonList(new Event(4, "end", 4.0)));

	expectedPatterns.add(secondPattern);

	NFA<Event> nfa = createStartEndNFA();
	NFATestHarness nfaTestHarness = NFATestHarness.forNFA(nfa).build();

	Collection<Map<String, List<Event>>> actualPatterns = nfaTestHarness.consumeRecords(streamEvents);

	assertEquals(expectedPatterns, actualPatterns);
}
 
Example 8
Source File: NFATest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that elements whose timestamp difference is exactly the window length are not matched.
 * The reason is that the right window side (later elements) is exclusive.
 */
@Test
public void testWindowBorders() throws Exception {
	List<StreamRecord<Event>> streamEvents = new ArrayList<>();

	streamEvents.add(new StreamRecord<>(new Event(1, "start", 1.0), 1L));
	streamEvents.add(new StreamRecord<>(new Event(2, "end", 2.0), 3L));

	List<Map<String, List<Event>>> expectedPatterns = Collections.emptyList();

	NFA<Event> nfa = createStartEndNFA();
	NFATestHarness nfaTestHarness = NFATestHarness.forNFA(nfa).build();

	Collection<Map<String, List<Event>>> actualPatterns = nfaTestHarness.consumeRecords(streamEvents);

	assertEquals(expectedPatterns, actualPatterns);
}
 
Example 9
Source File: NFATest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that pruning shared buffer elements and computations state use the same window border
 * semantics (left side inclusive and right side exclusive).
 */
@Test
public void testTimeoutWindowPruningWindowBorders() throws Exception {
	List<StreamRecord<Event>> streamEvents = new ArrayList<>();

	streamEvents.add(new StreamRecord<>(new Event(1, "start", 1.0), 1L));
	streamEvents.add(new StreamRecord<>(new Event(2, "start", 2.0), 2L));
	streamEvents.add(new StreamRecord<>(new Event(3, "foobar", 3.0), 3L));
	streamEvents.add(new StreamRecord<>(new Event(4, "end", 4.0), 3L));

	List<Map<String, List<Event>>> expectedPatterns = new ArrayList<>();

	Map<String, List<Event>> secondPattern = new HashMap<>();
	secondPattern.put("start", Collections.singletonList(new Event(2, "start", 2.0)));
	secondPattern.put("end", Collections.singletonList(new Event(4, "end", 4.0)));

	expectedPatterns.add(secondPattern);

	NFA<Event> nfa = createStartEndNFA();
	NFATestHarness nfaTestHarness = NFATestHarness.forNFA(nfa).build();

	Collection<Map<String, List<Event>>> actualPatterns = nfaTestHarness.consumeRecords(streamEvents);

	assertEquals(expectedPatterns, actualPatterns);
}