Search in sources :

Example 21 with Group

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

the class AggregationTestCase method incrementalStreamProcessorTest17.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest16" })
public void incrementalStreamProcessorTest17() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest17");
    SiddhiManager siddhiManager = new SiddhiManager();
    String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp long);";
    String query = "define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice, sum(price) as totalPrice, " + "(price * quantity) as lastTradeValue " + "group by symbol " + "aggregate by timestamp every sec...year; " + "define stream inputStream (symbol string, value int, startTime string, " + "endTime string, perValue string); " + "@info(name = 'query1') " + "from inputStream as i join stockAggregation as s " + "within \"2017-01-01 00:00:00\", \"2021-01-01 00:00:00\" " + "per \"months\" " + "select AGG_TIMESTAMP, s.symbol, avgPrice, totalPrice " + "order by AGG_TIMESTAMP " + "insert all events into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
    try {
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                if (inEvents != null) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    for (Event event : inEvents) {
                        inEventsList.add(event.getData());
                        inEventCount.incrementAndGet();
                    }
                    eventArrived = true;
                }
                if (removeEvents != null) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    for (Event event : removeEvents) {
                        removeEventsList.add(event.getData());
                        removeEventCount.incrementAndGet();
                    }
                }
                eventArrived = true;
            }
        });
        InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
        InputHandler inputStreamInputHandler = siddhiAppRuntime.getInputHandler("inputStream");
        siddhiAppRuntime.start();
        // Thursday, June 1, 2017 4:05:50 AM
        stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, 1496289950000L });
        stockStreamInputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10, 1496289950000L });
        // Thursday, June 1, 2017 4:05:52 AM
        stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 56, 1496289952000L });
        stockStreamInputHandler.send(new Object[] { "WSO2", 100f, null, 200L, 16, 1496289952000L });
        // Thursday, June 1, 2017 4:05:50 AM (out of order. since there's no buffer, this must be processed with
        // 52nd second's data. since IgnoreEventsOlderThanBuffer is false by default, the event must not be dropped)
        stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, 1496289950000L });
        stockStreamInputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10, 1496289950000L });
        // Thursday, June 1, 2017 4:05:54 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 26, 1496289954000L });
        stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 96, 1496289954000L });
        // Thursday, June 1, 2017 4:05:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 900f, null, 200L, 60, 1496289956000L });
        stockStreamInputHandler.send(new Object[] { "IBM", 500f, null, 200L, 7, 1496289956000L });
        // Thursday, June 1, 2017 4:06:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 400f, null, 200L, 9, 1496290016000L });
        // Thursday, June 1, 2017 4:07:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 600f, null, 200L, 6, 1496290076000L });
        // Thursday, June 1, 2017 5:07:56 AM
        stockStreamInputHandler.send(new Object[] { "CISCO", 700f, null, 200L, 20, 1496293676000L });
        // Thursday, June 1, 2017 6:07:56 AM
        stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 56, 1496297276000L });
        // Friday, June 2, 2017 6:07:56 AM
        stockStreamInputHandler.send(new Object[] { "CISCO", 800f, null, 100L, 10, 1496383676000L });
        // Saturday, June 3, 2017 6:07:56 AM
        stockStreamInputHandler.send(new Object[] { "CISCO", 900f, null, 100L, 15, 1496470076000L });
        // Monday, July 3, 2017 6:07:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 96, 1499062076000L });
        // Thursday, August 3, 2017 6:07:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 400f, null, 200L, 9, 1501740476000L });
        // Friday, August 3, 2018 6:07:56 AM
        stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 6, 1533276476000L });
        // Saturday, August 3, 2019 6:07:56 AM
        stockStreamInputHandler.send(new Object[] { "WSO2", 260f, 44f, 200L, 16, 1564812476000L });
        // Monday, August 3, 2020 6:07:56 AM
        stockStreamInputHandler.send(new Object[] { "CISCO", 260f, 44f, 200L, 16, 1596434876000L });
        // Monday, December 3, 2020 6:07:56 AM
        stockStreamInputHandler.send(new Object[] { "CISCO", 260f, 44f, 200L, 16, 1606975676000L });
        Thread.sleep(100);
        inputStreamInputHandler.send(new Object[] { "IBM", 1, "2017-06-01 09:35:51 +05:30", "2017-06-01 09:35:52 +05:30", "seconds" });
        Thread.sleep(100);
        List<Object[]> expected = Arrays.asList(new Object[] { 1496275200000L, "WSO2", 65.71428571428571, 460.0 }, new Object[] { 1496275200000L, "CISCO", 800.0, 2400.0 }, new Object[] { 1496275200000L, "IBM", 433.3333333333333, 2600.0 }, new Object[] { 1498867200000L, "IBM", 100.0, 100.0 }, new Object[] { 1501545600000L, "IBM", 400.0, 400.0 }, new Object[] { 1533081600000L, "WSO2", 60.0, 60.0 }, new Object[] { 1564617600000L, "WSO2", 260.0, 260.0 }, new Object[] { 1596240000000L, "CISCO", 260.0, 260.0 }, new Object[] { 1606780800000L, "CISCO", 260.0, 260.0 });
        SiddhiTestHelper.waitForEvents(100, 9, inEventCount, 60000);
        AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected));
        AssertJUnit.assertEquals("Remove events matched", true, SiddhiTestHelper.isEventsMatch(removeEventsList, expected));
        AssertJUnit.assertEquals("Number of success events", 9, inEventCount.get());
        AssertJUnit.assertEquals("Number of remove events", 9, removeEventCount.get());
        AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    } finally {
        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 22 with Group

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

the class AggregationTestCase method incrementalStreamProcessorTest30.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest29" }, expectedExceptions = StoreQueryCreationException.class)
public void incrementalStreamProcessorTest30() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest30");
    SiddhiManager siddhiManager = new SiddhiManager();
    String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp long);";
    String query = " define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue  " + "group by symbol " + "aggregate by timestamp every sec...hour ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
    siddhiAppRuntime.start();
    Thread.sleep(100);
    Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within \"2017-06-** 12:**:**\" " + "per \"hours\"");
    EventPrinter.print(events);
    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 23 with Group

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

