Search in sources :

Example 61 with QueryCallback

use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery23.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery22" })
public void testSnapshotOutputRateLimitQuery23() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test23");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest23') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(3) " + "select  ip, sum(calls) as totalCalls " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    log.info("Running : " + siddhiAppRuntime.getName());
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            eventArrived = true;
            count.incrementAndGet();
            for (Event inEvent : inEvents) {
                value++;
                if (value == 1) {
                    AssertJUnit.assertEquals("192.10.1.5", (String) inEvent.getData(0));
                } else if (value == 2) {
                    AssertJUnit.assertEquals("192.10.1.6", (String) inEvent.getData(0));
                } else if (value == 3) {
                    AssertJUnit.assertEquals("192.10.1.7", (String) inEvent.getData(0));
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    Thread.sleep(100);
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4", 2 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 1 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.6", 1 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.7", 2 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.8", 10 });
    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> eventArrived && count.get() == 1 && value == 3);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event bundles", 1, count.get());
    AssertJUnit.assertEquals("Number of output events", 3, value);
    siddhiAppRuntime.shutdown();
    Thread.sleep(2000);
}
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 62 with QueryCallback

use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery26.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery25" })
public void testSnapshotOutputRateLimitQuery26() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test26");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest23') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(3) " + "select ip, sum(calls) as totalCalls " + "group by ip " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    log.info("Running : " + siddhiAppRuntime.getName());
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            eventArrived = true;
            count.incrementAndGet();
            for (Event inEvent : inEvents) {
                value++;
                if (value == 1) {
                    AssertJUnit.assertEquals((Long) 1L, inEvent.getData(1));
                } else if (value == 2) {
                    AssertJUnit.assertEquals((Long) 1L, inEvent.getData(1));
                } else if (value == 3) {
                    AssertJUnit.assertEquals((Long) 2L, inEvent.getData(1));
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    Thread.sleep(100);
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4", 2 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 1 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.6", 1 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.7", 2 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.8", 10 });
    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> eventArrived && count.get() == 1 && value == 3);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event bundles", 1, count.get());
    AssertJUnit.assertEquals("Number of output events", 3, value);
    siddhiAppRuntime.shutdown();
    Thread.sleep(2000);
}
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 63 with QueryCallback

use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery27.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery26" })
public void testSnapshotOutputRateLimitQuery27() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test27");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest27') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(3) " + "select ip  " + "group by ip " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    log.info("Running : " + siddhiAppRuntime.getName());
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            eventArrived = true;
            count.incrementAndGet();
            for (Event inEvent : inEvents) {
                value++;
                if (value == 1) {
                    AssertJUnit.assertEquals("192.10.1.5", (String) inEvent.getData(0));
                } else if (value == 2) {
                    AssertJUnit.assertEquals("192.10.1.6", (String) inEvent.getData(0));
                } else if (value == 3) {
                    AssertJUnit.assertEquals("192.10.1.7", (String) inEvent.getData(0));
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    Thread.sleep(100);
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4", 2 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 1 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.6", 1 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.7", 2 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.8", 10 });
    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> eventArrived && count.get() == 1 && value == 3);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event bundles", 1, count.get());
    AssertJUnit.assertEquals("Number of output events", 3, value);
    siddhiAppRuntime.shutdown();
    Thread.sleep(2000);
}
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 64 with QueryCallback

use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery24.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery23" })
public void testSnapshotOutputRateLimitQuery24() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test24");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest23') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(3) " + "select  sum(calls) as totalCalls " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    log.info("Running : " + siddhiAppRuntime.getName());
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            eventArrived = true;
            count.incrementAndGet();
            for (Event inEvent : inEvents) {
                value++;
                if (value == 1) {
                    AssertJUnit.assertEquals((Long) 4L, inEvent.getData(0));
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    Thread.sleep(100);
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4", 2 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 1 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.6", 1 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.7", 2 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.8", 10 });
    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> eventArrived && count.get() == 1 && value == 1);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event bundles", 1, count.get());
    AssertJUnit.assertEquals("Number of output events", 1, value);
    siddhiAppRuntime.shutdown();
    Thread.sleep(2000);
}
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 65 with QueryCallback

use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.

the class TimeOutputRateLimitTestCase method testTimeOutputRateLimitQuery3.

@Test
public void testTimeOutputRateLimitQuery3() throws InterruptedException {
    log.info("TimeOutputRateLimit test3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('EventOutputRateLimitTest3') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "output every 1 sec " + "insert into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    log.info("Running : " + siddhiAppRuntime.getName());
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                count += inEvents.length;
            } else {
                AssertJUnit.fail("Remove events emitted");
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.9" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
    Thread.sleep(1100);
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.30" });
    Thread.sleep(1000);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event value", 8, count);
    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

QueryCallback (org.ballerinalang.siddhi.core.query.output.callback.QueryCallback)575 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)574 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)574 Test (org.testng.annotations.Test)574 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)572 Event (org.ballerinalang.siddhi.core.event.Event)569 SiddhiApp (org.ballerinalang.siddhi.query.api.SiddhiApp)73 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)73 Query (org.ballerinalang.siddhi.query.api.execution.query.Query)73 ArrayList (java.util.ArrayList)25 InMemoryPersistenceStore (org.ballerinalang.siddhi.core.util.persistence.InMemoryPersistenceStore)11 PersistenceStore (org.ballerinalang.siddhi.core.util.persistence.PersistenceStore)11 CannotRestoreSiddhiAppStateException (org.ballerinalang.siddhi.core.exception.CannotRestoreSiddhiAppStateException)10 StringConcatAggregatorString (org.ballerinalang.siddhi.core.query.extension.util.StringConcatAggregatorString)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)4 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)1