io.siddhi.core.SiddhiManager Java Examples

The following examples show how to use io.siddhi.core.SiddhiManager. 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: DefineTableTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuery18() {
    log.info("testTableDefinition18 - Table w/ ref and additional properties");

    Map<String, String> systemConfigs = new HashMap<>();
    systemConfigs.put("test1.type", "test");
    systemConfigs.put("test1.uri", "http://localhost");
    InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, systemConfigs);
    inMemoryConfigManager.extractSystemConfigs("test1");

    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setConfigManager(inMemoryConfigManager);
    siddhiManager.setExtension("store:test", TestStore.class);
    String siddhiApp = "" +
            "@store(ref='test1', uri='http://localhost:8080', table.name ='Foo')" +
            "define table testTable (symbol string, price int, volume float); ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.shutdown();

    Map<String, String> expectedSystemConfigs = new HashMap<>();
    expectedSystemConfigs.put("type", "test");
    expectedSystemConfigs.put("uri", "http://localhost:8080");
    expectedSystemConfigs.put("table.name", "Foo");
    AssertJUnit.assertEquals("Test store initialization failure", expectedSystemConfigs,
            TestStore.systemConfigs);
}
 
Example #2
Source File: SimpleQueryValidatorTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQueryWithAggregation() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String tables = "define stream TradeStream (symbol string, price double, volume long, timestamp long);\n" +
            "define aggregation TradeAggregation\n" +
            "  from TradeStream\n" +
            "  select symbol, avg(price) as avgPrice, sum(price) as total\n" +
            "    group by symbol\n" +
            "    aggregate by symbol every sec ... year; " +
            "" +
            "from every TradeAggregation \n" +
            "select * \n" +
            "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables);
    siddhiAppRuntime.shutdown();
}
 
Example #3
Source File: ConvertFunctionTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void convertFunctionExceptionTest7() throws InterruptedException {
    log.info("convert function test 7");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL " +
            "long, typeB bool, typeN double) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from typeStream " +
            "select convert(typeS,'234') as valueS, convert(typeF,'float') as valueF, convert(typeD," +
            "'double') as valueD , convert(typeI,'int') as valueI , convert(typeL,'long') as valueL , " +
            "convert(typeB,'bool') as valueB, convert(typeN,'string') as valueN " +
            "insert into outputStream ;";

    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
 
Example #4
Source File: OnDemandQueryTableTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiParserException.class)
public void test6() throws InterruptedException {
    log.info("Test5 table");

    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "define table StockTable (symbol string, price float, volume long); ";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
    try {
        siddhiAppRuntime.start();
        Event[] events = siddhiAppRuntime.query("" +
                "from StockTable1 " +
                "on price > 5 " +
                "select symbol1, sum(volume)  totalVolume " +
                "group by symbol " +
                "having totalVolume >150 ");
        EventPrinter.print(events);
        AssertJUnit.assertEquals(1, events.length);
        AssertJUnit.assertEquals(200L, events[0].getData(1));

    } finally {
        siddhiAppRuntime.shutdown();
    }
}
 
Example #5
Source File: AsyncTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void asyncTest1() throws InterruptedException {
    log.info("async test 1");

    SiddhiManager siddhiManager = new SiddhiManager();

    String siddhiApp = "" +
            "@app:async " +
            "define stream cseEventStream (symbol string, price float, volume int);" +
            "define stream cseEventStream2 (symbol string, price float, volume int);" +
            "" +
            "@info(name = 'query1') " +
            "from cseEventStream[70 > price] " +
            "select * " +
            "insert into outputStream ;" +
            "" +
            "@info(name = 'query2') " +
            "from cseEventStream[volume > 90] " +
            "select * " +
            "insert into outputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);


}
 
