io.siddhi.core.stream.input.InputHandler Java Examples

The following examples show how to use io.siddhi.core.stream.input.InputHandler. 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: LogicalAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent11"})
public void testQueryAbsent12() throws InterruptedException {
    log.info("Test the query e1 -> not e2 for 1 sec or e3 with e1 and e3 with extra 1 sec to make sure no " +
            "duplicates");

    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 or e3=Stream3[price>30] " +
            "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", new Object[]{"WSO2",
            "GOOGLE"});

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

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

    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 #2
Source File: SiddhiSyntaxTest.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimplePlan() throws InterruptedException {
    SiddhiAppRuntime runtime = siddhiManager.createSiddhiAppRuntime(
        "define stream inStream (name string, value double);"
            + "from inStream insert into outStream");
    runtime.start();

    final List<Object[]> received = new ArrayList<>(3);
    InputHandler inputHandler = runtime.getInputHandler("inStream");
    Assert.assertNotNull(inputHandler);

    try {
        runtime.getInputHandler("unknownStream");
        Assert.fail("Should throw exception for getting input handler for unknown streamId.");
    } catch (Exception ex) {
        // Expected exception for getting input handler for illegal streamId.
    }

    runtime.addCallback("outStream", new StreamCallback() {
        @Override
        public void receive(Event[] events) {
            for (Event event : events) {
                received.add(event.getData());
            }
        }
    });

    inputHandler.send(new Object[]{"a", 1.1});
    inputHandler.send(new Object[]{"b", 1.2});
    inputHandler.send(new Object[]{"c", 1.3});
    Thread.sleep(100);
    Assert.assertEquals(3, received.size());
    Assert.assertArrayEquals(received.get(0), new Object[]{"a", 1.1});
    Assert.assertArrayEquals(received.get(1), new Object[]{"b", 1.2});
    Assert.assertArrayEquals(received.get(2), new Object[]{"c", 1.3});
}
 
Example #3
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery75() throws InterruptedException {
    log.info("Filter test75");

    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_EQUAL,
            Expression.value(3L))));
    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", 500f, 60d, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 60d, 2});
    inputHandler.send(new Object[]{"WSO2", 60f, 300d, 4});
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    siddhiAppRuntime.shutdown();

}
 