the class AggregationTestCase method incrementalStreamProcessorTest31.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest30" })
public void incrementalStreamProcessorTest31() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest31");
    SiddhiManager siddhiManager = new SiddhiManager();
    String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp long);";
    String query = " define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue  " + "group by symbol " + "aggregate by timestamp every sec...hour ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();
    stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, 1496289950000L });
    stockStreamInputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10, 1496289950000L });
    stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 56, 1496289952000L });
    stockStreamInputHandler.send(new Object[] { "WSO2", 100f, null, 200L, 16, 1496289952000L });
    stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 26, 1496289954000L });
    stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 96, 1496289954000L });
    stockStreamInputHandler.send(new Object[] { "CISCO", 100f, null, 200L, 26, 1513578087000L });
    stockStreamInputHandler.send(new Object[] { "CISCO", 100f, null, 200L, 96, 1513578087000L });
    Thread.sleep(100);
    Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within \"2017-**-** **:**:**\" " + "per \"seconds\" " + "select * " + "order by AGG_TIMESTAMP ;");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(4, events.length);
    for (int i = 0; i < events.length; i++) {
        switch(i) {
            case 0:
                AssertJUnit.assertArrayEquals(new Object[] { 1496289950000L, "WSO2", 60.0, 120.0, 700f }, events[i].getData());
                break;
            case 1:
                AssertJUnit.assertArrayEquals(new Object[] { 1496289952000L, "WSO2", 80.0, 160.0, 1600f }, events[i].getData());
                break;
            case 2:
                AssertJUnit.assertArrayEquals(new Object[] { 1496289954000L, "IBM", 100.0, 200.0, 9600f }, events[i].getData());
                break;
            case 3:
                AssertJUnit.assertArrayEquals(new Object[] { 1513578087000L, "CISCO", 100.0, 200.0, 9600f }, events[i].getData());
                break;
            default:
                AssertJUnit.assertEquals(4, events.length);
        }
    }
    Thread.sleep(100);
    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) Test(org.testng.annotations.Test)

Example 24 with Group

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

the class AggregationTestCase method incrementalStreamProcessorTest5.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest4" })
public void incrementalStreamProcessorTest5() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest5");
    SiddhiManager siddhiManager = new SiddhiManager();
    String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp long);";
    String query = " define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue  " + "group by symbol " + "aggregate by timestamp every sec...hour ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();
    stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, 1496289950000L });
    stockStreamInputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10, 1496289950000L });
    stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 56, 1496289952000L });
    stockStreamInputHandler.send(new Object[] { "WSO2", 100f, null, 200L, 16, 1496289952000L });
    stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 26, 1496289954000L });
    stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 96, 1496289954000L });
    Thread.sleep(100);
    Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within \"2017-06-** **:**:**\" " + "per \"seconds\"");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(3, events.length);
    for (int i = 0; i < events.length; i++) {
        switch(i) {
            case 0:
                AssertJUnit.assertArrayEquals(new Object[] { 1496289952000L, "WSO2", 80.0, 160.0, 1600f }, events[i].getData());
                break;
            case 1:
                AssertJUnit.assertArrayEquals(new Object[] { 1496289950000L, "WSO2", 60.0, 120.0, 700f }, events[i].getData());
                break;
            case 3:
                AssertJUnit.assertArrayEquals(new Object[] { 1496289954000L, "IBM", 100.0, 200.0, 9600f }, events[i].getData());
                break;
            default:
                AssertJUnit.assertEquals(3, events.length);
        }
    }
    Thread.sleep(100);
    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) Test(org.testng.annotations.Test)

Example 25 with Group

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

the class AggregationTestCase method incrementalStreamProcessorTest3.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest2" })
public void incrementalStreamProcessorTest3() {
    LOG.info("incrementalStreamProcessorTest3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String stockStream = "" + " define stream stockStream (arrival long, symbol string, price float, volume int); ";
    String query = "" + " @info(name = 'query3') " + " define aggregation stockAggregation " + " from stockStream " + " select sum(price) as sumPrice " + " group by price " + " aggregate every sec, min, hour, day";
    siddhiManager.createSiddhiAppRuntime(stockStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) 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