Search in sources :

Example 36 with Group

use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery7.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery6" })
public void testSnapshotOutputRateLimitQuery7() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest7') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(5 sec) " + "select 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("uniqueIps", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            count.incrementAndGet();
            value += events.length;
            if (count.get() == 1 || count.get() == 2) {
                AssertJUnit.assertTrue((Long) events[0].getData(0) == 3L || (Long) events[1].getData(0) == 6L);
            } else if (count.get() == 3) {
                AssertJUnit.assertTrue((Long) events[0].getData(0) == 5L || (Long) events[1].getData(0) == 16L);
            }
        }
    });
    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(7200);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event bundles", 7, count.get());
    AssertJUnit.assertTrue("Number of output event value", 14 == value);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 37 with Group

use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery4.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery3" })
public void testSnapshotOutputRateLimitQuery4() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test4");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest4') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "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("uniqueIps", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            count.incrementAndGet();
            for (Event event : events) {
                if (event.isExpired()) {
                    AssertJUnit.fail("Remove events emitted");
                } else {
                    value++;
                    AssertJUnit.assertTrue("192.10.1.5".equals(event.getData(0)) || "192.10.1.3".equals(event.getData(0)) || "192.10.1.4".equals(event.getData(0)));
                }
            }
        }
    });
    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.4", 10 });
    Thread.sleep(1200);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event bundles ", 3, count.get());
    AssertJUnit.assertEquals("Number of output events  ", 7, value);
    siddhiAppRuntime.shutdown();
    Thread.sleep(2000);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 38 with Group

use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.

the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery6.

@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery5" })
public void testSnapshotOutputRateLimitQuery6() throws InterruptedException {
    log.info("SnapshotOutputRateLimit test6");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest6') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(1 sec) " + "select 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("uniqueIps", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            count.incrementAndGet();
            value += events.length;
            if (count.get() == 1) {
                AssertJUnit.assertTrue((Long) events[0].getData(0) == 3L || (Long) events[1].getData(0) == 6L);
            } else if (count.get() == 2) {
                AssertJUnit.assertTrue((Long) events[0].getData(0) == 2L || (Long) events[1].getData(0) == 10L);
            }
        }
    });
    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", 2, count.get());
    AssertJUnit.assertTrue("Number of output events", 4 == value);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 39 with Group

use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.

the class TimeOutputRateLimitTestCase method testTimeOutputRateLimitQuery9.

@Test
public void testTimeOutputRateLimitQuery9() throws InterruptedException {
    log.info("TimeOutputRateLimit test9");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('EventOutputRateLimitTest7') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(2) " + "select ip " + "group by ip " + "output last every 1 sec " + "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.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(1100);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event value", 4, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 40 with Group

use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.

the class TimeOutputRateLimitTestCase method testTimeOutputRateLimitQuery7.

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

Aggregations

Test (org.testng.annotations.Test)128 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)97 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)94 Event (org.wso2.siddhi.core.event.Event)87 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)78 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)51 Query (org.wso2.siddhi.query.api.execution.query.Query)17 ArrayList (java.util.ArrayList)16 CharonException (org.wso2.charon3.core.exceptions.CharonException)15 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)13 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)12 HashMap (java.util.HashMap)8 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)8 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)8 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)7 UserManager (org.wso2.charon3.core.extensions.UserManager)7 Group (org.wso2.charon3.core.objects.Group)7 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Produces (javax.ws.rs.Produces)6