Search in sources :

Example 26 with And

use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.

the class PlaybackTestCase method playbackTest5.

@Test
public void playbackTest5() throws InterruptedException {
    log.info("Playback Test 5: Playback enabled timeLength window with no of events less than window length and " + "time period less than window time");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "@app:playback define stream cseEventStream (symbol string, price float, volume int);";
    String query = "@info(name = 'query1') from cseEventStream#window.timeLength(4 sec,10) 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);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount);
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    long timestamp = System.currentTimeMillis();
    inputHandler.send(timestamp, new Object[] { "IBM", 700f, 1 });
    timestamp += 500;
    inputHandler.send(timestamp, new Object[] { "WSO2", 60.5f, 2 });
    timestamp += 500;
    inputHandler.send(timestamp, new Object[] { "IBM", 700f, 3 });
    timestamp += 500;
    inputHandler.send(timestamp, new Object[] { "WSO2", 60.5f, 4 });
    timestamp += 5000;
    inputHandler.send(timestamp, new Object[] { "GOOGLE", 90.5f, 5 });
    AssertJUnit.assertEquals(5, inEventCount);
    AssertJUnit.assertEquals(4, removeEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 27 with And

use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.

the class AggregationTestCase method incrementalStreamProcessorTest7.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest6" })
public void incrementalStreamProcessorTest7() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp string);";
    String query = "" + "@BufferSize('3') " + "@IgnoreEventsOlderThanBuffer('true')" + "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...year; " + "define stream inputStream (symbol string, value int, startTime string, " + "endTime string, perValue string); " + "@info(name = 'query1') " + "from inputStream as i join stockAggregation as s " + "on i.symbol == s.symbol " + "within \"2017-06-01 09:35:00 +05:30\", \"2017-06-01 10:37:57 +05:30\" " + "per i.perValue " + "select s.symbol, avgPrice, totalPrice as sumPrice, lastTradeValue  " + "insert all events into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
    try {
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                if (inEvents != null) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    for (Event event : inEvents) {
                        inEventsList.add(event.getData());
                        inEventCount.incrementAndGet();
                    }
                    eventArrived = true;
                }
                if (removeEvents != null) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    for (Event event : removeEvents) {
                        removeEventsList.add(event.getData());
                        removeEventCount.incrementAndGet();
                    }
                }
                eventArrived = true;
            }
        });
        InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
        InputHandler inputStreamInputHandler = siddhiAppRuntime.getInputHandler("inputStream");
        siddhiAppRuntime.start();
        // Thursday, June 1, 2017 4:05:50 AM (add 5.30 to get corresponding IST time)
        stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:51 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 50f, 60f, 90L, 6, "2017-06-01 04:05:51" });
        // Thursday, June 1, 2017 4:05:52 AM
        stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 56, "2017-06-01 04:05:52" });
        stockStreamInputHandler.send(new Object[] { "WSO2", 100f, null, 200L, 16, "2017-06-01 04:05:52" });
        // Thursday, June 1, 2017 4:05:50 AM (out of order. must be processed with 1st event for 50th second)
        stockStreamInputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:54 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 26, "2017-06-01 04:05:54" });
        stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 96, "2017-06-01 04:05:54" });
        // Thursday, June 1, 2017 4:05:50 AM (out of order. should not be processed since events for 50th second is
        // no longer in the buffer and @IgnoreEventsOlderThanBuffer is true)
        stockStreamInputHandler.send(new Object[] { "IBM", 50f, 60f, 90L, 6, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 900f, null, 200L, 60, "2017-06-01 04:05:56" });
        stockStreamInputHandler.send(new Object[] { "IBM", 500f, null, 200L, 7, "2017-06-01 04:05:56" });
        // Thursday, June 1, 2017 4:06:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 400f, null, 200L, 9, "2017-06-01 04:06:56" });
        // Thursday, June 1, 2017 4:07:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 600f, null, 200L, 6, "2017-06-01 04:07:56" });
        // Thursday, June 1, 2017 5:07:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 700f, null, 200L, 20, "2017-06-01 05:07:56" });
        Thread.sleep(100);
        inputStreamInputHandler.send(new Object[] { "IBM", 1, "2017-06-01 09:35:51 +05:30", "2017-06-01 09:35:52 +05:30", "minutes" });
        Thread.sleep(100);
        List<Object[]> expected = Arrays.asList(new Object[] { "IBM", 330.0, 1650.0, 3500f }, new Object[] { "IBM", 400.0, 400.0, 3600f }, new Object[] { "IBM", 700.0, 700.0, 14000f }, new Object[] { "IBM", 600.0, 600.0, 3600f });
        SiddhiTestHelper.waitForEvents(100, 4, inEventCount, 60000);
        AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected));
        AssertJUnit.assertEquals("Remove events matched", true, SiddhiTestHelper.isEventsMatch(removeEventsList, expected));
        AssertJUnit.assertEquals("Number of success events", 4, inEventCount.get());
        AssertJUnit.assertEquals("Number of remove events", 4, removeEventCount.get());
        AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 28 with And

use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.

the class AggregationTestCase method incrementalStreamProcessorTest39.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest38" })
public void incrementalStreamProcessorTest39() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest39");
    SiddhiManager siddhiManager = new SiddhiManager();
    String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp string);";
    String query = "" + "@BufferSize('3') " + "@IgnoreEventsOlderThanBuffer('true')" + "define aggregation stockAggregation " + "from stockStream " + "select avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue  " + "aggregate by timestamp every sec...year; " + "define stream inputStream (symbol string, value int, startTime string, " + "endTime string, perValue string); " + "@info(name = 'query1') " + "from inputStream join stockAggregation " + "within \"2017-06-01 04:05:49\", \"2017-06-01 05:07:57\" " + "per \"seconds\" " + "select AGG_TIMESTAMP, avgPrice, totalPrice as sumPrice, lastTradeValue  " + "order by AGG_TIMESTAMP " + "insert all events into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
    try {
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                if (inEvents != null) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    for (Event event : inEvents) {
                        inEventsList.add(event.getData());
                        inEventCount.incrementAndGet();
                    }
                    eventArrived = true;
                }
                if (removeEvents != null) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    for (Event event : removeEvents) {
                        removeEventsList.add(event.getData());
                        removeEventCount.incrementAndGet();
                    }
                }
                eventArrived = true;
            }
        });
        InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
        InputHandler inputStreamInputHandler = siddhiAppRuntime.getInputHandler("inputStream");
        siddhiAppRuntime.start();
        // Thursday, June 1, 2017 4:05:50 AM (add 5.30 to get corresponding IST time)
        stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:51 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 50f, 60f, 90L, 6, "2017-06-01 04:05:51" });
        // Thursday, June 1, 2017 4:05:47 AM (out of order. Should not be processed since it's not within
        // the buffer of 3 [since the latest max in buffer is for 51st second, we can hold seconds 48, 49,
        // 50, 51 only)
        stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 56, "2017-06-01 04:05:47" });
        // Thursday, June 1, 2017 4:05:49 AM (out of order. Should be processed since it's within the buffer of 3)
        stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 56, "2017-06-01 04:05:49" });
        // Thursday, June 1, 2017 4:05:52 AM
        stockStreamInputHandler.send(new Object[] { "WSO2", 100f, null, 200L, 16, "2017-06-01 04:05:52" });
        // Thursday, June 1, 2017 4:05:50 AM (out of order. must be processed with 1st event for 50th second)
        stockStreamInputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:53 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 26, "2017-06-01 04:05:53" });
        // Thursday, June 1, 2017 4:05:50 AM (out of order. should be processed with 50th second data)
        stockStreamInputHandler.send(new Object[] { "IBM", 50f, 60f, 90L, 6, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:54 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 96, "2017-06-01 04:05:54" });
        // Thursday, June 1, 2017 4:05:50 AM (out of order. should not be processed since events for 50th second is
        // no longer in the buffer and @IgnoreEventsOlderThanBuffer is true)
        stockStreamInputHandler.send(new Object[] { "IBM", 50f, 60f, 90L, 6, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 900f, null, 200L, 60, "2017-06-01 04:05:56" });
        stockStreamInputHandler.send(new Object[] { "IBM", 500f, null, 200L, 7, "2017-06-01 04:05:56" });
        // Thursday, June 1, 2017 4:06:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 400f, null, 200L, 9, "2017-06-01 04:06:56" });
        // Thursday, June 1, 2017 4:07:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 600f, null, 200L, 6, "2017-06-01 04:07:56" });
        // Thursday, June 1, 2017 5:07:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 700f, null, 200L, 20, "2017-06-01 05:07:56" });
        Thread.sleep(100);
        inputStreamInputHandler.send(new Object[] { "IBM", 1, "2017-06-01 09:35:51 +05:30", "2017-06-01 09:35:52 +05:30", "seconds" });
        Thread.sleep(100);
        List<Object[]> expected = Arrays.asList(new Object[] { 1496289949000L, 60.0, 60.0, 3360f }, new Object[] { 1496289950000L, 56.666666666666664, 170.0, 300f }, new Object[] { 1496289951000L, 50.0, 50.0, 300f }, new Object[] { 1496289952000L, 100.0, 100.0, 1600f }, new Object[] { 1496289953000L, 100.0, 100.0, 2600f }, new Object[] { 1496289954000L, 100.0, 100.0, 9600f }, new Object[] { 1496289956000L, 700.0, 1400.0, 3500f }, new Object[] { 1496290016000L, 400.0, 400.0, 3600f }, new Object[] { 1496290076000L, 600.0, 600.0, 3600f }, new Object[] { 1496293676000L, 700.0, 700.0, 14000f });
        SiddhiTestHelper.waitForEvents(100, 10, inEventCount, 60000);
        AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected));
        AssertJUnit.assertEquals("Remove events matched", true, SiddhiTestHelper.isEventsMatch(removeEventsList, expected));
        AssertJUnit.assertEquals("Number of success events", 10, inEventCount.get());
        AssertJUnit.assertEquals("Number of remove events", 10, removeEventCount.get());
        AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 29 with And

