Search in sources :

Example 51 with SiddhiApp

use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery81.

@Test
public void testFilterQuery81() throws InterruptedException {
    log.info("Filter test81");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.LESS_THAN, Expression.value(70f))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
    query.insertInto("outputStream");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count.addAndGet(inEvents.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50f, 60d });
    inputHandler.send(new Object[] { "WSO2", 70f, 40d });
    inputHandler.send(new Object[] { "WSO2", 44f, 200d });
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiApp(io.siddhi.query.api.SiddhiApp) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Query(io.siddhi.query.api.execution.query.Query) 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 52 with SiddhiApp

use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery48.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testFilterQuery48() throws InterruptedException {
    log.info("Filter test48");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("available", Attribute.Type.BOOL);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.not(Expression.variable("price"))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("available", Expression.variable("available")));
    query.insertInto("StockQuote");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
}
Also used : SiddhiApp(io.siddhi.query.api.SiddhiApp) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Query(io.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 53 with SiddhiApp

use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery49.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testFilterQuery49() throws InterruptedException {
    log.info("Filter test49");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("available", Attribute.Type.BOOL);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.variable("price")));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("available", Expression.variable("available")));
    query.insertInto("StockQuote");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
}
Also used : SiddhiApp(io.siddhi.query.api.SiddhiApp) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Query(io.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 54 with SiddhiApp

use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery20.

@Test
public void testFilterQuery20() throws InterruptedException {
    log.info("Filter test20");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.LESS_THAN, Expression.value(100))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
    query.insertInto("StockQuote");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            AssertJUnit.assertEquals(10L, ((Long) inEvents[0].getData(2)).longValue());
            count.addAndGet(inEvents.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 55.6f, 103L });
    inputHandler.send(new Object[] { "WSO2", 57.6f, 10L });
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiApp(io.siddhi.query.api.SiddhiApp) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Query(io.siddhi.query.api.execution.query.Query) 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 55 with SiddhiApp

use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery73.

@Test
public void testFilterQuery73() throws InterruptedException {
    log.info("Filter test73");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE).attribute("quantity", Attribute.Type.INT);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(5d))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("quantity", Expression.variable("quantity")));
    query.insertInto("outputStream");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count.addAndGet(inEvents.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 500f, 60d, 6 });
    inputHandler.send(new Object[] { "WSO2", 70f, 60d, 2 });
    inputHandler.send(new Object[] { "WSO2", 60f, 300d, 4 });
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiApp(io.siddhi.query.api.SiddhiApp) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Query(io.siddhi.query.api.execution.query.Query) 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

SiddhiApp (io.siddhi.query.api.SiddhiApp)97 Test (org.testng.annotations.Test)93 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)90 SiddhiManager (io.siddhi.core.SiddhiManager)89 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)88 Query (io.siddhi.query.api.execution.query.Query)86 InputHandler (io.siddhi.core.stream.input.InputHandler)84 Event (io.siddhi.core.event.Event)82 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)74 Partition (io.siddhi.query.api.execution.partition.Partition)10 StreamCallback (io.siddhi.core.stream.output.StreamCallback)9 FunctionDefinition (io.siddhi.query.api.definition.FunctionDefinition)4 TriggerDefinition (io.siddhi.query.api.definition.TriggerDefinition)2 Gson (com.google.gson.Gson)1 Source (io.siddhi.core.stream.input.source.Source)1 Sink (io.siddhi.core.stream.output.sink.Sink)1 InMemoryTable (io.siddhi.core.table.InMemoryTable)1 Table (io.siddhi.core.table.Table)1 TableDefinition (io.siddhi.query.api.definition.TableDefinition)1 ExecutionElement (io.siddhi.query.api.execution.ExecutionElement)1