aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-11-08 00:55:32 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-11-08 00:55:32 +0100
commitbddca73748f7eace28cdd76282fcfd33971e9995 (patch)
tree91b0e37362bb46b27ba3b34bdf751ac12fb808f6
downloadesper-testing-bddca73748f7eace28cdd76282fcfd33971e9995.tar.gz
esper-testing-bddca73748f7eace28cdd76282fcfd33971e9995.tar.bz2
esper-testing-bddca73748f7eace28cdd76282fcfd33971e9995.tar.xz
esper-testing-bddca73748f7eace28cdd76282fcfd33971e9995.zip
wip
-rw-r--r--.gitignore3
-rw-r--r--pom.xml23
-rw-r--r--src/main/java/io/trygvis/esper/testing/AtomImporter.java18
-rw-r--r--src/main/java/io/trygvis/esper/testing/DbMain.java33
-rw-r--r--src/main/java/io/trygvis/esper/testing/Main.java83
5 files changed, 160 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..612c5bc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+target
+.idea
+*.iml
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..6340300
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,23 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>io.trygvis.esper.testing</groupId>
+ <artifactId>esper-testing</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>com.espertech</groupId>
+ <artifactId>esper</artifactId>
+ <version>4.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.3.168</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-client</artifactId>
+ <version>1.1.2</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/main/java/io/trygvis/esper/testing/AtomImporter.java b/src/main/java/io/trygvis/esper/testing/AtomImporter.java
new file mode 100644
index 0000000..7e70715
--- /dev/null
+++ b/src/main/java/io/trygvis/esper/testing/AtomImporter.java
@@ -0,0 +1,18 @@
+package io.trygvis.esper.testing;
+
+import org.apache.abdera.*;
+import org.apache.abdera.protocol.client.*;
+import org.apache.abdera.protocol.client.cache.*;
+
+public class AtomImporter {
+ public static void main(String[] args) {
+ Abdera abdera = new Abdera();
+ AbderaClient abderaClient = new AbderaClient(abdera, new LRUCache(abdera, 1000));
+
+ while(true) {
+ ClientResponse response = abderaClient.get("http://gitorious.org/qt.atom");
+
+// response.
+ }
+ }
+}
diff --git a/src/main/java/io/trygvis/esper/testing/DbMain.java b/src/main/java/io/trygvis/esper/testing/DbMain.java
new file mode 100644
index 0000000..635e3cc
--- /dev/null
+++ b/src/main/java/io/trygvis/esper/testing/DbMain.java
@@ -0,0 +1,33 @@
+package io.trygvis.esper.testing;
+
+import org.h2.tools.*;
+
+import java.sql.*;
+
+public class DbMain {
+ private static final String JDBC_URL = "jdbc:h2:mem:esper;DB_CLOSE_DELAY=-1";
+
+ public static void main(String[] args) throws Exception {
+ Server server = Server.createTcpServer(args).start();
+
+ System.out.println("server.getURL() = " + server.getURL());
+
+ Connection connection = DriverManager.getConnection(JDBC_URL, "", "");
+ connection.setAutoCommit(false);
+ Statement s = connection.createStatement();
+ s.execute("create table subscription(" +
+ "itemName varchar(100) not null," +
+ "subscriber varchar(100) not null" +
+ ");");
+
+ s.execute("insert into subscription values('shirt', 'sub a');");
+ s.execute("insert into subscription values('shirt', 'sub b');");
+ s.execute("insert into subscription values('pants', 'sub b');");
+ s.execute("insert into subscription values('pants', 'sub c');");
+ connection.commit();
+
+ while(true) {
+ Thread.sleep(1000);
+ }
+ }
+}
diff --git a/src/main/java/io/trygvis/esper/testing/Main.java b/src/main/java/io/trygvis/esper/testing/Main.java
new file mode 100644
index 0000000..25b3fad
--- /dev/null
+++ b/src/main/java/io/trygvis/esper/testing/Main.java
@@ -0,0 +1,83 @@
+package io.trygvis.esper.testing;
+
+import com.espertech.esper.client.*;
+import org.apache.log4j.*;
+
+import java.util.*;
+
+public class Main {
+// private static final String JDBC_URL = "jdbc:h2:mem:esper;DB_CLOSE_DELAY=-1";
+ private static final String JDBC_URL = "jdbc:h2:tcp://127.0.0.1/esper;DB_CLOSE_DELAY=-1";
+
+ public Main() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty("log4j.rootLogger", "DEBUG, A1");
+ properties.setProperty("log4j.appender.A1", "org.apache.log4j.ConsoleAppender");
+ properties.setProperty("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout");
+ properties.setProperty("log4j.appender.A1.layout.ConversionPattern", "%-4r [%t] %-5p %c %x - %m%n");
+ PropertyConfigurator.configure(properties);
+ }
+
+ public static void main(String[] args) throws Exception {
+ Main main = new Main();
+ main.work();
+ }
+
+ private void work() throws Exception {
+ Configuration config = new Configuration();
+
+ ConfigurationDBRef configurationDBRef = new ConfigurationDBRef();
+ configurationDBRef.setDriverManagerConnection("org.h2.Driver", JDBC_URL, "", "");
+ configurationDBRef.setConnectionAutoCommit(false);
+ config.addDatabaseReference("db1", configurationDBRef);
+ config.addEventTypeAutoName(getClass().getPackage().getName());
+ EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config);
+
+// String expression = "select avg(price) from OrderEvent.win:time(30 sec)";
+
+ String expression = "select price, SUBSCRIBER from OrderEvent.win:time(30 sec)," +
+ "sql:db1 ['select subscriber from subscription where itemName=${itemName}']";
+
+ EPStatement statement = epService.getEPAdministrator().createEPL(expression);
+
+ MyListener listener = new MyListener();
+ statement.addListener(listener);
+
+ System.out.println("Inserting events");
+ epService.getEPRuntime().sendEvent(new OrderEvent("shirt", 72));
+ epService.getEPRuntime().sendEvent(new OrderEvent("shirt", 73));
+ epService.getEPRuntime().sendEvent(new OrderEvent("shirt", 74));
+
+ System.out.println("Sleeping");
+ Thread.sleep(1000);
+ System.out.println("Done..");
+ }
+}
+
+class OrderEvent {
+ private String itemName;
+ private double price;
+
+ public OrderEvent(String itemName, double price) {
+ this.itemName = itemName;
+ this.price = price;
+ }
+
+ public String getItemName() {
+ return itemName;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+}
+
+class MyListener implements UpdateListener {
+ public void update(EventBean[] newEvents, EventBean[] oldEvents) {
+ for (EventBean event : newEvents) {
+ System.out.println("event.getEventType() = " + event.getEventType());
+ System.out.println("event.getUnderlying() = " + event.getUnderlying());
+ System.out.println("avg=" + event.get("price"));
+ }
+ }
+}