Example #4
Source File: AbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent34"})
public void testQueryAbsent35() throws InterruptedException {
    log.info("Test the query not e1 for 1 sec, e2<2:5> 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); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from not Stream1[price>10] for 1 sec, e2=Stream2[price>20]<2:5> " +
            "select e2[0].symbol as symbol0, e2[1].symbol as symbol1, e2[2].symbol as symbol2, e2[3].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");


    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 15.0f, 100});
    Thread.sleep(100);
    stream2.send(new Object[]{"GOOGLE", 35.0f, 100});
    Thread.sleep(100);
    stream2.send(new Object[]{"ORACLE", 45.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 #5
Source File: LogicalAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryAbsent1() throws InterruptedException {
    log.info("Test the query e1 -> not e2 and e3 with e1 and 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 e1=Stream1[price>10] -> not Stream2[price>20] and e3=Stream3[price>30] " +
            "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", new Object[]{"WSO2",
            "GOOGLE"});

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

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

    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 #6
Source File: PartitionTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testPartitionQuery35() throws InterruptedException {
    log.info("Partition test34");
    SiddhiManager siddhiManager = new SiddhiManager();

    String siddhiApp = "@app:name('PartitionTest34') " +
            "define stream cseEventStream (atr1 string,  atr2 float, atr3 int, atr4 double, " +
            "atr5 long,  atr6 long,  atr7 double,  atr8 float , atr9 bool, atr10 bool,  atr11 int);"
            + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " +
            "cseEventStream[700>atr5 OR atr8 > atr3 OR atr6 > atr2 OR atr4 " +
            "> atr6 OR atr2 > atr7 OR atr3 > atr4 OR atr4 > atr3 OR atr6 > atr3 OR atr3" +
            "> atr2 OR atr8 > atr5 OR atr6 > atr4 OR atr3 > atr6 OR atr7 > atr8 OR atr7 " +
            "> atr4 OR atr6 > atr5 OR atr11 > atr3 OR atr8 > atr2] select" +
            " atr1 as symbol, sum(atr2) as price" + " insert into " + "OutStockStream ;  end ";


    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, 101.0, 500L, 200L, 102.0, 75.7f, false, true, 105});
    inputHandler.send(new Object[]{"WSO2", 75.6f, 100, 101.0, 501L, 201L, 103.0, 76.7f, false, true, 106});
    inputHandler.send(new Object[]{"IBM", 75.6f, 100, 102.0, 502L, 202L, 104.0, 77.7f, false, true, 107});
    inputHandler.send(new Object[]{"ORACLE", 75.6f, 100, 101.0, 502L, 202L, 104.0, 77.7f, false, true, 108});
    SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
    AssertJUnit.assertEquals(4, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #7
Source File: JoinTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void joinTest5() throws InterruptedException {
    log.info("Join test5");

    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream cseEventStream (symbol string, price float, volume int); " +
            "define stream twitterStream (user string, tweet string, company string); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.length(1) join twitterStream#window.length(1) " +
            "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " +
            "insert all events into outputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {
            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                eventArrived = true;
            }
        });
        InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
        InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
        siddhiAppRuntime.start();
        cseEventStreamHandler.send(new Object[]{"WSO2", 55.6f, 100});
        twitterStreamHandler.send(new Object[]{"User1", "Hello World", "WSO2"});
        cseEventStreamHandler.send(new Object[]{"IBM", 75.6f, 100});
        cseEventStreamHandler.send(new Object[]{"WSO2", 57.6f, 100});
        Thread.sleep(500);
        AssertJUnit.assertTrue(eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
 
Example #8
Source File: AbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent26"})
public void testQueryAbsent27() throws InterruptedException {
    log.info("Test the query not e1, e2 without e1");

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

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

    siddhiAppRuntime.start();

    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 #9
Source File: TimeWindowTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void timeWindowTest3() throws InterruptedException {

    SiddhiManager siddhiManager = new SiddhiManager();


    String queries = "define stream fireAlarmEventStream (deviceID string, sonar double);\n" +
            "@info(name = 'query1')\n" +
            "from fireAlarmEventStream#window.time(30 milliseconds)\n" +
            "select deviceID\n" +
            "insert expired events into analyzeStream;\n" +
            "" +
            "@info(name = 'query2')\n" +
            "from analyzeStream\n" +
            "select deviceID\n" +
            "insert into bulbOnStream;\n";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(queries);

    siddhiAppRuntime.addCallback("analyzeStream", new StreamCallback() {
        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("fireAlarmEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"id1", 20d});
    inputHandler.send(new Object[]{"id2", 20d});
    Thread.sleep(2000);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();

}
 
Example #10
Source File: LengthWindowTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testLengthWindow1() throws InterruptedException {
    log.info("Testing length window with no of events smaller than window size");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " +
            "define window cseWindow (symbol string, price float, volume int) length(4) output all events; ";
    String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow ;" +
            "@info(name = 'query2') from cseWindow insert into outputStream ;";

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

    siddhiAppRuntime.addCallback("query2", 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});
    Thread.sleep(500);
    AssertJUnit.assertEquals(2, inEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();

}
 
Example #11
Source File: InsertIntoTestStoreTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void insertIntoTestStoreTest2() throws InterruptedException, SQLException {
    //Testing table creation with a compound primary key (normal insertion)
    log.info("insertIntoTestStoreTest2");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "@Store(type=\"testStoreContainingInMemoryTable\")\n" +
            "@PrimaryKey(\"symbol\", \"price\")" +
            "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[]{"MSFT", 57.6F, 100L});
    stockStream.send(new Object[]{"WSO2", 58.6F, 100L});
    Thread.sleep(1000);

    Event[] events = siddhiAppRuntime.query("" +
            "from StockTable ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(4, events.length);

    siddhiAppRuntime.shutdown();
}
 
Example #12
Source File: LogicalAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent22"})
public void testQueryAbsent23() throws InterruptedException {
    log.info("Test the query e1 -> (not e2 for 1 sec and e3) within 2 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] for 1 sec and e3=Stream3[price>30]) within 2 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", new Object[]{"WSO2",
            "GOOGLE"});

    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", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #13
Source File: EveryAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent6"})
public void testQueryAbsent7() throws InterruptedException {
    log.info("Test the query e1 -> not e2 sending e2 for 1 sec but without satisfying the filter condition");

    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] -> every 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", new Object[]{"WSO2"},
            new Object[]{"WSO2"});

    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", 50.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 not arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
    Thread.sleep(2000);
}
 
Example #14
Source File: StringListSizeFunctionExtensionTest.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringListSize() throws Exception {
    Semaphore semp = new Semaphore(1);
    String ql = " define stream log(timestamp long, switchLabel string, port string, message string); " +
            " from log select str:listSize(switchLabel) as alertKey insert into output; ";
    SiddhiManager manager = new SiddhiManager();
    SiddhiAppRuntime runtime = manager.createSiddhiAppRuntime(ql);
    runtime.addCallback("output", new StreamCallback() {
        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            Assert.assertTrue(events.length == 1);
            Assert.assertTrue(Integer.parseInt(events[0].getData(0).toString()) == 5);
            semp.release();
        }
    });

    runtime.start();

    InputHandler logInput = runtime.getInputHandler("log");
    semp.acquire();
    Event e = new Event();
    e.setTimestamp(System.currentTimeMillis());
    String ths = "[\"a\", \"b\", \"c\", \"d\", \"e\"]";
    String rhs = "[\"b\", \"d\"]";
    e.setData(new Object[] {System.currentTimeMillis(), ths, "port01", rhs});
    logInput.send(e);

    semp.acquire();
    runtime.shutdown();

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

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" +
            "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 #16
Source File: EveryAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent44"})
public void testQueryAbsent45() throws InterruptedException {
    log.info("Test the query e1 -> every (not e2 for 1 sec and e3) 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] -> every (not Stream2[price>20] for 1 sec and e3=Stream3[price>30]) " +
            "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", new Object[]{"WSO2",
            "GOOGLE"}, new Object[]{"WSO2", "ORACLE"});

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

    siddhiAppRuntime.start();

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

    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();
}
 
Example #17
Source File: LogicalAbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent21"})
public void testQueryAbsent22() throws InterruptedException {
    log.info("Test the query e1, (not e2 and e3) within 1 sec with e1, e2 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 stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");

    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 15.0f, 100});
    Thread.sleep(1100);
    stream2.send(new Object[]{"IBM", 25.0f, 100});
    Thread.sleep(1100);
    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 #18
Source File: PartitionTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testPartitionQuery2() throws InterruptedException {
    log.info("Partition test2");
    SiddhiManager siddhiManager = new SiddhiManager();

    String siddhiApp = "@app:name('PartitionTest2') " +
            "define stream cseEventStream (symbol string, price float,volume int);"
            + "define stream StockStream1 (symbol string, price float,volume int);"
            + "partition with (symbol of cseEventStream , symbol of StockStream1) begin @info(name = 'query1') " +
            "from cseEventStream[700>price] select symbol,sum(price) as price,volume insert into OutStockStream ;" +
            "  end ";


    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);
    AssertJUnit.assertEquals(4, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #19
Source File: PartitionTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testPartitionQuery16() throws InterruptedException {
    log.info("partition test16");
    SiddhiManager siddhiManager = new SiddhiManager();

    String siddhiApp = "@app:name('PartitionTest16') " +
            "define stream streamA (symbol string, price int);"
            + "partition with (symbol of streamA) begin @info(name = 'query1') from streamA select symbol,price " +
            "insert into StockQuote ;"
            + "@info(name = 'query2') from streamA select symbol,price insert into StockQuote ; end ";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

    siddhiAppRuntime.addCallback("StockQuote", new StreamCallback() {
        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"IBM", 700});
    inputHandler.send(new Object[]{"WSO2", 60});
    inputHandler.send(new Object[]{"WSO2", 60});
    SiddhiTestHelper.waitForEvents(100, 6, count, 60000);
    AssertJUnit.assertEquals(6, count.get());
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
 
Example #20
Source File: InputEventHandler.java    From siddhi with Apache License 2.0 5 votes vote down vote up
InputEventHandler(InputHandler inputHandler, List<AttributeMapping> transportMapping,
                  ThreadLocal<Object[]> trpProperties, ThreadLocal<String[]> trpSyncProperties, String sourceType,
                  LatencyTracker latencyTracker, SiddhiAppContext siddhiAppContext,
                  InputEventHandlerCallback inputEventHandlerCallback) {
    this.inputHandler = inputHandler;
    this.transportMapping = transportMapping;
    this.trpProperties = trpProperties;
    this.trpSyncProperties = trpSyncProperties;
    this.sourceType = sourceType;
    this.latencyTracker = latencyTracker;
    this.siddhiAppContext = siddhiAppContext;
    this.inputEventHandlerCallback = inputEventHandlerCallback;
    this.timestampGenerator = siddhiAppContext.getTimestampGenerator();
}
 
Example #21
Source File: OuterJoinTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void joinTest6() throws InterruptedException {
    log.info("Outer Join test6");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "define stream cseEventStream (symbol string, price float, volume int); " +
            "define stream twitterStream (user string, tweet string, company string); ";
    String query = "@info(name = 'query1') " +
            "from cseEventStream#window.length(2) right outer join twitterStream " +
            "on cseEventStream.symbol== twitterStream.company " +
            "select cseEventStream.symbol as symbol, twitterStream.tweet " +
            "insert all events into outputStream ;";

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

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

    });

    InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    cseEventStreamHandler.send(new Object[]{"IBM", 57.6f, 100});
    cseEventStreamHandler.send(new Object[]{"WSO2", 57.6f, 100});
    Thread.sleep(500);
    AssertJUnit.assertFalse(eventArrived);
    siddhiAppRuntime.shutdown();
}
 
Example #22
Source File: SetUpdateInMemoryTableTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void updateFromTableTest4() throws InterruptedException, SQLException {
    log.info("SET-RDBMS-update test case 4: using one of the output attribute values in the " +
            "select clause as the assignment expression.");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "define stream UpdateStockStream (symbol string, price float, volume long); " +
            "define table StockTable (symbol string, price float, volume long); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from StockStream " +
            "insert into StockTable ;" +
            "" +
            "@info(name = 'query2') " +
            "from UpdateStockStream " +
            "select price + 100 as newPrice , symbol " +
            "update StockTable " +
            "set StockTable.price = newPrice " +
            "   on StockTable.symbol == symbol ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
    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});
    updateStockStream.send(new Object[]{"IBM", 100f, 100L});
    Thread.sleep(1000);

    siddhiAppRuntime.shutdown();
}
 
Example #23
Source File: LogicalAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent12"})
public void testQueryAbsent13() throws InterruptedException {
    log.info("Test the query e1 -> not e2 for 1 sec or e3 with e1 only with 1 sec waiting");

    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 or e3=Stream3[price>30] " +
            "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", new Object[]{"WSO2",
            null});

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

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

    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 #24
Source File: LogicalAbsentPatternTestCase.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 not e1 and e2 -> e3 with e2 and 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] and 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", new Object[]{"IBM",
            "GOOGLE"});

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

    stream2.send(new Object[]{"IBM", 25.0f, 100});
    Thread.sleep(100);
    stream3.send(new Object[]{"GOOGLE", 35.0f, 100});
    Thread.sleep(100);

    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 #25
