use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalPatternTestCase method testQuery6.
@Test
public void testQuery6() throws InterruptedException {
log.info("testPatternLogical6 - 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] and e3=Stream1['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, 75.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[] { "IBM", 72.7f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "IBM", 75.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 org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalPatternTestCase method testQuery15.
@Test
public void testQuery15() throws InterruptedException {
log.info("testQuery15 - OUT 2");
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] and e2=Stream2[price >30]) " + "select e1.symbol as symbol1, 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;
eventArrived = true;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 35.0f }, inEvents[0].getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "GOOGLE", 55.0f }, inEvents[0].getData());
}
}
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", 25.0f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 35.0f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "GOOGLE", 45.0f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "ORACLE", 55.0f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class AbsentPatternTestCase method testQueryAbsent23.
@Test(dependsOnMethods = { "testQueryAbsent22" })
public void testQueryAbsent23() throws InterruptedException {
log.info("Test the query not e1 for 1 sec -> e2 -> e3-> e4 with e1, e2, e3, and e4");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); " + "define stream Stream4 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from not Stream1[price>10] for 1 sec -> e2=Stream2[price>20] -> e3=Stream3[price>30] -> " + "e4=Stream4[price>40] " + "select e2.symbol as symbol2, e3.symbol as symbol3, e4.symbol as symbol4 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
InputHandler stream4 = siddhiAppRuntime.getInputHandler("Stream4");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 15.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 28.7f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 38.7f, 100 });
Thread.sleep(100);
stream4.send(new Object[] { "ORACLE", 44.7f, 100 });
Thread.sleep(100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class AbsentPatternTestCase method testQueryAbsent26.
@Test(dependsOnMethods = { "testQueryAbsent25" })
public void testQueryAbsent26() throws InterruptedException {
log.info("Test the query not e1 for 1 sec -> e2 -> not e3 for 1 sec-> e4 with e2, e3 and e4");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); " + "define stream Stream4 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from not Stream1[price>10] for 1 sec -> e2=Stream2[price>20] -> not Stream3[price>30] for 1 " + "sec -> e4=Stream4[price>40] " + "select e2.symbol as symbol2, e4.symbol as symbol4 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
InputHandler stream4 = siddhiAppRuntime.getInputHandler("Stream4");
siddhiAppRuntime.start();
stream2.send(new Object[] { "IBM", 28.7f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 38.7f, 100 });
Thread.sleep(100);
stream4.send(new Object[] { "ORACLE", 44.7f, 100 });
Thread.sleep(100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class AbsentPatternTestCase method testQueryAbsent28.
@Test(dependsOnMethods = { "testQueryAbsent27" })
public void testQueryAbsent28() throws InterruptedException {
log.info("Test the query e1 -> not e2 for 1 sec -> e3 and e4 without e2");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); " + "define stream Stream4 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> not Stream2[price>20] for 1 sec -> e2=Stream3[price>30] and " + "e3=Stream4[price>40]" + "select e1.symbol as symbol1, e2.symbol as symbol2, e3.symbol as symbol3 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[] { "IBM", "WSO2", "GOOGLE" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
InputHandler stream4 = siddhiAppRuntime.getInputHandler("Stream4");
siddhiAppRuntime.start();
stream1.send(new Object[] { "IBM", 18.7f, 100 });
Thread.sleep(1100);
stream3.send(new Object[] { "WSO2", 35.0f, 100 });
Thread.sleep(100);
stream4.send(new Object[] { "GOOGLE", 56.86f, 100 });
Thread.sleep(100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertTrue("Event not arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
Aggregations