forked from phil3k3/flink-esper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
distinguish between esper pattern and query. cleanup tests. move stat…
…e change pattern tests to test project
- Loading branch information
phil3k
committed
Jan 14, 2018
1 parent
3a5f759
commit 81c1292
Showing
16 changed files
with
253 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
flink-esper-test/src/test/java/at/datasciencelabs/test/BuildEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package at.datasciencelabs.test; | ||
|
||
|
||
interface BuildEvent { | ||
} |
2 changes: 1 addition & 1 deletion
2
...java/at/datasciencelabs/BuildFailure.java → ...at/datasciencelabs/test/BuildFailure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package at.datasciencelabs; | ||
package at.datasciencelabs.test; | ||
|
||
public class BuildFailure implements BuildEvent { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...java/at/datasciencelabs/BuildSuccess.java → ...at/datasciencelabs/test/BuildSuccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package at.datasciencelabs; | ||
package at.datasciencelabs.test; | ||
|
||
public class BuildSuccess implements BuildEvent { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...tasciencelabs/StateChangePatternTest.java → ...encelabs/test/StateChangePatternTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
flink-esper/src/main/java/at/datasciencelabs/EsperPattern.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package at.datasciencelabs; | ||
|
||
import com.espertech.esper.client.EPAdministrator; | ||
import com.espertech.esper.client.EPStatement; | ||
|
||
class EsperPattern implements EsperStatementFactory { | ||
|
||
private String pattern; | ||
|
||
EsperPattern(String pattern) { | ||
this.pattern = pattern; | ||
} | ||
|
||
@Override | ||
public EPStatement createStatement(EPAdministrator administrator) { | ||
return administrator.createPattern(pattern); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
flink-esper/src/main/java/at/datasciencelabs/EsperQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package at.datasciencelabs; | ||
|
||
import com.espertech.esper.client.EPAdministrator; | ||
import com.espertech.esper.client.EPStatement; | ||
|
||
class EsperQuery implements EsperStatementFactory { | ||
|
||
private String query; | ||
|
||
EsperQuery(String query) { | ||
this.query = query; | ||
} | ||
|
||
|
||
@Override | ||
public EPStatement createStatement(EPAdministrator administrator) { | ||
return administrator.createEPL(query); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
flink-esper/src/main/java/at/datasciencelabs/EsperStatementFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package at.datasciencelabs; | ||
|
||
import com.espertech.esper.client.EPAdministrator; | ||
import com.espertech.esper.client.EPStatement; | ||
|
||
import java.io.Serializable; | ||
|
||
interface EsperStatementFactory extends Serializable { | ||
EPStatement createStatement(EPAdministrator administrator); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
138 changes: 138 additions & 0 deletions
138
flink-esper/src/test/java/at/datasciencelabs/EsperPatternTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package at.datasciencelabs; | ||
|
||
import com.espertech.esper.client.EventBean; | ||
import com.google.common.collect.Lists; | ||
import org.apache.flink.streaming.api.datastream.DataStream; | ||
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; | ||
import org.apache.flink.streaming.api.functions.sink.SinkFunction; | ||
import org.apache.flink.streaming.util.StreamingMultipleProgramsTestBase; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.Serializable; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.Is.is; | ||
|
||
public class EsperPatternTest extends StreamingMultipleProgramsTestBase implements Serializable { | ||
|
||
|
||
private static List<ComplexEvent> resultingEvents; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
resultingEvents = Lists.newArrayList(); | ||
} | ||
|
||
@Test | ||
public void testEsperPattern() throws Exception { | ||
StreamExecutionEnvironment executionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment(); | ||
executionEnvironment.setParallelism(1); | ||
|
||
List<ComplexEvent> expectedValues = Lists.newArrayList(); | ||
ComplexEvent complexEvent = new ComplexEvent(Event.start(), Event.end()); | ||
expectedValues.add(complexEvent); | ||
|
||
List<Event> events = Arrays.asList(complexEvent.getStartEvent(), complexEvent.getEndEvent()); | ||
DataStream<Event> dataStream = executionEnvironment.fromCollection(events); | ||
|
||
EsperStream<Event> esperStream = Esper.pattern(dataStream, "every (A=Event(type='start') -> B=Event(type='end'))"); | ||
|
||
DataStream<ComplexEvent> complexEventDataStream = esperStream.select(new EsperSelectFunction<ComplexEvent>() { | ||
@Override | ||
public ComplexEvent select(EventBean eventBean) throws Exception { | ||
return new ComplexEvent((Event) eventBean.get("A"), (Event) eventBean.get("B")); | ||
} | ||
}); | ||
|
||
complexEventDataStream.addSink(new SinkFunction<ComplexEvent>() { | ||
@Override | ||
public void invoke(ComplexEvent value) throws Exception { | ||
System.err.println(value); | ||
resultingEvents.add(value); | ||
} | ||
}); | ||
|
||
executionEnvironment.execute("test-2"); | ||
|
||
assertThat(resultingEvents, is(expectedValues)); | ||
} | ||
|
||
private static class ComplexEvent { | ||
private Event startEvent; | ||
private Event endEvent; | ||
|
||
ComplexEvent(Event startEvent, Event endEvent) { | ||
this.startEvent = startEvent; | ||
this.endEvent = endEvent; | ||
} | ||
|
||
Event getStartEvent() { | ||
return startEvent; | ||
} | ||
|
||
Event getEndEvent() { | ||
return endEvent; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
ComplexEvent that = (ComplexEvent) o; | ||
|
||
if (startEvent != null ? !startEvent.equals(that.startEvent) : that.startEvent != null) return false; | ||
return endEvent != null ? endEvent.equals(that.endEvent) : that.endEvent == null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = startEvent != null ? startEvent.hashCode() : 0; | ||
result = 31 * result + (endEvent != null ? endEvent.hashCode() : 0); | ||
return result; | ||
} | ||
} | ||
|
||
public static class Event { | ||
|
||
private String type; | ||
|
||
private Event(String type) { | ||
this.type = type; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
static Event start() { | ||
return new Event("start"); | ||
} | ||
|
||
static Event end() { | ||
return new Event("end"); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Event event = (Event) o; | ||
|
||
return type != null ? type.equals(event.type) : event.type == null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return type != null ? type.hashCode() : 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters