Search in sources :

Example 81 with QueryCallback

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

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery16.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery15" })
public void testSnapshotOutputRateLimitQuery16() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test16");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest16') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(1 sec) " + "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;
            if (inEvents != null) {
                count.incrementAndGet();
                for (Event event : inEvents) {
                    AssertJUnit.assertTrue("192.10.1.5".equals(event.getData(0)) || "192.10.1.3".equals(event.getData(0)));
                }
                value += inEvents.length;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    Thread.sleep(1100);
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
    Thread.sleep(2200);
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 2 });
    inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 10 });
    Thread.sleep(1200);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event bundles with inEvents", 2, count.get());
    AssertJUnit.assertEquals("Number of output event", 4, value);
    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 82 with QueryCallback

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

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery22.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery21" })
public void testSnapshotOutputRateLimitQuery22() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test22");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest22') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(3) " + "select  ip, calls " + "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 });
    Thread.sleep(1200);
    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(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 83 with QueryCallback

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

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery28.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery27" })
public void testSnapshotOutputRateLimitQuery28() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test28");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest28') " + "" + "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();
            if (inEvents != null) {
                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.3", (String) inEvent.getData(0));
                    } else if (value == 3) {
                        AssertJUnit.assertEquals("192.10.1.4", (String) inEvent.getData(0));
                    } else if (value == 4) {
                        AssertJUnit.assertEquals("192.10.1.5", (String) inEvent.getData(0));
                    } else if (value == 5) {
                        AssertJUnit.assertEquals("192.10.1.6", (String) inEvent.getData(0));
                    } else if (value == 6) {
                        AssertJUnit.assertEquals("192.10.1.7", (String) inEvent.getData(0));
                    }
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    Thread.sleep(2100);
    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 });
    Thread.sleep(1200);
    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 });
    Thread.sleep(1200);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertTrue("Number of output event bundles count > 2", count.get() > 2);
    AssertJUnit.assertEquals("Number of output events", 6, value);
    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 84 with QueryCallback

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

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 });
    Thread.sleep(1200);
    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(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 85 with QueryCallback

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

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 });
    Thread.sleep(1200);
    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(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