Example #6
Source File: MaxAggregatorExtensionTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void minAttributeAggregatorTest2() throws InterruptedException {

    log.info("minAttributeAggregator Test #2");

    SiddhiManager siddhiManager = new SiddhiManager();

    String execPlan = "" +
            "@app:name('minAttributeAggregatorTests') " +
            "" +
            "define stream cseEventStream (weight double, deviceId string);" +
            "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.lengthBatch(5) " +
            "select min(weight, deviceId) as max " +
            "insert into outputStream;";

    SiddhiAppRuntime execPlanRunTime = siddhiManager.createSiddhiAppRuntime(execPlan);
    execPlanRunTime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {

            EventPrinter.print(timestamp, inEvents, removeEvents);
            AssertJUnit.assertEquals(10, inEvents[0].getData()[0]);
        }
    });

    InputHandler inputHandler = execPlanRunTime.getInputHandler("cseEventStream");

    execPlanRunTime.start();
    inputHandler.send(new Object[]{20.0, "Box1"});
    inputHandler.send(new Object[]{30.0, "Box2"});
    inputHandler.send(new Object[]{10.0, "Box3"});
    inputHandler.send(new Object[]{40.0, "Box4"});
    inputHandler.send(new Object[]{50.0, "Box5"});
    Thread.sleep(100);
    execPlanRunTime.shutdown();
}
 
Example #7
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void filterTest117() throws InterruptedException {
    log.info("filter test116");
    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume long);";
    String query = "@info(name = 'query1') from cseEventStream#window.timeBatch(500) select symbol,sum(price)+5 " +
            "as price insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);

    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count.addAndGet(inEvents.length);
            eventArrived.set(true);
            if (count.get() == 1) {
                AssertJUnit.assertEquals(1465.5, inEvents[0].getData()[1]);
            }
        }

    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{"IBM", 700f, 100L});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 200L});
    inputHandler.send(new Object[]{"IBM", 700f, 100L});
    SiddhiTestHelper.waitForEvents(10, 1, count, 1000);
    AssertJUnit.assertEquals(1, count.get());
    AssertJUnit.assertTrue(eventArrived.get());
    siddhiAppRuntime.shutdown();

}
 
Example #8
Source File: LengthBatchWindowTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void lengthBatchWindowTest19() throws InterruptedException {
    log.info("Dynamic value");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.lengthBatch(1/2) " +
            "select symbol,price,volume " +
            "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            AssertJUnit.fail("No events should arrive");
            inEventCount = inEventCount + inEvents.length;
            eventArrived = true;
        }

    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"IBM", 700f, 0});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 1});
    AssertJUnit.assertEquals(0, inEventCount);
    AssertJUnit.assertFalse(eventArrived);
    siddhiAppRuntime.shutdown();
}
 
