org.apache.flink.cep.nfa.DeweyNumber Java Examples
The following examples show how to use
org.apache.flink.cep.nfa.DeweyNumber.
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: SharedBufferAccessor.java From flink with Apache License 2.0 | 6 votes |
/** * Stores given value (value + timestamp) under the given state. It assigns a preceding element * relation to the previous entry. * * @param stateName name of the state that the event should be assigned to * @param eventId unique id of event assigned by this SharedBuffer * @param previousNodeId id of previous entry (might be null if start of new run) * @param version Version of the previous relation * @return assigned id of this element */ public NodeId put( final String stateName, final EventId eventId, @Nullable final NodeId previousNodeId, final DeweyNumber version) { if (previousNodeId != null) { lockNode(previousNodeId); } NodeId currentNodeId = new NodeId(eventId, getOriginalNameFromInternal(stateName)); Lockable<SharedBufferNode> currentNode = sharedBuffer.getEntry(currentNodeId); if (currentNode == null) { currentNode = new Lockable<>(new SharedBufferNode(), 0); lockEvent(eventId); } currentNode.getElement().addEdge(new SharedBufferEdge( previousNodeId, version)); sharedBuffer.upsertEntry(currentNodeId, currentNode); return currentNodeId; }
Example #2
Source File: SharedBufferAccessor.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Stores given value (value + timestamp) under the given state. It assigns a preceding element * relation to the previous entry. * * @param stateName name of the state that the event should be assigned to * @param eventId unique id of event assigned by this SharedBuffer * @param previousNodeId id of previous entry (might be null if start of new run) * @param version Version of the previous relation * @return assigned id of this element */ public NodeId put( final String stateName, final EventId eventId, @Nullable final NodeId previousNodeId, final DeweyNumber version) { if (previousNodeId != null) { lockNode(previousNodeId); } NodeId currentNodeId = new NodeId(eventId, getOriginalNameFromInternal(stateName)); Lockable<SharedBufferNode> currentNode = sharedBuffer.getEntry(currentNodeId); if (currentNode == null) { currentNode = new Lockable<>(new SharedBufferNode(), 0); lockEvent(eventId); } currentNode.getElement().addEdge(new SharedBufferEdge( previousNodeId, version)); sharedBuffer.upsertEntry(currentNodeId, currentNode); return currentNodeId; }
Example #3
Source File: SharedBufferAccessor.java From flink with Apache License 2.0 | 6 votes |
/** * Stores given value (value + timestamp) under the given state. It assigns a preceding element * relation to the previous entry. * * @param stateName name of the state that the event should be assigned to * @param eventId unique id of event assigned by this SharedBuffer * @param previousNodeId id of previous entry (might be null if start of new run) * @param version Version of the previous relation * @return assigned id of this element */ public NodeId put( final String stateName, final EventId eventId, @Nullable final NodeId previousNodeId, final DeweyNumber version) { if (previousNodeId != null) { lockNode(previousNodeId); } NodeId currentNodeId = new NodeId(eventId, getOriginalNameFromInternal(stateName)); Lockable<SharedBufferNode> currentNode = sharedBuffer.getEntry(currentNodeId); if (currentNode == null) { currentNode = new Lockable<>(new SharedBufferNode(), 0); lockEvent(eventId); } currentNode.getElement().addEdge(new SharedBufferEdge( previousNodeId, version)); sharedBuffer.upsertEntry(currentNodeId, currentNode); return currentNodeId; }
Example #4
Source File: SharedBufferAccessor.java From flink with Apache License 2.0 | 5 votes |
ExtractionState( final Tuple2<NodeId, SharedBufferNode> entry, final DeweyNumber version, final Stack<Tuple2<NodeId, SharedBufferNode>> path) { this.entry = entry; this.version = version; this.path = path; }
Example #5
Source File: SharedBufferAccessor.java From flink with Apache License 2.0 | 5 votes |
ExtractionState( final Tuple2<NodeId, SharedBufferNode> entry, final DeweyNumber version, final Stack<Tuple2<NodeId, SharedBufferNode>> path) { this.entry = entry; this.version = version; this.path = path; }
Example #6
Source File: SharedBufferTest.java From flink with Apache License 2.0 | 5 votes |
/** * Test releasing a node which has a long path to the terminal node (the node without an out-going edge). * @throws Exception if creating the shared buffer accessor fails. */ @Test public void testReleaseNodesWithLongPath() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); final int numberEvents = 100000; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; NodeId[] nodeIds = new NodeId[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp); } try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { for (int i = 0; i < numberEvents; i++) { NodeId prevId = i == 0 ? null : nodeIds[i - 1]; nodeIds[i] = sharedBufferAccessor.put("n" + i, eventIds[i], prevId, DeweyNumber.fromString("1.0")); } NodeId lastNode = nodeIds[numberEvents - 1]; sharedBufferAccessor.releaseNode(lastNode); for (int i = 0; i < numberEvents; i++) { sharedBufferAccessor.releaseEvent(eventIds[i]); } } assertTrue(sharedBuffer.isEmpty()); }
Example #7
Source File: SharedBufferTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSharedBufferAccessor() throws Exception { TestSharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBufferAccessor.registerEvent(events[i], timestamp); } assertEquals(8, sharedBuffer.getEventsBufferCacheSize()); assertEquals(0, sharedBuffer.getSharedBufferNodeCacheSize()); NodeId start = sharedBufferAccessor.put("start", eventIds[1], null, DeweyNumber.fromString("1")); NodeId b0 = sharedBufferAccessor.put("branching", eventIds[2], start, DeweyNumber.fromString("1.0")); NodeId b1 = sharedBufferAccessor.put("branching", eventIds[3], start, DeweyNumber.fromString("1.1")); NodeId b00 = sharedBufferAccessor.put("branching", eventIds[3], b0, DeweyNumber.fromString("1.0.0")); sharedBufferAccessor.put("branching", eventIds[4], b00, DeweyNumber.fromString("1.0.0.0")); assertEquals(4, sharedBuffer.getSharedBufferNodeCacheSize()); assertEquals(0, sharedBuffer.getSharedBufferNodeSize()); sharedBufferAccessor.lockNode(b0); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } } assertEquals(0, sharedBuffer.getEventsBufferCacheSize()); assertEquals(4, sharedBuffer.getEventsBufferSize()); assertEquals(0, sharedBuffer.getSharedBufferNodeCacheSize()); assertEquals(4, sharedBuffer.getSharedBufferNodeSize()); }
Example #8
Source File: SharedBufferTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testClearingSharedBufferWithMultipleEdgesBetweenEntries() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp); } try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { NodeId start = sharedBufferAccessor.put("start", eventIds[1], null, DeweyNumber.fromString("1")); NodeId b0 = sharedBufferAccessor.put("branching", eventIds[2], start, DeweyNumber.fromString("1.0")); NodeId b1 = sharedBufferAccessor.put("branching", eventIds[3], start, DeweyNumber.fromString("1.1")); NodeId b00 = sharedBufferAccessor.put("branching", eventIds[3], b0, DeweyNumber.fromString("1.0.0")); sharedBufferAccessor.put("branching", eventIds[4], b00, DeweyNumber.fromString("1.0.0.0")); NodeId b10 = sharedBufferAccessor.put("branching", eventIds[4], b1, DeweyNumber.fromString("1.1.0")); //simulate IGNORE (next event can point to events[2]) sharedBufferAccessor.lockNode(b0); sharedBufferAccessor.releaseNode(b10); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } } //There should be still events[1] and events[2] in the buffer assertFalse(sharedBuffer.isEmpty()); }
Example #9
Source File: SharedBufferEdge.java From flink with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); if (nodeIdSerializer == null) { // the nested serializers will be null if this was read from a savepoint taken with versions // lower than Flink 1.7; in this case, we explicitly create instances for the nested serializers this.nodeIdSerializer = new NodeId.NodeIdSerializer(); this.deweyNumberSerializer = DeweyNumber.DeweyNumberSerializer.INSTANCE; } }
Example #10
Source File: SharedBufferEdge.java From flink with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); if (nodeIdSerializer == null) { // the nested serializers will be null if this was read from a savepoint taken with versions // lower than Flink 1.7; in this case, we explicitly create instances for the nested serializers this.nodeIdSerializer = new NodeId.NodeIdSerializer(); this.deweyNumberSerializer = DeweyNumber.DeweyNumberSerializer.INSTANCE; } }
Example #11
Source File: SharedBufferTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSharedBufferAccessor() throws Exception { TestSharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBufferAccessor.registerEvent(events[i], timestamp); } assertEquals(8, sharedBuffer.getEventsBufferCacheSize()); assertEquals(0, sharedBuffer.getSharedBufferNodeCacheSize()); NodeId start = sharedBufferAccessor.put("start", eventIds[1], null, DeweyNumber.fromString("1")); NodeId b0 = sharedBufferAccessor.put("branching", eventIds[2], start, DeweyNumber.fromString("1.0")); NodeId b1 = sharedBufferAccessor.put("branching", eventIds[3], start, DeweyNumber.fromString("1.1")); NodeId b00 = sharedBufferAccessor.put("branching", eventIds[3], b0, DeweyNumber.fromString("1.0.0")); sharedBufferAccessor.put("branching", eventIds[4], b00, DeweyNumber.fromString("1.0.0.0")); assertEquals(4, sharedBuffer.getSharedBufferNodeCacheSize()); assertEquals(0, sharedBuffer.getSharedBufferNodeSize()); sharedBufferAccessor.lockNode(b0); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } } assertEquals(0, sharedBuffer.getEventsBufferCacheSize()); assertEquals(4, sharedBuffer.getEventsBufferSize()); assertEquals(0, sharedBuffer.getSharedBufferNodeCacheSize()); assertEquals(4, sharedBuffer.getSharedBufferNodeSize()); }
Example #12
Source File: SharedBufferTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testClearingSharedBufferWithMultipleEdgesBetweenEntries() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp); } try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { NodeId start = sharedBufferAccessor.put("start", eventIds[1], null, DeweyNumber.fromString("1")); NodeId b0 = sharedBufferAccessor.put("branching", eventIds[2], start, DeweyNumber.fromString("1.0")); NodeId b1 = sharedBufferAccessor.put("branching", eventIds[3], start, DeweyNumber.fromString("1.1")); NodeId b00 = sharedBufferAccessor.put("branching", eventIds[3], b0, DeweyNumber.fromString("1.0.0")); sharedBufferAccessor.put("branching", eventIds[4], b00, DeweyNumber.fromString("1.0.0.0")); NodeId b10 = sharedBufferAccessor.put("branching", eventIds[4], b1, DeweyNumber.fromString("1.1.0")); //simulate IGNORE (next event can point to events[2]) sharedBufferAccessor.lockNode(b0); sharedBufferAccessor.releaseNode(b10); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } } //There should be still events[1] and events[2] in the buffer assertFalse(sharedBuffer.isEmpty()); }
Example #13
Source File: SharedBufferTest.java From flink with Apache License 2.0 | 5 votes |
/** * Test releasing a node which has a long path to the terminal node (the node without an out-going edge). * @throws Exception if creating the shared buffer accessor fails. */ @Test public void testReleaseNodesWithLongPath() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); final int numberEvents = 100000; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; NodeId[] nodeIds = new NodeId[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp); } try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { for (int i = 0; i < numberEvents; i++) { NodeId prevId = i == 0 ? null : nodeIds[i - 1]; nodeIds[i] = sharedBufferAccessor.put("n" + i, eventIds[i], prevId, DeweyNumber.fromString("1.0")); } NodeId lastNode = nodeIds[numberEvents - 1]; sharedBufferAccessor.releaseNode(lastNode); for (int i = 0; i < numberEvents; i++) { sharedBufferAccessor.releaseEvent(eventIds[i]); } } assertTrue(sharedBuffer.isEmpty()); }
Example #14
Source File: SharedBufferEdge.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); if (nodeIdSerializer == null) { // the nested serializers will be null if this was read from a savepoint taken with versions // lower than Flink 1.7; in this case, we explicitly create instances for the nested serializers this.nodeIdSerializer = new NodeId.NodeIdSerializer(); this.deweyNumberSerializer = DeweyNumber.DeweyNumberSerializer.INSTANCE; } }
Example #15
Source File: SharedBufferAccessor.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
ExtractionState( final Tuple2<NodeId, SharedBufferNode> entry, final DeweyNumber version, final Stack<Tuple2<NodeId, SharedBufferNode>> path) { this.entry = entry; this.version = version; this.path = path; }
Example #16
Source File: SharedBufferTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSharedBufferAccessor() throws Exception { TestSharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBufferAccessor.registerEvent(events[i], timestamp); } assertEquals(8, sharedBuffer.getEventsBufferCacheSize()); assertEquals(0, sharedBuffer.getSharedBufferNodeCacheSize()); NodeId start = sharedBufferAccessor.put("start", eventIds[1], null, DeweyNumber.fromString("1")); NodeId b0 = sharedBufferAccessor.put("branching", eventIds[2], start, DeweyNumber.fromString("1.0")); NodeId b1 = sharedBufferAccessor.put("branching", eventIds[3], start, DeweyNumber.fromString("1.1")); NodeId b00 = sharedBufferAccessor.put("branching", eventIds[3], b0, DeweyNumber.fromString("1.0.0")); sharedBufferAccessor.put("branching", eventIds[4], b00, DeweyNumber.fromString("1.0.0.0")); assertEquals(4, sharedBuffer.getSharedBufferNodeCacheSize()); assertEquals(0, sharedBuffer.getSharedBufferNodeSize()); sharedBufferAccessor.lockNode(b0); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } } assertEquals(0, sharedBuffer.getEventsBufferCacheSize()); assertEquals(4, sharedBuffer.getEventsBufferSize()); assertEquals(0, sharedBuffer.getSharedBufferNodeCacheSize()); assertEquals(4, sharedBuffer.getSharedBufferNodeSize()); }
Example #17
Source File: SharedBufferTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testClearingSharedBufferWithMultipleEdgesBetweenEntries() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp); } try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { NodeId start = sharedBufferAccessor.put("start", eventIds[1], null, DeweyNumber.fromString("1")); NodeId b0 = sharedBufferAccessor.put("branching", eventIds[2], start, DeweyNumber.fromString("1.0")); NodeId b1 = sharedBufferAccessor.put("branching", eventIds[3], start, DeweyNumber.fromString("1.1")); NodeId b00 = sharedBufferAccessor.put("branching", eventIds[3], b0, DeweyNumber.fromString("1.0.0")); sharedBufferAccessor.put("branching", eventIds[4], b00, DeweyNumber.fromString("1.0.0.0")); NodeId b10 = sharedBufferAccessor.put("branching", eventIds[4], b1, DeweyNumber.fromString("1.1.0")); //simulate IGNORE (next event can point to events[2]) sharedBufferAccessor.lockNode(b0); sharedBufferAccessor.releaseNode(b10); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } } //There should be still events[1] and events[2] in the buffer assertFalse(sharedBuffer.isEmpty()); }
Example #18
Source File: NFASerializerUpgradeTest.java From flink with Apache License 2.0 | 5 votes |
@Override public SharedBufferNode createTestData() { SharedBufferNode result = new SharedBufferNode(); result.addEdge(new SharedBufferEdge( new NodeId(new EventId(42, 42L), "page"), new DeweyNumber(42))); return result; }
Example #19
Source File: NFASerializerUpgradeTest.java From flink with Apache License 2.0 | 5 votes |
@Override public Matcher<SharedBufferNode> testDataMatcher() { SharedBufferNode result = new SharedBufferNode(); result.addEdge(new SharedBufferEdge( new NodeId(new EventId(42, 42L), "page"), new DeweyNumber(42))); return is(result); }
Example #20
Source File: SharedBufferEdge.java From flink with Apache License 2.0 | 4 votes |
@Override public SharedBufferEdge deserialize(DataInputView source) throws IOException { NodeId target = nodeIdSerializer.deserialize(source); DeweyNumber deweyNumber = deweyNumberSerializer.deserialize(source); return new SharedBufferEdge(target, deweyNumber); }
Example #21
Source File: SharedBufferEdge.java From flink with Apache License 2.0 | 4 votes |
DeweyNumber getDeweyNumber() { return deweyNumber; }
Example #22
Source File: SharedBufferTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testSharedBufferExtractOrder() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 5; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp); } Map<String, List<Event>> expectedResult = new LinkedHashMap<>(); expectedResult.put("a", new ArrayList<>()); expectedResult.get("a").add(events[0]); expectedResult.put("b", new ArrayList<>()); expectedResult.get("b").add(events[1]); expectedResult.put("aa", new ArrayList<>()); expectedResult.get("aa").add(events[2]); expectedResult.put("bb", new ArrayList<>()); expectedResult.get("bb").add(events[3]); expectedResult.put("c", new ArrayList<>()); expectedResult.get("c").add(events[4]); try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { NodeId a = sharedBufferAccessor.put("a", eventIds[0], null, DeweyNumber.fromString("1")); NodeId b = sharedBufferAccessor.put("b", eventIds[1], a, DeweyNumber.fromString("1.0")); NodeId aa = sharedBufferAccessor.put("aa", eventIds[2], b, DeweyNumber.fromString("1.0.0")); NodeId bb = sharedBufferAccessor.put("bb", eventIds[3], aa, DeweyNumber.fromString("1.0.0.0")); NodeId c = sharedBufferAccessor.put("c", eventIds[4], bb, DeweyNumber.fromString("1.0.0.0.0")); Map<String, List<Event>> patternsResult = sharedBufferAccessor.materializeMatch(sharedBufferAccessor.extractPatterns(c, DeweyNumber.fromString("1.0.0.0.0")).get(0)); List<String> expectedOrder = new ArrayList<>(); expectedOrder.add("a"); expectedOrder.add("b"); expectedOrder.add("aa"); expectedOrder.add("bb"); expectedOrder.add("c"); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } List<String> resultOrder = new ArrayList<>(patternsResult.keySet()); assertEquals(expectedOrder, resultOrder); } }
Example #23
Source File: SharedBufferTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testSharedBuffer() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp); } Map<String, List<Event>> expectedPattern1 = new HashMap<>(); expectedPattern1.put("a1", new ArrayList<>()); expectedPattern1.get("a1").add(events[2]); expectedPattern1.put("a[]", new ArrayList<>()); expectedPattern1.get("a[]").add(events[3]); expectedPattern1.put("b", new ArrayList<>()); expectedPattern1.get("b").add(events[5]); Map<String, List<Event>> expectedPattern2 = new HashMap<>(); expectedPattern2.put("a1", new ArrayList<>()); expectedPattern2.get("a1").add(events[0]); expectedPattern2.put("a[]", new ArrayList<>()); expectedPattern2.get("a[]").add(events[1]); expectedPattern2.get("a[]").add(events[2]); expectedPattern2.get("a[]").add(events[3]); expectedPattern2.get("a[]").add(events[4]); expectedPattern2.put("b", new ArrayList<>()); expectedPattern2.get("b").add(events[5]); Map<String, List<Event>> expectedPattern3 = new HashMap<>(); expectedPattern3.put("a1", new ArrayList<>()); expectedPattern3.get("a1").add(events[0]); expectedPattern3.put("a[]", new ArrayList<>()); expectedPattern3.get("a[]").add(events[1]); expectedPattern3.get("a[]").add(events[2]); expectedPattern3.get("a[]").add(events[3]); expectedPattern3.get("a[]").add(events[4]); expectedPattern3.get("a[]").add(events[5]); expectedPattern3.get("a[]").add(events[6]); expectedPattern3.put("b", new ArrayList<>()); expectedPattern3.get("b").add(events[7]); try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { NodeId a10 = sharedBufferAccessor.put("a1", eventIds[0], null, DeweyNumber.fromString("1")); NodeId aLoop0 = sharedBufferAccessor.put("a[]", eventIds[1], a10, DeweyNumber.fromString("1.0")); NodeId a11 = sharedBufferAccessor.put("a1", eventIds[2], null, DeweyNumber.fromString("2")); NodeId aLoop1 = sharedBufferAccessor.put("a[]", eventIds[2], aLoop0, DeweyNumber.fromString("1.0")); NodeId aLoop2 = sharedBufferAccessor.put("a[]", eventIds[3], aLoop1, DeweyNumber.fromString("1.0")); NodeId aSecondLoop0 = sharedBufferAccessor.put("a[]", eventIds[3], a11, DeweyNumber.fromString("2.0")); NodeId aLoop3 = sharedBufferAccessor.put("a[]", eventIds[4], aLoop2, DeweyNumber.fromString("1.0")); NodeId b0 = sharedBufferAccessor.put("b", eventIds[5], aLoop3, DeweyNumber.fromString("1.0.0")); NodeId aLoop4 = sharedBufferAccessor.put("a[]", eventIds[5], aLoop3, DeweyNumber.fromString("1.1")); NodeId b1 = sharedBufferAccessor.put("b", eventIds[5], aSecondLoop0, DeweyNumber.fromString("2.0.0")); NodeId aLoop5 = sharedBufferAccessor.put("a[]", eventIds[6], aLoop4, DeweyNumber.fromString("1.1")); NodeId b3 = sharedBufferAccessor.put("b", eventIds[7], aLoop5, DeweyNumber.fromString("1.1.0")); List<Map<String, List<EventId>>> patterns3 = sharedBufferAccessor.extractPatterns(b3, DeweyNumber.fromString("1.1.0")); assertEquals(1L, patterns3.size()); assertEquals(expectedPattern3, sharedBufferAccessor.materializeMatch(patterns3.get(0))); sharedBufferAccessor.releaseNode(b3); List<Map<String, List<EventId>>> patterns4 = sharedBufferAccessor.extractPatterns(b3, DeweyNumber.fromString("1.1.0")); assertEquals(0L, patterns4.size()); assertTrue(patterns4.isEmpty()); List<Map<String, List<EventId>>> patterns1 = sharedBufferAccessor.extractPatterns(b1, DeweyNumber.fromString("2.0.0")); assertEquals(1L, patterns1.size()); assertEquals(expectedPattern1, sharedBufferAccessor.materializeMatch(patterns1.get(0))); List<Map<String, List<EventId>>> patterns2 = sharedBufferAccessor.extractPatterns(b0, DeweyNumber.fromString("1.0.0")); assertEquals(1L, patterns2.size()); assertEquals(expectedPattern2, sharedBufferAccessor.materializeMatch(patterns2.get(0))); sharedBufferAccessor.releaseNode(b1); sharedBufferAccessor.releaseNode(b0); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } } assertTrue(sharedBuffer.isEmpty()); }
Example #24
Source File: SharedBufferEdge.java From flink with Apache License 2.0 | 4 votes |
public SharedBufferEdgeSerializer() { this(new NodeId.NodeIdSerializer(), DeweyNumber.DeweyNumberSerializer.INSTANCE); }
Example #25
Source File: SharedBufferEdge.java From flink with Apache License 2.0 | 4 votes |
private SharedBufferEdgeSerializer( TypeSerializer<NodeId> nodeIdSerializer, TypeSerializer<DeweyNumber> deweyNumberSerializer) { this.nodeIdSerializer = checkNotNull(nodeIdSerializer); this.deweyNumberSerializer = checkNotNull(deweyNumberSerializer); }
Example #26
Source File: NFASerializerUpgradeTest.java From flink with Apache License 2.0 | 4 votes |
@Override public SharedBufferEdge createTestData() { return new SharedBufferEdge( new NodeId(new EventId(42, 42L), "page"), new DeweyNumber(42)); }
Example #27
Source File: SharedBufferEdge.java From flink with Apache License 2.0 | 4 votes |
@Override protected SharedBufferEdgeSerializer createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) { return new SharedBufferEdgeSerializer( (NodeId.NodeIdSerializer) nestedSerializers[0], (DeweyNumber.DeweyNumberSerializer) nestedSerializers[1]); }
Example #28
Source File: NFASerializerUpgradeTest.java From flink with Apache License 2.0 | 4 votes |
@Override public TypeSerializer<DeweyNumber> createPriorSerializer() { return DeweyNumber.DeweyNumberSerializer.INSTANCE; }
Example #29
Source File: NFASerializerUpgradeTest.java From flink with Apache License 2.0 | 4 votes |
@Override public DeweyNumber createTestData() { return new DeweyNumber(42); }
Example #30
Source File: NFASerializerUpgradeTest.java From flink with Apache License 2.0 | 4 votes |
@Override public TypeSerializer<DeweyNumber> createUpgradedSerializer() { return DeweyNumber.DeweyNumberSerializer.INSTANCE; }