Search in sources :

Example 16 with SiddhiApp

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

the class FilterTestCase1 method testFilterQuery54.

@Test
public void testFilterQuery54() throws InterruptedException {
    log.info("Filter test54");
    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(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.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 17 with SiddhiApp

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

the class PartitionTestCase1 method testPartitionQuery48.

@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery48() {
    log.info("Partition test48");
    SiddhiApp siddhiApp = new SiddhiApp("plan48");
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    siddhiApp.defineStream(streamDefinition);
    FunctionDefinition functionDefinition = new FunctionDefinition();
    siddhiApp.defineFunction(functionDefinition.id("e1").type(null));
}
Also used : SiddhiApp(io.siddhi.query.api.SiddhiApp) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) FunctionDefinition(io.siddhi.query.api.definition.FunctionDefinition) Test(org.testng.annotations.Test)

Example 18 with SiddhiApp

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

the class PartitionTestCase1 method testPartitionQuery49.

@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery49() {
    log.info("Partition test49");
    SiddhiApp siddhiApp = new SiddhiApp("plan49");
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    siddhiApp.defineStream(streamDefinition);
    FunctionDefinition functionDefinition = new FunctionDefinition();
    siddhiApp.defineFunction(functionDefinition.id("e1").type(Attribute.Type.STRING).body(null));
}
Also used : SiddhiApp(io.siddhi.query.api.SiddhiApp) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) FunctionDefinition(io.siddhi.query.api.definition.FunctionDefinition) Test(org.testng.annotations.Test)

Example 19 with SiddhiApp

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

the class PartitionTestCase1 method testPartitionQuery43.

public void testPartitionQuery43() throws InterruptedException {
    log.info("Partition test43");
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiApp siddhiApp = new SiddhiApp("plan43");
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    siddhiApp.defineStream(streamDefinition);
    Partition partition = Partition.partition().with("cseEventStream", Expression.variable("symbol"));
    Query query = Query.query();
    query.from(InputStream.stream("cseEventStream"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
    query.insertIntoInner("StockStream", OutputStream.OutputEventType.CURRENT_EVENTS);
    Query query1 = Query.query();
    query1.from(InputStream.innerStream("StockStream"));
    query1.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
    query1.insertInto("OutStockStream", OutputStream.OutputEventType.CURRENT_EVENTS);
    partition.addQuery(query);
    partition.addQuery(query1);
    siddhiApp.addPartition(partition);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
    SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertEquals(4, count.get());
}
Also used : Partition(io.siddhi.query.api.execution.partition.Partition) 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) StreamCallback(io.siddhi.core.stream.output.StreamCallback)

Example 20 with SiddhiApp

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

the class PartitionTestCase1 method testPartitionQuery3.

@Test
public void testPartitionQuery3() throws InterruptedException {
    log.info("Partition test3");
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiApp siddhiApp = new SiddhiApp("plan3");
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    siddhiApp.defineStream(streamDefinition);
    Partition partition = Partition.partition().with("cseEventStream", Expression.variable("symbol"));
    Query query = Query.query();
    query.from(InputStream.stream("cseEventStream"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
    query.insertIntoInner("StockStream");
    Query query1 = Query.query();
    query1.from(InputStream.innerStream("StockStream"));
    query1.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
    query1.insertInto("OutStockStream");
    partition.addQuery(query);
    partition.addQuery(query1);
    siddhiApp.addPartition(partition);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
    SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertEquals(4, count.get());
}
Also used : Partition(io.siddhi.query.api.execution.partition.Partition) 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) StreamCallback(io.siddhi.core.stream.output.StreamCallback) 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