use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class LogicalPatternTestCase method testQuery7.
@Test
public void testQuery7() throws InterruptedException {
log.info("testPatternLogical7 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price > 20] and e2=Stream2[price >30] -> e3=Stream2['IBM' == symbol] " + "select e1.symbol as symbol1, e2.price as price2, e3.price as price3 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 72.7f, 4.7f }, inEvents[0].getData());
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "GOOG", 72.7f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 4.7f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class LogicalPatternTestCase method testQuery1.
@Test
public void testQuery1() throws InterruptedException {
log.info("testPatternLogical1 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price > 20] -> e2=Stream2[price > e1.price] or e3=Stream2['IBM' == symbol] " + "select e1.symbol as symbol1, e2.symbol as symbol2 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "GOOG" }, inEvents[0].getData());
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "GOOG", 59.6f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class WithinPatternTestCase method testQuery2.
@Test
public void testQuery2() throws InterruptedException {
log.info("testPatternWithin2 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from (every e1=Stream1[price>20]-> e2=Stream2[price>e1.price]) " + "within 1 sec " + "select e1.symbol as symbol1, e2.symbol as symbol2 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
AssertJUnit.assertArrayEquals(new Object[] { "GOOG", "IBM" }, inEvents[0].getData());
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(1500);
stream1.send(new Object[] { "GOOG", 54f, 100 });
Thread.sleep(500);
stream2.send(new Object[] { "IBM", 55.7f, 100 });
Thread.sleep(500);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class WithinPatternTestCase method testQuery3.
@Test
public void testQuery3() throws InterruptedException {
log.info("testPatternWithin3 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from (every (e1=Stream1[price>20] -> e3=Stream1[price>20]) -> e2=Stream2[price>e1.price]) " + "within 2 sec " + "select e1.price as price1, e3.price as price3, e2.price as price2 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
AssertJUnit.assertArrayEquals(new Object[] { 53.6f, 53f, 57.7f }, inEvents[0].getData());
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(600);
stream1.send(new Object[] { "GOOG", 54f, 100 });
Thread.sleep(600);
stream1.send(new Object[] { "WSO2", 53.6f, 100 });
Thread.sleep(900);
stream1.send(new Object[] { "GOOG", 53f, 100 });
Thread.sleep(600);
stream2.send(new Object[] { "IBM", 57.7f, 100 });
Thread.sleep(600);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class WithinPatternTestCase method testQuery7.
@Test
public void testQuery7() throws InterruptedException {
log.info("testPatternWithin5 - OUT 1 : Within clause for grouped pattern states(3)");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from every (e1=Stream1 -> e2=Stream1[symbol == e1.symbol] -> e3=Stream1[symbol == e2.symbol]) " + "within 5 sec " + " select e1.symbol as symbol1, e1.volume as volume1, e2.symbol as symbol2, e2.volume as volume2, " + " e3.symbol as symbol3, e3.volume as volume3" + " insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 150, "WSO2", 200, "WSO2", 250 }, inEvents[0].getData());
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(6000);
stream1.send(new Object[] { "WSO2", 56.6f, 150 });
stream1.send(new Object[] { "WSO2", 57.7f, 200 });
Thread.sleep(500);
stream1.send(new Object[] { "WSO2", 58.7f, 250 });
stream1.send(new Object[] { "WSO2", 57.7f, 300 });
stream1.send(new Object[] { "WSO2", 59.7f, 350 });
Thread.sleep(500);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations