Search in sources :

Example 41 with Group

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

the class TimeOutputRateLimitTestCase method testTimeOutputRateLimitQuery8.

@Test
public void testTimeOutputRateLimitQuery8() throws InterruptedException {
    log.info("TimeOutputRateLimit test8");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('EventOutputRateLimitTest8') " + "" + "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 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(1200);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event value", 5, 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 42 with Group

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

the class StdDevAttributeAggregatorTestCase method stdDevAggregatorTest5.

@Test
public void stdDevAggregatorTest5() throws InterruptedException {
    log.info("stdDevAggregator Test #5: stdDev of large and small numbers");
    SiddhiManager siddhiManager = new SiddhiManager();
    String execPlan = "" + "@app:name('stdDevAggregatorTests') " + "" + "define stream cseEventStream (symbol string, price double);" + "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(6) " + "select stdDev(price) as deviation " + "group by symbol " + "insert into outputStream;";
    SiddhiAppRuntime execPlanRunTime = siddhiManager.createSiddhiAppRuntime(execPlan);
    execPlanRunTime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            AssertJUnit.assertTrue(Math.abs((Double) inEvents[0].getData(0) - 400.13025) < epsilon);
            AssertJUnit.assertTrue(Math.abs((Double) inEvents[1].getData(0) - 0.00103) < epsilon);
        }
    });
    InputHandler inputHandler = execPlanRunTime.getInputHandler("cseEventStream");
    execPlanRunTime.start();
    inputHandler.send(new Object[] { "WSO2", 23.0 });
    inputHandler.send(new Object[] { "WSO2", 1003.0 });
    inputHandler.send(new Object[] { "WSO2", 500.0 });
    inputHandler.send(new Object[] { "IBM", 0.002 });
    inputHandler.send(new Object[] { "IBM", 0.0034 });
    inputHandler.send(new Object[] { "IBM", 0.00454 });
    Thread.sleep(600);
    execPlanRunTime.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 43 with Group

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

the class StdDevAttributeAggregatorTestCase method stdDevAggregatorTest2.

@Test
public void stdDevAggregatorTest2() throws InterruptedException {
    log.info("stdDevAggregator Test #2: Single event in the stream");
    SiddhiManager siddhiManager = new SiddhiManager();
    String execPlan = "" + "@app:name('stdDevAggregatorTests') " + "" + "define stream cseEventStream (symbol string, price double);" + "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(1) " + "select stdDev(price) as deviation " + "group by symbol " + "insert into outputStream;";
    SiddhiAppRuntime execPlanRunTime = siddhiManager.createSiddhiAppRuntime(execPlan);
    execPlanRunTime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            AssertJUnit.assertTrue(Math.abs((Double) inEvents[0].getData(0) - 0) < epsilon);
        }
    });
    InputHandler inputHandler = execPlanRunTime.getInputHandler("cseEventStream");
    execPlanRunTime.start();
    inputHandler.send(new Object[] { "WSO2", 1.0 });
    Thread.sleep(100);
    execPlanRunTime.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 44 with Group

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

the class StdDevAttributeAggregatorTestCase method stdDevAggregatorTest1.

@Test
public void stdDevAggregatorTest1() throws InterruptedException {
    log.info("stdDevAggregator Test #1: No events in the stream");
    SiddhiManager siddhiManager = new SiddhiManager();
    String execPlan = "" + "@app:name('stdDevAggregatorTests') " + "" + "define stream cseEventStream (symbol string, price double);" + "" + "@info(name = 'query1') " + "from cseEventStream " + "select stdDev(price) as deviation " + "group by symbol " + "insert into outputStream;";
    SiddhiAppRuntime execPlanRunTime = siddhiManager.createSiddhiAppRuntime(execPlan);
    log.info("Running: " + execPlanRunTime.getName());
    execPlanRunTime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            inEventCount++;
        }
    });
    execPlanRunTime.start();
    execPlanRunTime.shutdown();
    AssertJUnit.assertEquals(0, inEventCount);
}
Also used : 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 45 with Group

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

the class StdDevAttributeAggregatorTestCase method stdDevAggregatorTest6.

@Test
public void stdDevAggregatorTest6() throws InterruptedException {
    log.info("stdDevAggregator Test #6");
    final double[] results = new double[] { 0.0, 489.95, 400.09052, 405.11802, 199.96026 };
    SiddhiManager siddhiManager = new SiddhiManager();
    String windowExecPlan = "" + "@app:name('stdDevAggregatorTests') " + "" + "define stream cseEventStream (symbol string, price double);" + "" + "@info(name = 'query1') " + "from cseEventStream#window.length(3) " + "select stdDev(price) as deviation " + "group by symbol " + "insert all events into outputStream;";
    SiddhiAppRuntime execPlanRunTime = siddhiManager.createSiddhiAppRuntime(windowExecPlan);
    execPlanRunTime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            for (Event event : inEvents) {
                AssertJUnit.assertTrue(Math.abs(results[inEventCount] - (Double) event.getData(0)) < epsilon);
                inEventCount++;
            }
        }
    });
    InputHandler inputHandler = execPlanRunTime.getInputHandler("cseEventStream");
    execPlanRunTime.start();
    inputHandler.send(new Object[] { "WSO2", 23.3 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { "WSO2", 1003.2 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { "WSO2", 500.1 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { "WSO2", 10.9 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { "WSO2", 234.5 });
    Thread.sleep(100);
    execPlanRunTime.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)155 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)99 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)94 Event (org.wso2.siddhi.core.event.Event)89 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)80 Group (org.wso2.charon3.core.objects.Group)57 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)53 CharonException (org.wso2.charon3.core.exceptions.CharonException)43 HashMap (java.util.HashMap)38 Connection (java.sql.Connection)34 SQLException (java.sql.SQLException)34 ArrayList (java.util.ArrayList)34 IdentitySCIMException (org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)34 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)33 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)32 PreparedStatement (java.sql.PreparedStatement)29 ResultSet (java.sql.ResultSet)29 Operation (io.swagger.v3.oas.annotations.Operation)27 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)27 Response (javax.ws.rs.core.Response)27