Search in sources :

Example 86 with SiddhiApp

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

the class FilterTestCase1 method testFilterQuery69.

@Test
public void testFilterQuery69() throws InterruptedException {
    log.info("Filter test69");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.LONG);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(50))));
    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 = count + inEvents.length;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50d, 60L });
    inputHandler.send(new Object[] { "WSO2", 70d, 40L });
    inputHandler.send(new Object[] { "WSO2", 44d, 200L });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Query(org.wso2.siddhi.query.api.execution.query.Query) 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 87 with SiddhiApp

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

the class FilterTestCase1 method testFilterQuery66.

@Test
public void testFilterQuery66() throws InterruptedException {
    log.info("Filter test66");
    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.not(Expression.compare(Expression.variable("volume"), Compare.Operator.EQUAL, Expression.value(40)))));
    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 = count + inEvents.length;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50f, 60L });
    inputHandler.send(new Object[] { "WSO2", 70f, 40L });
    inputHandler.send(new Object[] { "WSO2", 44f, 200L });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Query(org.wso2.siddhi.query.api.execution.query.Query) 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 88 with SiddhiApp

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

the class FilterTestCase1 method testFilterQuery56.

@Test
public void testFilterQuery56() throws InterruptedException {
    log.info("Filter test56");
    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("price"), Compare.Operator.EQUAL, Expression.value(70))));
    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 = count + 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 });
    Thread.sleep(100);
    AssertJUnit.assertEquals(1, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Query(org.wso2.siddhi.query.api.execution.query.Query) 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 89 with SiddhiApp

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

the class FilterTestCase1 method testFilterQuery17.

@Test
public void testFilterQuery17() throws InterruptedException {
    log.info("Filter test17");
    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.GREATER_THAN, Expression.value(45))));
    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("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 = count + inEvents.length;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50f, 60L });
    inputHandler.send(new Object[] { "WSO2", 70f, 40L });
    inputHandler.send(new Object[] { "WSO2", 44f, 200L });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Query(org.wso2.siddhi.query.api.execution.query.Query) 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 90 with SiddhiApp

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

the class FilterTestCase1 method testFilterQuery71.

@Test
public void testFilterQuery71() throws InterruptedException {
    log.info("Filter test71");
    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("price"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(50d))));
    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 = count + inEvents.length;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50f, 60L });
    inputHandler.send(new Object[] { "WSO2", 70f, 40L });
    inputHandler.send(new Object[] { "WSO2", 44f, 200L });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Query(org.wso2.siddhi.query.api.execution.query.Query) 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

SiddhiManager (org.wso2.siddhi.core.SiddhiManager)273 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)272 Test (org.testng.annotations.Test)261 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)245 Event (org.wso2.siddhi.core.event.Event)241 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)138 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)109 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)88 Query (org.wso2.siddhi.query.api.execution.query.Query)84 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)81 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13 InMemoryPersistenceStore (org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore)13 PersistenceStore (org.wso2.siddhi.core.util.persistence.PersistenceStore)13 Partition (org.wso2.siddhi.query.api.execution.partition.Partition)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintStream (java.io.PrintStream)6 HashMap (java.util.HashMap)6 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)6 InMemoryConfigManager (org.wso2.siddhi.core.util.config.InMemoryConfigManager)5 ExecutionElement (org.wso2.siddhi.query.api.execution.ExecutionElement)4