Search in sources :

Example 86 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery10.

@Test
public void testEventOutputRateLimitQuery10() throws InterruptedException {
    log.info("EventOutputRateLimit test10");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('EventOutputRateLimitTest8') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "group by ip " + "output first every 5 events " + "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" });
    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.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", 5, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 87 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery14.

@Test
public void testEventOutputRateLimitQuery14() throws InterruptedException {
    log.info("EventOutputRateLimit test14");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('EventOutputRateLimitTest14') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(4) " + "select  ip , count() as total " + "output last every 2 events " + "insert expired 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);
            if (removeEvents != null) {
                count += removeEvents.length;
            } else {
                AssertJUnit.fail("InEvents 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.3" });
    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.3" });
    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.4" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.30" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.31" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.32" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.33" });
    Thread.sleep(1000);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event value", 1, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 88 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery7.

@Test
public void testEventOutputRateLimitQuery7() throws InterruptedException {
    log.info("EventOutputRateLimit test7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('EventOutputRateLimitTest7') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "output last every 4 events " + "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;
                AssertJUnit.assertTrue("192.10.1.4".equals(inEvents[0].getData(0)));
            } else {
                AssertJUnit.fail("Remove events emitted");
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
    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.4" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
    Thread.sleep(1000);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event value", 1, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 89 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery16.

@Test
public void testEventOutputRateLimitQuery16() throws InterruptedException {
    log.info("EventOutputRateLimit test16");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('EventOutputRateLimitTest16') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(4) " + "select  ip , count() as total " + "group by ip " + "output all every 2 events " + "insert expired 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);
            if (removeEvents != null) {
                count += removeEvents.length;
            } else {
                AssertJUnit.fail("InEvents 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.3" });
    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.3" });
    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.4" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.30" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.31" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.32" });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.33" });
    Thread.sleep(1000);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event value", 4, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 90 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery9.

@Test
public void testEventOutputRateLimitQuery9() throws InterruptedException {
    log.info("EventOutputRateLimit test9");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('EventOutputRateLimitTest9') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select  ip " + "group by  ip " + "output last every 5 events " + "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" });
    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", 4, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)824 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)823 Test (org.testng.annotations.Test)822 SiddhiManager (io.siddhi.core.SiddhiManager)821 Event (io.siddhi.core.event.Event)818 InputHandler (io.siddhi.core.stream.input.InputHandler)817 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)75 SiddhiApp (io.siddhi.query.api.SiddhiApp)74 Query (io.siddhi.query.api.execution.query.Query)74 ArrayList (java.util.ArrayList)43 Logger (org.apache.logging.log4j.core.Logger)26 CannotRestoreSiddhiAppStateException (io.siddhi.core.exception.CannotRestoreSiddhiAppStateException)23 TestAppenderToValidateLogsForCachingTests (io.siddhi.core.query.table.util.TestAppenderToValidateLogsForCachingTests)21 InMemoryPersistenceStore (io.siddhi.core.util.persistence.InMemoryPersistenceStore)11 IncrementalFileSystemPersistenceStore (io.siddhi.core.util.persistence.IncrementalFileSystemPersistenceStore)11 PersistenceStore (io.siddhi.core.util.persistence.PersistenceStore)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 StreamCallback (io.siddhi.core.stream.output.StreamCallback)7 StringConcatAggregatorExecutorString (io.siddhi.core.query.extension.util.StringConcatAggregatorExecutorString)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6