Search in sources :

Example 26 with Within

use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.

the class LogicalAbsentPatternTestCase method testQueryAbsent29.

@Test(dependsOnMethods = { "testQueryAbsent28" })
public void testQueryAbsent29() throws InterruptedException {
    log.info("Test the query e1 -> (not e2 for 1 sec or not e3 for 1 sec) within 2 sec with e1 only");
    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 or not Stream3[price>30] for 1 sec) " + "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" });
    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "WSO2", 15.0f, 100 });
    Thread.sleep(1100);
    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();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 27 with Within

use of org.wso2.siddhi.query.api.aggregation.Within 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();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 28 with Within

use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.

the class LogicalAbsentPatternTestCase method testQueryAbsent31.

@Test(dependsOnMethods = { "testQueryAbsent30" })
public void testQueryAbsent31() throws InterruptedException {
    log.info("Test the query e1 -> (not e2 for 1 sec or not e3 for 1 sec) within 2 sec with e1 and 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 e1=Stream1[price>10] -> (not Stream2[price>20] for 1 sec or not Stream3[price>30] for 1 sec) " + "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" });
    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[] { "IBM", 35.0f, 102 });
    Thread.sleep(1100);
    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();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 29 with Within

use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.

the class LogicalAbsentPatternTestCase method testQueryAbsent6.

@Test(dependsOnMethods = { "testQueryAbsent5_2" })
public void testQueryAbsent6() throws InterruptedException {
    log.info("Test the query e1 -> not e2 for 1 sec 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] -> 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();
    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();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 30 with Within

use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.

the class LogicalAbsentPatternTestCase method testQueryAbsent1.

@Test
public void testQueryAbsent1() throws InterruptedException {
    log.info("Test the query e1 -> 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] -> 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" });
    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);
    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();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)135 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)101 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)100 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)90 TestUtil (org.wso2.siddhi.core.TestUtil)60 Event (org.wso2.siddhi.core.event.Event)37 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)28 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)27 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)23 BString (org.ballerinalang.model.values.BString)22 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)19 BJSON (org.ballerinalang.model.values.BJSON)18 ArrayList (java.util.ArrayList)8 ExecutorService (java.util.concurrent.ExecutorService)6 Expression (org.wso2.siddhi.query.api.expression.Expression)6 Map (java.util.Map)4 Semaphore (java.util.concurrent.Semaphore)4 Header (org.wso2.carbon.messaging.Header)4 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)4 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4