Search in sources :

Example 81 with SiddhiAppRuntime

use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.

the class TimeWindowTestCase method timeWindowTest6.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void timeWindowTest6() throws InterruptedException, SiddhiAppCreationException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "define stream cseEventStream (symbol string, time long, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(4.7) " + "select symbol,price,volume " + "insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 82 with SiddhiAppRuntime

use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.

the class TimeWindowTestCase method timeWindowTest5.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void timeWindowTest5() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "define stream cseEventStream (symbol string, time long, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(time) " + "select symbol,price,volume " + "insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 83 with SiddhiAppRuntime

use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.

the class TimeWindowTestCase method timeWindowTest3.

@Test
public void timeWindowTest3() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String queries = "define stream fireAlarmEventStream (deviceID string, sonar double);\n" + "@info(name = 'query1')\n" + "from fireAlarmEventStream#window.time(30 milliseconds)\n" + "select deviceID\n" + "insert expired events into analyzeStream;\n" + "" + "@info(name = 'query2')\n" + "from analyzeStream\n" + "select deviceID\n" + "insert into bulbOnStream;\n";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(queries);
    siddhiAppRuntime.addCallback("analyzeStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("fireAlarmEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "id1", 20d });
    inputHandler.send(new Object[] { "id2", 20d });
    Thread.sleep(2000);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) StreamCallback(org.ballerinalang.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 84 with SiddhiAppRuntime

use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.

the class TimeWindowTestCase method timeWindowTest1.

@Test
public void timeWindowTest1() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(2 sec) " + "select symbol,price,volume " + "insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + 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;
            }
            if (removeEvents != null) {
                AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount);
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700f, 0 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
    Thread.sleep(4000);
    AssertJUnit.assertEquals(2, inEventCount);
    AssertJUnit.assertEquals(2, removeEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) QueryCallback(org.ballerinalang.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 85 with SiddhiAppRuntime

use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.

the class TimeWindowTestCase method timeWindowTest2.

/**
 * Commenting out intermittent failing test case until fix this properly.
 *
 * @throws InterruptedException throw exception if interrupted the input handler sender.
 */
@Test
public void timeWindowTest2() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "@info(name = 'query1') from cseEventStream#window.time(1 sec) select symbol,price," + "volume insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + 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;
            }
            if (removeEvents != null) {
                AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount);
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700f, 1 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
    Thread.sleep(1100);
    inputHandler.send(new Object[] { "IBM", 700f, 3 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 4 });
    Thread.sleep(1100);
    inputHandler.send(new Object[] { "IBM", 700f, 5 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
    Thread.sleep(4000);
    AssertJUnit.assertEquals(6, inEventCount);
    AssertJUnit.assertEquals(6, removeEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) QueryCallback(org.ballerinalang.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)1235 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)1231 Test (org.testng.annotations.Test)1231 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)1123 Event (org.ballerinalang.siddhi.core.event.Event)798 QueryCallback (org.ballerinalang.siddhi.core.query.output.callback.QueryCallback)574 TestUtil (org.ballerinalang.siddhi.core.TestUtil)300 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)201 SiddhiApp (org.ballerinalang.siddhi.query.api.SiddhiApp)85 Query (org.ballerinalang.siddhi.query.api.execution.query.Query)82 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)80 ArrayList (java.util.ArrayList)25 InMemoryBroker (org.ballerinalang.siddhi.core.util.transport.InMemoryBroker)16 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)12 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 HashMap (java.util.HashMap)11 InMemoryConfigManager (org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6