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

The following examples show how to use io.siddhi.core.SiddhiAppRuntime#getQueries() . 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: StateTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void stateTest1() throws InterruptedException {
    log.info("stateTest1");

    SiddhiManager siddhiManager = new SiddhiManager();

    String app = "" +
            "define stream cseEventStream (symbol string, price float, volume int);" +
            "" +
            "@info(name = 'query1') " +
            "from cseEventStream " +
            "select * " +
            "insert all events into outputStream;" +
            "" +
            "@info(name = 'query2') " +
            "from cseEventStream#window.timeBatch(1 sec) " +
            "select * " +
            "insert all events into outputStream;" +
            "" +
            "@info(name = 'query3') " +
            "from cseEventStream " +
            "select sum(price) as total " +
            "insert all events into outputStream1;" +
            "" +
            "@info(name = 'query4') " +
            "from cseEventStream " +
            "select * " +
            "output every 5 min " +
            "insert all events into outputStream;" +
            "" +
            "";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(app);

    for (QueryRuntime queryRuntime : siddhiAppRuntime.getQueries()) {
        inEventCount++;
        switch (inEventCount) {
            case 1:
                Assert.assertFalse(queryRuntime.isStateful());
                break;
            case 2:
                Assert.assertTrue(queryRuntime.isStateful());
                break;
            case 3:
                Assert.assertTrue(queryRuntime.isStateful());
                break;
            case 4:
                Assert.assertTrue(queryRuntime.isStateful());
                break;
        }
    }
    Assert.assertEquals(inEventCount, 4);
    siddhiAppRuntime.shutdown();

}
 
Example 2
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();

}