Source File: AbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent36"})
public void testQueryAbsent37() throws InterruptedException {
    log.info("Test the query not e1 for 1 sec -> e2 with e2 only");

    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>10] for 1 sec -> e2=Stream2[price>20] " +
            "select e2.symbol as symbol " +
            "insert into OutputStream ;";

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

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

    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    siddhiAppRuntime.start();
    Thread.sleep(2100);
    stream2.send(new Object[]{"WSO2", 35.0f, 100});
    Thread.sleep(100);
    stream2.send(new Object[]{"IBM", 45.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 #26
Source File: EveryAbsentPatternTestCase.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 every not e1 for 1 sec -> e2 -> e3 with e2 and 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", new Object[]{"IBM",
            "GOOGLE"}, new Object[]{"IBM", "GOOGLE"});

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

    siddhiAppRuntime.start();

    Thread.sleep(2100);
    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", 2, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

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

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

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.not(Expression.compare(Expression.variable
            ("volume"), Compare.Operator.EQUAL, Expression.value(40)))));
    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, 60L});
    inputHandler.send(new Object[]{"WSO2", 70f, 40L});
    inputHandler.send(new Object[]{"WSO2", 44f, 200L});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    siddhiAppRuntime.shutdown();

}
 
Example #28
Source File: AbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent10"})
public void testQueryAbsent11() throws InterruptedException {
    log.info("Test the query e1, e2, 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], 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"});

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

    TestUtil.waitForInEvents(1000, 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 #29
Source File: LogSinkTest.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithDefaultPrefix() throws Exception {
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "@App:name(\"HelloWorldApp\")\n" +
            "define stream CargoStream (weight int);";
    String outputStream = "@sink(type='log',  priority='info')\n" +
            "define stream OutputStream(weight int, totalWeight long);";

    String query = (
            "@info(name='HelloWorldQuery') " +
                    "from CargoStream " +
                    "select weight, sum(weight) as totalWeight " +
                    "insert into OutputStream;");

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + outputStream + query);

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

    Logger logger = Logger.getLogger(LogSink.class);
    UnitTestAppender appender = new UnitTestAppender();
    logger.addAppender(appender);
    try {
        inputHandler.send(new Object[]{2});
        AssertJUnit.assertTrue(appender.getMessages().contains("HelloWorldApp : OutputStream"));
        AssertJUnit.assertTrue(appender.getMessages().contains("data=[2, 2]"));
        inputHandler.send(new Object[]{3});
        AssertJUnit.assertTrue(appender.getMessages().contains("HelloWorldApp : OutputStream"));
        AssertJUnit.assertTrue(appender.getMessages().contains("data=[3, 5]"));
    } catch (Exception e) {
        Assert.fail("Unexpected exception occurred when testing with default prefix", e);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
 
Example #30
Source File: QueryAPITestCaseForTestStore.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = StoreQueryCreationException.class)
public void test4() throws InterruptedException {
    log.info("Test4 table with cache");

    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "@Store(type=\"testStoreContainingInMemoryTable\")\n" +
            "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);
    try {
        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 StockTabled " +
                "on price > 5 " +
                "select symbol1, sum(volume) as totalVolume " +
                "group by symbol " +
                "having totalVolume >150 ");
        EventPrinter.print(events);
        AssertJUnit.assertEquals(1, events.length);
        AssertJUnit.assertEquals(400L, events[0].getData(1));

    } finally {
        siddhiAppRuntime.shutdown();
    }
}