use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.

the class AggregationTestCase method incrementalStreamProcessorTest38.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest37" })
public void incrementalStreamProcessorTest38() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest38");
    SiddhiManager siddhiManager = new SiddhiManager();
    String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp string);";
    String query = "" + "@BufferSize('3') " + "@IgnoreEventsOlderThanBuffer('true')" + "define aggregation stockAggregation " + "from stockStream " + "select avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue  " + "aggregate by timestamp every sec...year; " + "define stream inputStream (symbol string, value int, startTime string, " + "endTime string, perValue string); " + "@info(name = 'query1') " + "from inputStream join stockAggregation " + "within \"2017-06-01 09:35:00 +05:30\", \"2017-06-01 10:37:57 +05:30\" " + "per perValue " + "select avgPrice, totalPrice as sumPrice, lastTradeValue  " + "insert all events into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
    try {
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                if (inEvents != null) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    for (Event event : inEvents) {
                        inEventsList.add(event.getData());
                        inEventCount.incrementAndGet();
                    }
                    eventArrived = true;
                }
                if (removeEvents != null) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    for (Event event : removeEvents) {
                        removeEventsList.add(event.getData());
                        removeEventCount.incrementAndGet();
                    }
                }
                eventArrived = true;
            }
        });
        InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
        InputHandler inputStreamInputHandler = siddhiAppRuntime.getInputHandler("inputStream");
        siddhiAppRuntime.start();
        // Thursday, June 1, 2017 4:05:50 AM (add 5.30 to get corresponding IST time)
        stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:51 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 50f, 60f, 90L, 6, "2017-06-01 04:05:51" });
        // Thursday, June 1, 2017 4:05:52 AM
        stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 56, "2017-06-01 04:05:52" });
        stockStreamInputHandler.send(new Object[] { "WSO2", 100f, null, 200L, 16, "2017-06-01 04:05:52" });
        // Thursday, June 1, 2017 4:05:50 AM (out of order. must be processed with 1st event for 50th second)
        stockStreamInputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:54 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 26, "2017-06-01 04:05:54" });
        stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 96, "2017-06-01 04:05:54" });
        // Thursday, June 1, 2017 4:05:50 AM (out of order. should not be processed since events for 50th second is
        // no longer in the buffer and @IgnoreEventsOlderThanBuffer is true)
        stockStreamInputHandler.send(new Object[] { "IBM", 50f, 60f, 90L, 6, "2017-06-01 04:05:50" });
        // Thursday, June 1, 2017 4:05:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 900f, null, 200L, 60, "2017-06-01 04:05:56" });
        stockStreamInputHandler.send(new Object[] { "IBM", 500f, null, 200L, 7, "2017-06-01 04:05:56" });
        // Thursday, June 1, 2017 4:06:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 400f, null, 200L, 9, "2017-06-01 04:06:56" });
        // Thursday, June 1, 2017 4:07:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 600f, null, 200L, 6, "2017-06-01 04:07:56" });
        // Thursday, June 1, 2017 5:07:56 AM
        stockStreamInputHandler.send(new Object[] { "IBM", 700f, null, 200L, 20, "2017-06-01 05:07:56" });
        Thread.sleep(100);
        inputStreamInputHandler.send(new Object[] { "IBM", 1, "2017-06-01 09:35:51 +05:30", "2017-06-01 09:35:52 +05:30", "minutes" });
        Thread.sleep(100);
        List<Object[]> expected = Arrays.asList(new Object[] { 214.44444444444446, 1930.0, 3500f }, new Object[] { 400.0, 400.0, 3600f }, new Object[] { 700.0, 700.0, 14000f }, new Object[] { 600.0, 600.0, 3600f });
        SiddhiTestHelper.waitForEvents(100, 4, inEventCount, 60000);
        AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected));
        AssertJUnit.assertEquals("Remove events matched", true, SiddhiTestHelper.isEventsMatch(removeEventsList, expected));
        AssertJUnit.assertEquals("Number of success events", 4, inEventCount.get());
        AssertJUnit.assertEquals("Number of remove events", 4, removeEventCount.get());
        AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 30 with And

