Java Code Examples for io.siddhi.core.SiddhiAppRuntime#getTables()

The following examples show how to use io.siddhi.core.SiddhiAppRuntime#getTables() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SandboxTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@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();

}
 
Example 2
Source File: SandboxTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void sandboxTest2() throws InterruptedException {
    log.info("sandbox test2");

    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 ;";

    SiddhiApp siddhiApp = SiddhiCompiler.parse(app);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSandboxSiddhiAppRuntime(siddhiApp);

    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();

}
 
Example 3
Source File: StateTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void stateTest3() throws InterruptedException {
    log.info("stateTest3");

    SiddhiManager siddhiManager = new SiddhiManager();

    String app = "" +
            "" +
            "define table cseEventTable (symbol string, price float, volume int);" +
            "" +
            "@Store(type='testStoreContainingInMemoryTable') " +
            "define table StockTable (symbol string, price float, volume long); " +
            "" +
            "define window cseEventWindow (symbol string, price float, volume int) time(1 sec) " +
            "       output all events; " +
            "" +
            "define trigger triggerStream at every 500 milliseconds ;" +
            "" +
            "define stream cseEventStream (symbol string, price float, volume int);" +
            "define stream twitterStream (user string, tweet string, company string); " +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " +
            "on cseEventStream.symbol== twitterStream.company " +
            "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " +
            "insert all events into outputStream ;" +
            "" +
            "@info(name = 'query2') " +
            "from every ( e1=Stream1[price > 20] -> e2=Stream2[price > e1.price] " +
            "   or e3=Stream2['IBM' == symbol]) -> e4=Stream2[price > e1.price] " +
            "select e1.price as price1, e2.price as price2, e3.price as price3, e4.price as price4 " +
            "insert into OutputStream ;" +
            "";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(app);

    for (QueryRuntime queryRuntime : siddhiAppRuntime.getQueries()) {
        inEventCount++;
        switch (inEventCount) {
            case 1:
                Assert.assertTrue(queryRuntime.isStateful());
                break;
            case 2:
                Assert.assertTrue(queryRuntime.isStateful());
                break;
        }
    }

    for (Table table : siddhiAppRuntime.getTables()) {
        inEventCount++;
        switch (inEventCount) {
            case 3:
                Assert.assertTrue(table.isStateful());
                break;
            case 4:
                Assert.assertFalse(table.isStateful());
                break;
        }
    }

    inEventCount++;
    Assert.assertTrue(siddhiAppRuntime.getWindows().iterator().next().isStateful());

    inEventCount++;
    Assert.assertFalse(siddhiAppRuntime.getTiggers().iterator().next().isStateful());

    Assert.assertEquals(inEventCount, 6);
    siddhiAppRuntime.shutdown();

}