Example #9
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery91() throws InterruptedException {
    log.info("Filter test91");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE)
            .attribute("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"),
            Compare.Operator.LESS_THAN, Expression.value(15))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")).select("quantity", Expression.variable("quantity")));
    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, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 40d, 10});
    inputHandler.send(new Object[]{"WSO2", 44f, 200d, 56});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    AssertJUnit.assertEquals(2, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #10
Source File: DefineTableTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQuery15() throws InterruptedException {
    log.info("testTableDefinition15 - OUT 0");

    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" +
            "define stream StockStream(symbol string, price int, volume float);" +
            "define table OutputStream (symbol string, price int, volume float); " +
            "" +
            "from OutputStream " +
            "select symbol, price, volume " +
            "insert into StockStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.shutdown();
}
 
Example #11
Source File: AbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent5"})
public void testQueryAbsent6() throws InterruptedException {
    log.info("Test the query not e1, e2 with e1 and e2 after 1 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from not Stream1[price>20] for 1 sec, e2=Stream2[price>30] " +
            "select e2.symbol as symbol " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"IBM"});

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");

    siddhiAppRuntime.start();

    Thread.sleep(100);
    stream1.send(new Object[]{"WSO2", 59.6f, 100});
    Thread.sleep(2100);
    stream2.send(new Object[]{"IBM", 58.7f, 100});

    TestUtil.waitForInEvents(100, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertFalse("Event not arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #12
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testFilterQuery47() throws InterruptedException {
    log.info("Filter test47");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume long);";
    String query = "@info(name = 'query1') from cseEventStream[price or volume >= 50 ] select symbol,price,volume" +
            " insert into outputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
 
Example #13
Source File: StdDevAttributeAggregatorExecutorTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void stdDevAggregatorTest8() throws InterruptedException {

    log.info("stdDevAggregator Test #8");

    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price double, discount int);";
    String execPlan = "@info(name = 'query1') " +
            "from cseEventStream#window.lengthBatch(1) " +
            "select stdDev(price, discount) as deviation " +
            "group by symbol " +
            "insert into outputStream;";

    siddhiManager.createSiddhiAppRuntime(cseEventStream + execPlan);
}
 
Example #14
Source File: AndAggregatorExtensionTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void andAggregatorTest6() throws InterruptedException {

    log.info("andAggregator Test 6");

    SiddhiManager siddhiManager = new SiddhiManager();

    String execPlan = "" +
            "@app:name('andAggregatorTests') " +
            "" +
            "define stream cseEventStream (name string, isFraud bool);" +
            "" +
            "@info(name = 'query1') " +
            "from cseEventStream " +
            "select and(isFraud) as isFraudTransaction " +
            "insert into outputStream;";

    SiddhiAppRuntime execPlanRunTime = siddhiManager.createSiddhiAppRuntime(execPlan);

    log.info("Running: " + execPlanRunTime.getName());

    execPlanRunTime.addCallback("query1", new QueryCallback() {

        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {

            EventPrinter.print(timestamp, inEvents, removeEvents);
            inEventCount++;
        }
    });

    execPlanRunTime.start();
    execPlanRunTime.shutdown();
    AssertJUnit.assertEquals(0, inEventCount);
}
 
Example #15
Source File: LogicalAbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent49"})
public void testQueryAbsent50() throws InterruptedException {
    log.info("Test the query every (not e1 for 1 sec and not e2 for 1 sec), e3 with an e3 after 2 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from every (not Stream1[price>10] for 1 sec and not Stream2[price>20] for 1 sec), " +
            "e3=Stream3[price>30] " +
            "select e3.symbol as symbol " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2"});

    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    siddhiAppRuntime.start();

    Thread.sleep(2100);
    stream3.send(new Object[]{"WSO2", 35.0f, 100});

    TestUtil.waitForInEvents(100, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #16
Source File: LogicalAbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent18"})
public void testQueryAbsent19() throws InterruptedException {
    log.info("Test the query not e1 for 1 sec or e2, e3 with e3 within 1 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from not Stream1[price>10] for 1 sec or e2=Stream2[price>20], e3=Stream3[price>30] " +
            "select e2.symbol as symbol2, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");

    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");

    siddhiAppRuntime.start();

    stream3.send(new Object[]{"GOOGLE", 35.0f, 100});

    TestUtil.waitForInEvents(100, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #17
Source File: EveryAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent17"})
public void testQueryAbsent18() throws InterruptedException {
    log.info("Test the query every not e1 for 1 sec -> e2 -> e3 with e1, e2 e3");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from every not Stream1[price>10] for 1 sec -> e2=Stream2[price>20] -> e3=Stream3[price>30] " +
            "select e2.symbol as symbol2, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");

    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 15.6f, 100});
    Thread.sleep(100);
    stream2.send(new Object[]{"IBM", 28.7f, 100});
    Thread.sleep(100);
    stream3.send(new Object[]{"GOOGLE", 55.7f, 100});
    Thread.sleep(100);

    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #18
Source File: OnDemandQueryTableTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void test7() throws InterruptedException {
    log.info("Test7 table");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long);" +
            "@PrimaryKey('symbol') " +
            "define table StockTable (symbol string, price float, volume long); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from StockStream " +
            "insert into StockTable ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");

    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});
    Thread.sleep(500);

    Event[] events = siddhiAppRuntime.query("" +
            "from StockTable " +
            "on symbol == 'IBM' " +
            "select symbol, volume ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(1, events.length);
    AssertJUnit.assertEquals("IBM", events[0].getData()[0]);
}
 
Example #19
Source File: LengthWindowTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void lengthWindowTest5() throws InterruptedException {
    log.info("Testing length window grater than one parameter");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "@info(name = 'query1') from cseEventStream#window.length(2, price) select symbol,price," +
            "volume insert" +
            " all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            AssertJUnit.assertEquals("Message order inEventCount", inEventCount, inEvents[0].getData(2));
            AssertJUnit.assertEquals("Events cannot be expired", false, inEvents[0].isExpired());
            inEventCount = inEventCount + inEvents.length;
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"IBM", 700f, 0});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 1});
    AssertJUnit.assertEquals(2, inEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
 
Example #20
Source File: PartitionPerformance.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
        SiddhiManager siddhiManager = new SiddhiManager();

        String siddhiApp = "" +
                "define stream cseEventStream (symbol string, price float, volume long);" +
                "" +
                "partition with (symbol of cseEventStream) " +
                "begin " +
                "   @info(name = 'query1') " +
                "   from cseEventStream[700 > price] " +
                "   select * " +
                "   insert into outputStream ;" +
                "end;";

        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
        siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

            @Override
            public void receive(Event[] events) {
//                EventPrinter.print(events);
            }
        });


        InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
        siddhiAppRuntime.start();

        while (true) {
            count++;
            inputHandler.send(new Object[]{"WSO2" + count, 55.6f, 100});
            System.out.println("Partition created :" + count);
        }

    }
 