use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.

the class ComplexPatternTestCase method testQuery3.

@Test
public void testQuery3() throws InterruptedException {
    log.info("testPatternComplex3 - OUT 3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream Stream1 (symbol string, price float, volume int); ";
    String query = "" + "@info(name = 'query1') " + "from every e1 = Stream1 [ price >= 50 and volume > 100 ] -> e2 = Stream1 [price <= 40 ] <2:> -> e3 =" + " Stream1 [volume <= 70 ] " + "select e1.symbol as symbol1, e2[last].symbol as symbol2, e3.symbol as symbol3 " + "insert into StockQuote;";
    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);
            if (inEvents != null) {
                for (Event event : inEvents) {
                    inEventCount++;
                    switch(inEventCount) {
                        case 1:
                            AssertJUnit.assertArrayEquals(new Object[] { "IBM", "FB", "WSO2" }, event.getData());
                            break;
                        case 2:
                            AssertJUnit.assertArrayEquals(new Object[] { "ADP", "WSO2", "AMZN" }, event.getData());
                            break;
                        case 3:
                            AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "QQQ", "CSCO" }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(3, inEventCount);
                    }
                }
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "IBM", 75.6f, 105 });
    Thread.sleep(100);
    stream1.send(new Object[] { "GOOG", 39.8f, 91 });
    stream1.send(new Object[] { "FB", 35f, 81 });
    stream1.send(new Object[] { "WSO2", 21f, 61 });
    stream1.send(new Object[] { "ADP", 50f, 101 });
    stream1.send(new Object[] { "GOOG", 41.2f, 90 });
    stream1.send(new Object[] { "FB", 40f, 100 });
    stream1.send(new Object[] { "WSO2", 33.6f, 85 });
    stream1.send(new Object[] { "AMZN", 23.5f, 55 });
    stream1.send(new Object[] { "WSO2", 51.7f, 180 });
    stream1.send(new Object[] { "TXN", 34f, 61 });
    stream1.send(new Object[] { "QQQ", 24.6f, 45 });
    stream1.send(new Object[] { "CSCO", 181.6f, 40 });
    stream1.send(new Object[] { "WSO2", 53.7f, 200 });
    Thread.sleep(100);
    AssertJUnit.assertEquals("Number of success events", 3, inEventCount);
    AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)409 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)337 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)336 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)327 TestUtil (org.wso2.siddhi.core.TestUtil)204 Event (org.wso2.siddhi.core.event.Event)119 ArrayList (java.util.ArrayList)110 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)86 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)77 HashMap (java.util.HashMap)61 PreparedStatement (java.sql.PreparedStatement)55 SQLException (java.sql.SQLException)51 IOException (java.io.IOException)45 Connection (java.sql.Connection)45 ActivityInterface (org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface)44 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)43 API (org.wso2.carbon.apimgt.core.models.API)39 ResultSet (java.sql.ResultSet)35 Map (java.util.Map)33 CharonException (org.wso2.charon3.core.exceptions.CharonException)33