Search in sources :

Example 61 with Name

use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.

the class MinimumFunctionExtensionTestCase method testMinFunctionExtension5.

@Test
public void testMinFunctionExtension5() throws InterruptedException {
    log.info("MinimumFunctionExecutor TestCase 5");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "define stream inputStream (price1 long, price2 long, price3 long);";
    String query = ("@info(name = 'query1') from inputStream " + "select minimum(price1, price2, price3) as min " + "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);
            eventArrived = true;
            for (Event event : inEvents) {
                count++;
                switch(count) {
                    case 1:
                        AssertJUnit.assertEquals(36L, event.getData(0));
                        break;
                    case 2:
                        AssertJUnit.assertEquals(37L, event.getData(0));
                        break;
                    case 3:
                        AssertJUnit.assertEquals(9L, event.getData(0));
                        break;
                    default:
                        org.testng.AssertJUnit.fail();
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 36, 38, 74 });
    inputHandler.send(new Object[] { 78, 38, 37 });
    inputHandler.send(new Object[] { 9, 39, 38 });
    Thread.sleep(300);
    AssertJUnit.assertEquals(3, count);
    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 62 with Name

use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.

the class MinimumFunctionExtensionTestCase method testMinFunctionExtensionException7.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testMinFunctionExtensionException7() throws InterruptedException {
    log.info("MinimumFunctionExecutor TestCase 7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "define stream inputStream (price1 double,price2 double, price3 object);";
    String query = ("@info(name = 'query1') from inputStream " + "select minimum(price1, price2, price3) as min " + "insert into outputStream;");
    siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 63 with Name

use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.

the class MinimumFunctionExtensionTestCase method testMinFunctionExtension8.

@Test
public void testMinFunctionExtension8() throws InterruptedException {
    log.info("MinimumFunctionExecutor TestCase 8");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "define stream inputStream (price1 float, price2 float, price3 float);";
    String query = ("@info(name = 'query1') from inputStream " + "select minimum(price1, price2, price3) as min " + "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);
            eventArrived = true;
            for (Event event : inEvents) {
                count++;
                switch(count) {
                    case 1:
                        AssertJUnit.assertEquals(35.75f, event.getData(0));
                        break;
                    case 2:
                        AssertJUnit.assertEquals(37.62f, event.getData(0));
                        break;
                    case 3:
                        AssertJUnit.assertEquals(38.62f, event.getData(0));
                        break;
                    case 4:
                        AssertJUnit.assertEquals(36.75f, event.getData(0));
                        break;
                    case 5:
                        AssertJUnit.assertEquals(37.75f, event.getData(0));
                        break;
                    case 6:
                        AssertJUnit.assertEquals(37.75f, event.getData(0));
                        break;
                    default:
                        org.junit.Assert.fail();
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 36f, 36.75f, 35.75f });
    inputHandler.send(new Object[] { 37.88f, 38.12f, 37.62f });
    inputHandler.send(new Object[] { 39.00f, 39.25f, 38.62f });
    inputHandler.send(new Object[] { 36.88f, 37.75f, 36.75f });
    inputHandler.send(new Object[] { 38.12f, 38.12f, 37.75f });
    inputHandler.send(new Object[] { 38.12f, 40f, 37.75f });
    Thread.sleep(300);
    AssertJUnit.assertEquals(6, count);
    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 64 with Name

use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.

the class MinimumFunctionExtensionTestCase method testMinFunctionExtensionException6.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testMinFunctionExtensionException6() throws InterruptedException {
    log.info("MinimumFunctionExecutor TestCase 6");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "define stream inputStream (price1 object,price2 double, price3 double);";
    String query = ("@info(name = 'query1') from inputStream " + "select minimum(price1, price2, price3) as min " + "insert into outputStream;");
    siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 65 with Name

use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.

the class JoinTestCase method joinTest3.

@Test
public void joinTest3() throws InterruptedException {
    log.info("Join test3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); ";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(500 milliseconds) as a " + "join cseEventStream#window.time(500 milliseconds) as b " + "on a.symbol== b.symbol " + "select a.symbol as symbol, a.price as priceA, b.price as priceB " + "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);
                if (inEvents != null) {
                    inEventCount.addAndGet(inEvents.length);
                }
                if (removeEvents != null) {
                    removeEventCount.getAndAdd(removeEvents.length);
                }
                eventArrived = true;
            }
        });
        InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
        siddhiAppRuntime.start();
        cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
        cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
        SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
        SiddhiTestHelper.waitForEvents(100, 2, removeEventCount, 60000);
        AssertJUnit.assertEquals(2, inEventCount.get());
        AssertJUnit.assertEquals(2, removeEventCount.get());
        AssertJUnit.assertTrue(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)

Aggregations

Test (org.testng.annotations.Test)1322 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1191 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1162 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1118 Event (org.wso2.siddhi.core.event.Event)786 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)585 TestUtil (org.wso2.siddhi.core.TestUtil)298 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)200 ArrayList (java.util.ArrayList)136 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)100 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)82 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)80 Query (org.wso2.siddhi.query.api.execution.query.Query)80 HashMap (java.util.HashMap)76 SQLException (java.sql.SQLException)70 PreparedStatement (java.sql.PreparedStatement)67 API (org.wso2.carbon.apimgt.core.models.API)65 Connection (java.sql.Connection)64 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)64 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)50