Search in sources :

Example 31 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery52.

@Test
public void testFilterQuery52() throws InterruptedException {
    log.info("Filter test52");
    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.EQUAL, Expression.value(60))));
    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, 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 32 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery21.

@Test
public void testFilterQuery21() throws InterruptedException {
    log.info("Filter test21");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume long);";
    String query = "@info(name = 'query1') from cseEventStream[volume != 100] select symbol,price,volume insert " + "into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    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, 100L });
    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) 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 33 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery23.

@Test
public void testFilterQuery23() throws InterruptedException {
    log.info("Filter test23");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume long);";
    String query = "@info(name = 'query1') from cseEventStream[symbol != 'WSO2' and volume != 55L and price != " + "45f ] select symbol,price,volume insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    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", 45f, 100L });
    inputHandler.send(new Object[] { "IBM", 35f, 50L });
    SiddhiTestHelper.waitForEvents(10, 1, count, 200);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) 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 34 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery24.

@Test
public void testFilterQuery24() throws InterruptedException {
    log.info("Filter test24");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume long);";
    String query = "@info(name = 'query1') from cseEventStream[volume != 50f] select symbol,price insert into " + "outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    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", 45f, 100L });
    inputHandler.send(new Object[] { "IBM", 35f, 50L });
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) 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 35 with QueryCallback

use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class FilterTestCase1 method testFilterQuery36.

@Test
public void testFilterQuery36() throws InterruptedException {
    log.info("Filter test36");
    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.compare(Expression.variable("available"), Compare.Operator.EQUAL, Expression.value(true))));
    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);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            AssertJUnit.assertEquals("IBM", inEvents[0].getData(0).toString());
            count.addAndGet(inEvents.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 55.6f, true });
    inputHandler.send(new Object[] { "WSO2", 57.6f, false });
    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)

Aggregations

QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)824 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)823 Test (org.testng.annotations.Test)822 SiddhiManager (io.siddhi.core.SiddhiManager)821 Event (io.siddhi.core.event.Event)818 InputHandler (io.siddhi.core.stream.input.InputHandler)817 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)75 SiddhiApp (io.siddhi.query.api.SiddhiApp)74 Query (io.siddhi.query.api.execution.query.Query)74 ArrayList (java.util.ArrayList)43 Logger (org.apache.logging.log4j.core.Logger)26 CannotRestoreSiddhiAppStateException (io.siddhi.core.exception.CannotRestoreSiddhiAppStateException)23 TestAppenderToValidateLogsForCachingTests (io.siddhi.core.query.table.util.TestAppenderToValidateLogsForCachingTests)21 InMemoryPersistenceStore (io.siddhi.core.util.persistence.InMemoryPersistenceStore)11 IncrementalFileSystemPersistenceStore (io.siddhi.core.util.persistence.IncrementalFileSystemPersistenceStore)11 PersistenceStore (io.siddhi.core.util.persistence.PersistenceStore)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 StreamCallback (io.siddhi.core.stream.output.StreamCallback)7 StringConcatAggregatorExecutorString (io.siddhi.core.query.extension.util.StringConcatAggregatorExecutorString)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6