use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class AbsentPatternTestCase method testQueryAbsent29.
@Test(dependsOnMethods = { "testQueryAbsent28" })
public void testQueryAbsent29() throws InterruptedException {
log.info("Test the query e1 -> not e2 for 1 sec -> e3 and e4 without e2 within 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); " + "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");
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(100);
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", 0, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertFalse("Event not arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class EveryAbsentPatternTestCase method testQueryAbsent3.
@Test(dependsOnMethods = { "testQueryAbsent2" })
public void testQueryAbsent3() throws InterruptedException {
log.info("Test the query (e1 -> every not e2 for 900 milliseconds) within 2 sec without sending e2");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "@app:playback " + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream TimerStream (symbol string); ";
String query = "" + "@info(name = 'query1') " + "from (e1=Stream1[price>20] -> every not Stream2[price>e1.price] for 900 milliseconds) within 2 sec " + "select e1.symbol as symbol1 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[] { "WSO2" }, new Object[] { "WSO2" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler timerStream = siddhiAppRuntime.getInputHandler("TimerStream");
siddhiAppRuntime.start();
long timestamp = System.currentTimeMillis();
stream1.send(timestamp, new Object[] { "WSO2", 55.6f, 100 });
timestamp += 1000;
timerStream.send(timestamp, new Object[] { "UPDATE-TIME" });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events after first timeout", 1, callback.getInEventCount());
timestamp += 1000;
timerStream.send(timestamp, new Object[] { "UPDATE-TIME" });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events after second timeout", 2, callback.getInEventCount());
timestamp += 1000;
timerStream.send(timestamp, new Object[] { "UPDATE-TIME" });
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 not arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class EveryAbsentPatternTestCase method testQueryAbsent41.
@Test(dependsOnMethods = { "testQueryAbsent40" })
public void testQueryAbsent41() throws InterruptedException {
log.info("Test the query e1 -> every (not e2 and e3) with e1 and e3 within 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] -> every (not Stream2[price>20] 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", new Object[] { "WSO2", "GOOGLE" }, new Object[] { "WSO2", "ORACLE" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 15.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 35.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "ORACLE", 45.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.aggregation.Within in project siddhi by wso2.
the class EveryAbsentPatternTestCase method testQueryAbsent2.
@Test(dependsOnMethods = { "testQueryAbsent1" })
public void testQueryAbsent2() throws InterruptedException {
log.info("Test the query (e1 -> every not e2 for 900 milliseconds) within 2 sec without sending 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); ";
String query = "" + "@info(name = 'query1') " + "from (e1=Stream1[price>20] -> every not Stream2[price>e1.price] for 900 milliseconds) within 2 sec " + "select e1.symbol as symbol1 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[] { "WSO2" }, new Object[] { "WSO2" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(3200);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 2, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertTrue("Event not arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class EveryAbsentPatternTestCase method testQueryAbsent35.
@Test(dependsOnMethods = { "testQueryAbsent34" })
public void testQueryAbsent35() throws InterruptedException {
log.info("Test the query e1 -> every not e2 for 1 sec -> e3 and e4 without e2 within 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); " + "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");
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(100);
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", 0, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertFalse("Event not arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
Aggregations