use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent52.
@Test(dependsOnMethods = { "testQueryAbsent51" })
public void testQueryAbsent52() throws InterruptedException {
log.info("Test the query every (not e1 for 1 sec or e2) -> e3 with e1, e3 and e2, e3");
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); ";
String query = "" + "@info(name = 'query1') " + "from every (not Stream1[price>10] for 1 sec or e2=Stream2[price>20]) -> " + "e3=Stream3[price>30] " + "select 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[] { "MICROSOFT", "IBM" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
Thread.sleep(500);
stream1.send(new Object[] { "ORACLE", 15.0f, 100 });
Thread.sleep(600);
stream3.send(new Object[] { "WSO2", 35.0f, 100 });
Thread.sleep(300);
stream2.send(new Object[] { "MICROSOFT", 45.0f, 100 });
Thread.sleep(800);
stream3.send(new Object[] { "IBM", 55.0f, 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 arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent51.
@Test(dependsOnMethods = { "testQueryAbsent50" })
public void testQueryAbsent51() throws InterruptedException {
log.info("Test the query e1 and not e2 for 1 sec -> e3 with e2 and e3 after 1 sec");
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); ";
String query = "" + "@info(name = 'query1') " + "from every (e1=Stream1[price>10] and not Stream2[price>20] for 1 sec) -> " + "e3=Stream3[price>30] " + "select e1.symbol as symbol1, e3.symbol as symbol3 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[] { "IBM", "GOOGLE" }, new Object[] { "ORACLE", "MICROSOFT" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
Thread.sleep(1100);
stream1.send(new Object[] { "IBM", 25.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 35.0f, 100 });
Thread.sleep(1100);
stream1.send(new Object[] { "ORACLE", 45.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "MICROSOFT", 55.0f, 100 });
Thread.sleep(100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 2, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent5_2.
@Test(dependsOnMethods = { "testQueryAbsent5_1" })
public void testQueryAbsent5_2() throws InterruptedException {
log.info("Test the query e1 -> not e2 for 1 sec and e3 with e1 and e3 after 1 sec");
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); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> not Stream2[price>20] for 1 sec and e3=Stream3[price>30] " + "select e1.symbol as symbol1, e3.symbol as symbol3 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
Thread.sleep(1100);
stream1.send(new Object[] { "WSO2", 15.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 35.0f, 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 LogicalAbsentPatternTestCase method testQueryAbsent62.
@Test(dependsOnMethods = { "testQueryAbsent61" })
public void testQueryAbsent62() throws InterruptedException {
log.info("Test the query every (e1 and not e2 for 1 sec) -> e3 with e3, e3, e2, e3");
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); ";
String query = "" + "@info(name = 'query1') " + "from every (e2=Stream2[price>20] and not Stream1[price>10] for 1 sec) -> " + "e3=Stream3[price>30] " + "select 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[] { "ORACLE", "GOOGLE" });
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
Thread.sleep(1200);
stream3.send(new Object[] { "WSO2", 35.0f, 100 });
Thread.sleep(1200);
stream3.send(new Object[] { "IBM", 55.0f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "ORACLE", 65.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 75.0f, 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 arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent22.
@Test(dependsOnMethods = { "testQueryAbsent21" })
public void testQueryAbsent22() throws InterruptedException {
log.info("Test the query e1 -> (not e2 and e3) within 1 sec with e1, e2 and e3 after 1 sec");
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); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> (not Stream2[price>20] and e3=Stream3[price>30]) within 1 sec " + "select e1.symbol as symbol1, e3.symbol as symbol3 " + "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");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 15.0f, 100 });
Thread.sleep(1100);
stream2.send(new Object[] { "IBM", 25.0f, 100 });
Thread.sleep(1100);
stream3.send(new Object[] { "GOOGLE", 35.0f, 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();
}
Aggregations