use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class JoinTestCase method joinTest3.
@Test
public void joinTest3() throws InterruptedException {
log.info("Join test3");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(500 milliseconds) as a " + "join cseEventStream#window.time(500 milliseconds) as b " + "on a.symbol== b.symbol " + "select a.symbol as symbol, a.price as priceA, b.price as priceB " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount.addAndGet(inEvents.length);
}
if (removeEvents != null) {
removeEventCount.getAndAdd(removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
SiddhiTestHelper.waitForEvents(100, 2, removeEventCount, 60000);
AssertJUnit.assertEquals(2, inEventCount.get());
AssertJUnit.assertEquals(2, removeEventCount.get());
AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class JoinTestCase method joinTest14.
@Test
public void joinTest14() throws InterruptedException {
log.info("Join test14");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream order (billnum string, custid string, items string, dow string, timestamp long); " + "define table dow_items (custid string, dow string, item string) ; " + "define stream dow_items_stream (custid string, dow string, item string); ";
String query = "" + "@info(name = 'query1') " + "from order join dow_items \n" + "on order.custid == dow_items.custid \n" + "select dow_items.item\n" + "having order.items == \"item1\" \n" + "insert into recommendationStream ;" + "@info(name = 'query2') " + "from dow_items_stream " + "insert into dow_items ;" + "" + "";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
InputHandler orderStream = siddhiAppRuntime.getInputHandler("order");
InputHandler itemsStream = siddhiAppRuntime.getInputHandler("dow_items_stream");
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
}
});
siddhiAppRuntime.start();
Thread.sleep(100);
itemsStream.send(new Object[] { "cust1", "bill1", "item1" });
orderStream.send(new Object[] { "bill1", "cust1", "item1", "dow1", 12323232L });
Thread.sleep(100);
AssertJUnit.assertEquals("Event Arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class JoinTestCase method joinTest17.
@Test
public void joinTest17() throws InterruptedException {
log.info("Join test17");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream order (billnum string, custid string, items string, dow string, timestamp long); " + "define table dow_items (custid string, dow string, item string) ; " + "define stream dow_items_stream (custid string, dow string, item string); ";
String query = "" + "@info(name = 'query1') " + "from order join dow_items \n" + "select dow_items.custid\n" + "having order.items == \"item1\" \n" + "insert into recommendationStream ;" + "@info(name = 'query2') " + "from dow_items_stream " + "insert into dow_items ;" + "" + "";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
InputHandler orderStream = siddhiAppRuntime.getInputHandler("order");
InputHandler itemsStream = siddhiAppRuntime.getInputHandler("dow_items_stream");
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
}
});
siddhiAppRuntime.start();
Thread.sleep(100);
itemsStream.send(new Object[] { "cust1", "bill1", "item1" });
orderStream.send(new Object[] { "bill1", "cust1", "item1", "dow1", 12323232L });
Thread.sleep(100);
AssertJUnit.assertEquals("Event Arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class JoinTestCase method joinTest9.
@Test
public void joinTest9() throws InterruptedException {
log.info("Join test9");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); ";
String query = "" + "@info(name = 'query1') " + "from cseEventStream join twitterStream " + "select count() as events, symbol " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "WSO2", 55.6f, 100 });
cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(500);
AssertJUnit.assertFalse(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class JoinTestCase method joinTest10.
@Test
public void joinTest10() throws InterruptedException {
log.info("Join test10");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); ";
String query = "" + "@info(name = 'query1') " + "from cseEventStream join twitterStream#window.length(1) " + "select count() as events, symbol " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount.getAndAdd(inEvents.length);
}
if (removeEvents != null) {
removeEventCount.getAndAdd(removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", 55.6f, 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
AssertJUnit.assertEquals("inEventCount", 2, inEventCount.get());
AssertJUnit.assertEquals("removeEventCount", 0, removeEventCount.get());
AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
Aggregations