Search in sources :

Example 6 with Source

use of io.siddhi.core.stream.input.source.Source in project siddhi by wso2.

the class SandboxTestCase method sandboxTest1.

@Test
public void sandboxTest1() throws InterruptedException {
    log.info("sandbox test1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String app = "" + "@source(type='foo')" + "@source(type='foo1')" + "@sink(type='foo1')" + "@source(type='inMemory', topic='myTopic')" + "define stream StockStream (symbol string, price float, vol long);\n" + "" + "@sink(type='foo1')" + "@sink(type='inMemory', topic='myTopic1')" + "define stream DeleteStockStream (symbol string, price float, vol long);\n" + "" + "@store(type='rdbms')" + "define table StockTable (symbol string, price float, volume long);\n" + "" + "define stream CountStockStream (symbol string);\n" + "" + "@info(name = 'query1') " + "from StockStream " + "select symbol, price, vol as volume " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream[vol>=100] " + "delete StockTable " + "   on StockTable.symbol==symbol ;" + "" + "@info(name = 'query3') " + "from CountStockStream#window.length(0) join StockTable" + " on CountStockStream.symbol==StockTable.symbol " + "select CountStockStream.symbol as symbol " + "insert into CountResultsStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSandboxSiddhiAppRuntime(app);
    Assert.assertEquals(siddhiAppRuntime.getSources().size(), 1);
    Assert.assertEquals(siddhiAppRuntime.getSinks().size(), 1);
    Assert.assertEquals(siddhiAppRuntime.getTables().size(), 1);
    for (List<Source> sources : siddhiAppRuntime.getSources()) {
        for (Source source : sources) {
            Assert.assertTrue(source.getType().equalsIgnoreCase("inMemory"));
        }
    }
    for (List<Sink> sinks : siddhiAppRuntime.getSinks()) {
        for (Sink sink : sinks) {
            Assert.assertTrue(sink.getType().equalsIgnoreCase("inMemory"));
        }
    }
    for (Table table : siddhiAppRuntime.getTables()) {
        Assert.assertTrue(table instanceof InMemoryTable);
    }
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream");
    InputHandler countStockStream = siddhiAppRuntime.getInputHandler("CountStockStream");
    siddhiAppRuntime.addCallback("CountResultsStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
        }
    });
    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 });
    deleteStockStream.send(new Object[] { "IBM", 57.6f, 100L });
    countStockStream.send(new Object[] { "WSO2" });
    Thread.sleep(500);
    Assert.assertEquals(count.get(), 2);
    siddhiAppRuntime.shutdown();
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) InputHandler(io.siddhi.core.stream.input.InputHandler) Table(io.siddhi.core.table.Table) InMemoryTable(io.siddhi.core.table.InMemoryTable) Source(io.siddhi.core.stream.input.source.Source) StreamCallback(io.siddhi.core.stream.output.StreamCallback) Sink(io.siddhi.core.stream.output.sink.Sink) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

Source (io.siddhi.core.stream.input.source.Source)6 Sink (io.siddhi.core.stream.output.sink.Sink)4 Table (io.siddhi.core.table.Table)4 Test (org.testng.annotations.Test)3 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)2 SiddhiManager (io.siddhi.core.SiddhiManager)2 Event (io.siddhi.core.event.Event)2 InputHandler (io.siddhi.core.stream.input.InputHandler)2 SourceHandlerManager (io.siddhi.core.stream.input.source.SourceHandlerManager)2 StreamCallback (io.siddhi.core.stream.output.StreamCallback)2 InMemoryTable (io.siddhi.core.table.InMemoryTable)2 AggregationRuntime (io.siddhi.core.aggregation.AggregationRuntime)1 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)1 SiddhiContext (io.siddhi.core.config.SiddhiContext)1 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)1 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)1 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)1 QueryRuntimeImpl (io.siddhi.core.query.QueryRuntimeImpl)1 SingleStreamRuntime (io.siddhi.core.query.input.stream.single.SingleStreamRuntime)1 StreamJunction (io.siddhi.core.stream.StreamJunction)1