Example #21
Source File: AbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent2"})
public void testQueryAbsent3() throws InterruptedException {
    log.info("Test the query e1, not e2 sending e2 for 1 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>20], not Stream2[price>e1.price] for 1 sec " +
            "select e1.symbol as symbol1 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");

    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 55.6f, 100});
    Thread.sleep(100);
    stream2.send(new Object[]{"IBM", 58.7f, 100});

    TestUtil.waitForInEvents(500, callback, 10);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #22
Source File: Aggregation1TestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"incrementalStreamProcessorTest35"}, expectedExceptions =
        StoreQueryCreationException.class)
public void incrementalStreamProcessorTest36() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest36");
    SiddhiManager siddhiManager = new SiddhiManager();

    String stockStream =
            "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " +
                    "quantity int, timestamp long);";
    String query = " define aggregation stockAggregation " +
            "from stockStream " +
            "select symbol, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " +
            "as lastTradeValue  " +
            "group by symbol " +
            "aggregate by timestamp every sec...hour ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);

    siddhiAppRuntime.start();
    Thread.sleep(100);

    Event[] events = siddhiAppRuntime.query("from stockAggregation " +
            "within 1513578087000L " +
            "per \"hours\"");
    EventPrinter.print(events);

    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
}
 
Example #23
Source File: CustomJoinWindowTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testWindowAfterWindow() throws InterruptedException {
    log.info("Test traditional window for a stream out of window");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "define window StockWindow (symbol string, price float, volume long) timeBatch(1 sec) output current " +
            "events; ";
    String query = "" +
            "@info(name = 'query0') " +
            "from StockStream " +
            "insert into StockWindow; " +
            "" +
            "@info(name = 'query1') " +
            "from StockWindow#window.lengthBatch(2) " +
            "insert into OutputStream; ";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");

    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});
    Thread.sleep(1100);
    stockStream.send(new Object[]{"IBM", 65.0f, 100L});
    stockStream.send(new Object[]{"WSO2", 50.0f, 100L});
    Thread.sleep(1500);

    siddhiAppRuntime.shutdown();
}
 
