Search in sources :

Example 61 with InputHandler

use of org.ballerinalang.siddhi.core.stream.input.InputHandler in project ballerina by ballerina-lang.

the class LogicalAbsentSequenceTestCase method testQueryAbsent36.

@Test(dependsOnMethods = { "testQueryAbsent35" })
public void testQueryAbsent36() throws InterruptedException {
    log.info("Test the query (not e1 for 1 sec or not e2 for 1 sec), e3 with e1, e2 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 (not Stream1[price>10] for 1 sec or not Stream2[price>20] for 1 sec), e3=Stream3[price>30] " + "select e3.symbol as symbol " + "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[] { "ORACLE", 15.0f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "IBM", 25.0f, 100 });
    Thread.sleep(100);
    stream3.send(new Object[] { "WSO2", 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.ballerinalang.siddhi.core.stream.input.InputHandler) TestUtil(org.ballerinalang.siddhi.core.TestUtil) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 62 with InputHandler

use of org.ballerinalang.siddhi.core.stream.input.InputHandler in project ballerina by ballerina-lang.

the class LogicalAbsentSequenceTestCase method testQueryAbsent14.

@Test(dependsOnMethods = { "testQueryAbsent13" })
public void testQueryAbsent14() throws InterruptedException {
    log.info("Test the query e1, not e2 for 1 sec or e3 with e1 only with no waiting");
    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 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");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "WSO2", 15.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.ballerinalang.siddhi.core.stream.input.InputHandler) TestUtil(org.ballerinalang.siddhi.core.TestUtil) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 63 with InputHandler

use of org.ballerinalang.siddhi.core.stream.input.InputHandler in project ballerina by ballerina-lang.

the class LogicalAbsentSequenceTestCase method testQueryAbsent59.

@Test(dependsOnMethods = { "testQueryAbsent58" })
public void testQueryAbsent59() throws InterruptedException {
    log.info("Test the query every (e1 or 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] or 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[] { null, "WSO2" }, new Object[] { null, "IBM" }, 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", 3, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) TestUtil(org.ballerinalang.siddhi.core.TestUtil) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 64 with InputHandler

use of org.ballerinalang.siddhi.core.stream.input.InputHandler in project ballerina by ballerina-lang.

the class LogicalAbsentSequenceTestCase method testQueryAbsent3.

@Test(dependsOnMethods = { "testQueryAbsent2" })
public void testQueryAbsent3() throws InterruptedException {
    log.info("Test the query not e1 and e2, e3 with e2 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 not Stream1[price>10] and 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[] { "IBM", "GOOGLE" });
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    siddhiAppRuntime.start();
    stream2.send(new Object[] { "IBM", 25.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.ballerinalang.siddhi.core.stream.input.InputHandler) TestUtil(org.ballerinalang.siddhi.core.TestUtil) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 65 with InputHandler

use of org.ballerinalang.siddhi.core.stream.input.InputHandler in project ballerina by ballerina-lang.

the class LogicalAbsentSequenceTestCase method testQueryAbsent30.

@Test(dependsOnMethods = { "testQueryAbsent29" })
public void testQueryAbsent30() 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 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); ";
    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");
    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "WSO2", 15.0f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "IBM", 25.0f, 101 });
    Thread.sleep(1100);
    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.ballerinalang.siddhi.core.stream.input.InputHandler) TestUtil(org.ballerinalang.siddhi.core.TestUtil) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)1124 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)1123 Test (org.testng.annotations.Test)1122 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)1120 Event (org.ballerinalang.siddhi.core.event.Event)771 QueryCallback (org.ballerinalang.siddhi.core.query.output.callback.QueryCallback)572 TestUtil (org.ballerinalang.siddhi.core.TestUtil)300 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)190 SiddhiApp (org.ballerinalang.siddhi.query.api.SiddhiApp)79 Query (org.ballerinalang.siddhi.query.api.execution.query.Query)79 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)77 ArrayList (java.util.ArrayList)25 InMemoryBroker (org.ballerinalang.siddhi.core.util.transport.InMemoryBroker)13 CannotRestoreSiddhiAppStateException (org.ballerinalang.siddhi.core.exception.CannotRestoreSiddhiAppStateException)12 InMemoryPersistenceStore (org.ballerinalang.siddhi.core.util.persistence.InMemoryPersistenceStore)12 PersistenceStore (org.ballerinalang.siddhi.core.util.persistence.PersistenceStore)12 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintStream (java.io.PrintStream)6 Partition (org.ballerinalang.siddhi.query.api.execution.partition.Partition)6