Search in sources :

Example 26 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class CastFunctionExecutorTestCase method testCastFunctionExtension8.

@Test
public void testCastFunctionExtension8() throws InterruptedException {
    log.info("CastFunctionExecutor TestCase 8");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "\ndefine stream inputStream (symbol object, price object, volume long);";
    String query = ("@info(name = 'query1') from inputStream select symbol,price, " + "cast(symbol, 'string') as symbolInString insert into outputStream;");
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            for (Event event : inEvents) {
                count.incrementAndGet();
                if (count.get() == 1) {
                    AssertJUnit.assertEquals("IBM", event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 2) {
                    AssertJUnit.assertEquals("WSO2", event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 3) {
                    AssertJUnit.assertEquals("XYZ", event.getData(0));
                    eventArrived = true;
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 1003453L, 100L });
    inputHandler.send(new Object[] { "WSO2", true, 200L });
    inputHandler.send(new Object[] { "XYZ", 30043253L, 200L });
    SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
    AssertJUnit.assertEquals(3, count.get());
    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 InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class ExternalTimeBatchWindowTestCase method testExternalTimeBatchWindow17.

@Test
public void testExternalTimeBatchWindow17() throws InterruptedException {
    log.info("ExternalTimeBatchWindow test17");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "define stream inputStream(currentTime long,value int); " + "define window inputWindow(currentTime long,value int) externalTimeBatch(currentTime,5 sec,1200); ";
    String query = " " + "@info(name = 'query0') " + "from inputStream " + "insert into inputWindow; " + "" + "@info(name='query') " + "from inputWindow " + "select value " + "insert into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query);
    siddhiAppRuntime.addCallback("query", new QueryCallback() {

        int count = 0;

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            if (count == 0) {
                assertEquals(0L, inEvents[0].getData(0));
                assertEquals(11L, inEvents[inEvents.length - 1].getData(0));
            }
            if (count == 1) {
                assertEquals(12L, inEvents[0].getData(0));
            }
            count += 1;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    for (long i = 0; i < 10000; i += 100) {
        inputHandler.send(new Object[] { i + 10000, i / 100 });
        Thread.sleep(200);
    }
}
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 InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class ExternalTimeBatchWindowTestCase method testExternalTimeBatchWindow18.

@Test
public void testExternalTimeBatchWindow18() throws InterruptedException {
    log.info("ExternalTimeBatchWindow test18");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "define stream inputStream(currentTime long,value int); " + "define window inputWindow(currentTime long,value int) externalTimeBatch(currentTime,5 sec, 0, 6 sec)" + " output current events; ";
    String query = " " + "@info(name = 'query0') " + "from inputStream " + "insert into inputWindow; " + "" + "@info(name='query') " + "from inputWindow " + "select value, currentTime " + "insert into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query);
    siddhiAppRuntime.addCallback("query", new QueryCallback() {

        int count = 0;

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            if (count == 0) {
                assertEquals(1, inEvents[0].getData(0));
            } else if (count == 1) {
                assertEquals(6, inEvents[0].getData(0));
            } else if (count == 2) {
                assertEquals(11, inEvents[0].getData(0));
            } else if (count == 3) {
                assertEquals(14, inEvents[0].getData(0));
            } else if (count == 4) {
                assertEquals(15, inEvents[0].getData(0));
            }
            count += 1;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 10000L, 1 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 11000L, 2 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 12000L, 3 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 13000L, 4 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 14000L, 5 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 15000L, 6 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 16500L, 7 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 17000L, 8 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 18000L, 9 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 19000L, 10 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 20100L, 11 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 20500L, 12 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 22000L, 13 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 25000L, 14 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 32000L, 15 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 33000L, 16 });
    Thread.sleep(6000);
}
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 InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class ExternalTimeBatchWindowTestCase method schedulerLastBatchTriggerTest.

@Test
public void schedulerLastBatchTriggerTest() throws InterruptedException {
    siddhiManager = new SiddhiManager();
    String inputStream = "define stream inputStream(currentTime long,value int); ";
    String query = " " + "@info(name='query') " + "from inputStream#window.externalTimeBatch(currentTime,5 sec, 0, 6 sec) " + "select value, currentTime " + "insert current events into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query);
    siddhiAppRuntime.addCallback("query", new QueryCallback() {

        int count = 0;

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            if (count == 0) {
                AssertJUnit.assertEquals(1, inEvents[0].getData(0));
            } else if (count == 1) {
                AssertJUnit.assertEquals(6, inEvents[0].getData(0));
            } else if (count == 2) {
                AssertJUnit.assertEquals(11, inEvents[0].getData(0));
            } else if (count == 3) {
                AssertJUnit.assertEquals(14, inEvents[0].getData(0));
            } else if (count == 4) {
                AssertJUnit.assertEquals(15, inEvents[0].getData(0));
            }
            count += 1;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 10000L, 1 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 11000L, 2 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 12000L, 3 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 13000L, 4 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 14000L, 5 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 15000L, 6 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 16500L, 7 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 17000L, 8 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 18000L, 9 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 19000L, 10 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 20100L, 11 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 20500L, 12 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 22000L, 13 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 25000L, 14 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 32000L, 15 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 33000L, 16 });
    Thread.sleep(6000);
}
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 InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class ExternalTimeBatchWindowTestCase method test2.

@Test
public void test2() throws InterruptedException {
    siddhiManager = new SiddhiManager();
    String inputStream = "define stream inputStream(currentTime long,value int); ";
    String query = " @info(name='query') " + "from inputStream#window.externalTimeBatch(currentTime,5 sec,1200) " + "select value " + "insert into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query);
    siddhiAppRuntime.addCallback("query", new QueryCallback() {

        int count = 0;

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (count == 0) {
                AssertJUnit.assertEquals(0L, inEvents[0].getData(0));
                AssertJUnit.assertEquals(11L, inEvents[inEvents.length - 1].getData(0));
            }
            if (count == 1) {
                AssertJUnit.assertEquals(12L, inEvents[0].getData(0));
            }
            count += 1;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    for (long i = 0; i < 10000; i += 100) {
        inputHandler.send(new Object[] { i + 10000, i / 100 });
        Thread.sleep(200);
    }
}
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)80 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)67 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)58 InputStream (java.io.InputStream)54 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)54 Event (org.wso2.siddhi.core.event.Event)48 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)47 IOException (java.io.IOException)32 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)20 API (org.wso2.carbon.apimgt.core.models.API)18 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)17 FileInputStream (java.io.FileInputStream)15 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)13 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)12 Response (javax.ws.rs.core.Response)11 HashMap (java.util.HashMap)9 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 File (java.io.File)7 Connection (java.sql.Connection)7