Example #24
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void filterTest119() throws InterruptedException {
    log.info("filter test119");
    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume long);";
    String query = "@info(name = 'query1') from cseEventStream select symbol,sum(price)+10 as price group by " +
            "symbol having price > 880 insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);

    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count.addAndGet(inEvents.length);
            eventArrived.set(true);
        }

    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{"IBM", 700f, 100L});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 200L});
    inputHandler.send(new Object[]{"IBM", 700f, 100L});
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    AssertJUnit.assertEquals(1, count.get());
    AssertJUnit.assertTrue(eventArrived.get());
    siddhiAppRuntime.shutdown();

}
 
Example #25
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery14() throws InterruptedException {
    log.info("Filter test14");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume float);";
    String query = "@info(name = 'query1') from cseEventStream[volume > 45] select symbol,price insert into " +
            "outputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);

    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, 60f});
    inputHandler.send(new Object[]{"WSO2", 70f, 40f});
    inputHandler.send(new Object[]{"WSO2", 44f, 200f});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    siddhiAppRuntime.shutdown();


}
 
Example #26
Source File: LogicalAbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent25"})
public void testQueryAbsent26() throws InterruptedException {
    log.info("Test the query e1, (not e2 for 1 sec and not e3 for 1 sec) within 2 sec with e1 and e2");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>10], (not Stream2[price>20] for 1 sec and not Stream3[price>30] for 1 sec) " +
            "within 2 sec " +
            "select e1.symbol as symbol1 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");

    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 15.0f, 100});
    Thread.sleep(100);
    stream2.send(new Object[]{"IBM", 25.0f, 101});

    TestUtil.waitForInEvents(1000, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #27
Source File: DefineTableTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testQuery12() throws InterruptedException {
    log.info("testTableDefinition12 - OUT 0");

    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" +
            "define stream StockStream(symbol string, price int, volume float);" +
            "define table OutputStream (symbol string, price int, volume float); " +
            "" +
            "from StockStream " +
            "select * " +
            "insert into OutputStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.shutdown();
}
 
Example #28
Source File: EveryAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent13"})
public void testQueryAbsent14() throws InterruptedException {
    log.info("Test the query e1 -> e2 -> every not e3 with e1, e2 and not e3 for 1 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>10] -> e2=Stream2[price>20] -> every not Stream3[price>30] for 1 sec " +
            "select e1.symbol as symbol1, e2.symbol as symbol2 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2",
            "IBM"}, new Object[]{"WSO2", "IBM"});

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");

    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 15.6f, 100});
    Thread.sleep(100);
    stream2.send(new Object[]{"IBM", 28.7f, 100});
    Thread.sleep(2100);

    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 2, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
    Thread.sleep(2000);
}
 
Example #29
Source File: TriggerTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testQuery4")
public void testQuery5() throws InterruptedException {
    log.info("testTrigger5 - OUT 1");

    SiddhiManager siddhiManager = new SiddhiManager();

    String plan = "" +
            "define stream cseEventStream (symbol string, price float, volume long);" +
            "define trigger triggerStream at 'start';";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(plan);

    siddhiAppRuntime.addCallback("triggerStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count += events.length;
            eventArrived = true;
        }
    });

    siddhiAppRuntime.start();

    Thread.sleep(100);
    AssertJUnit.assertEquals(1, count);
    AssertJUnit.assertEquals(true, eventArrived);
    siddhiAppRuntime.shutdown();

}
 
Example #30
Source File: LogicalAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent20"})
public void testQueryAbsent21() throws InterruptedException {
    log.info("Test the query e1 -> (not e2 and e3) within 1 sec with e1 and e3 after 1 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>10] -> (not Stream2[price>20] and e3=Stream3[price>30]) within 1 sec " +
            "select e1.symbol as symbol1, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 15.0f, 100});
    Thread.sleep(1100);
    stream3.send(new Object[]{"GOOGLE", 35.0f, 100});
    Thread.sleep(100);

    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}