Search in sources :

Example 51 with Group

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

the class StoreQueryTableTestCase method test13.

@Test
public void test13() throws InterruptedException {
    log.info("Test13 - Test output attributes and its types for aggregation table");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long);" + "define aggregation StockTableAg " + "from StockStream " + "select symbol, price " + "group by symbol " + "aggregate every minutes ...year;";
    String storeQuery = "" + "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, price ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
    siddhiAppRuntime.start();
    Attribute[] actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
    Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
    Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
    Attribute[] expectedAttributeArray = new Attribute[] { symbolAttribute, priceAttribute };
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
    storeQuery = "" + "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, sum(price) as total";
    actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
    Attribute totalVolumeAttribute = new Attribute("total", Attribute.Type.DOUBLE);
    expectedAttributeArray = new Attribute[] { symbolAttribute, totalVolumeAttribute };
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
Also used : Attribute(org.wso2.siddhi.query.api.definition.Attribute) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 52 with Group

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

the class StoreQueryTableTestCase method test3.

@Test
public void test3() throws InterruptedException {
    log.info("Test3 table");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 75.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    Thread.sleep(500);
    Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, sum(volume) as totalVolume " + "group by symbol " + "having totalVolume >150 ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(1, events.length);
    AssertJUnit.assertEquals(200L, events[0].getData(1));
    events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, sum(volume) as totalVolume " + "group by symbol  ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(2, events.length);
    events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, sum(volume) as totalVolume " + "group by symbol,price  ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(3, events.length);
    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 53 with Group

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

the class StoreQueryTableTestCase method test6.

@Test(expectedExceptions = SiddhiParserException.class)
public void test6() throws InterruptedException {
    log.info("Test5 table");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
    try {
        siddhiAppRuntime.start();
        Event[] events = siddhiAppRuntime.query("" + "from StockTable1 " + "on price > 5 " + "select symbol1, sum(volume)  totalVolume " + "group by symbol " + "having totalVolume >150 ");
        EventPrinter.print(events);
        AssertJUnit.assertEquals(1, events.length);
        AssertJUnit.assertEquals(200L, events[0].getData(1));
    } finally {
        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 54 with Group

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

the class IncrementalStreamProcessorTestCase method incrementalStreamProcessorTest3.

@Test
public void incrementalStreamProcessorTest3() {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + " define stream cseEventStream (arrival long, symbol string, price float, volume int); ";
    String query = "" + " @info(name = 'query3') " + " define aggregation cseEventAggregation " + " from cseEventStream " + " select sum(price) as sumPrice " + " group by price " + " aggregate every sec, min, hour, day";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 55 with Group

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

the class DefineAggregationTestCase method test2.

@Test
public void test2() throws SiddhiParserException {
    AggregationDefinition aggregationDefinitionQuery = SiddhiCompiler.parseAggregationDefinition("define aggregation StockAggregationDefinition " + "from StockStream " + "select StockStream.timestamp, StockStream.symbol as symbol, " + "       StockStream.price as price " + "   group by StockStream.symbol " + "aggregate by timestamp " + "every seconds, minutes, hours ;");
    AggregationDefinition aggregationDefinition = AggregationDefinition.id("StockAggregationDefinition").from(InputStream.stream("StockStream")).select(Selector.basicSelector().select(Expression.variable("timestamp").ofStream("StockStream")).select("symbol", Expression.variable("symbol").ofStream("StockStream")).select("price", Expression.variable("price").ofStream("StockStream")).groupBy(Expression.variable("symbol").ofStream("StockStream"))).aggregateBy(Expression.variable("timestamp")).every(TimePeriod.interval(TimePeriod.Duration.SECONDS, TimePeriod.Duration.MINUTES, TimePeriod.Duration.HOURS));
    AssertJUnit.assertEquals(aggregationDefinition, aggregationDefinitionQuery);
}
Also used : AggregationDefinition(org.wso2.siddhi.query.api.definition.AggregationDefinition) 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