Search in sources :

Example 91 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class MaximumFunctionExtensionTestCase method testMaxFunctionExtension10.

@Test
public void testMaxFunctionExtension10() throws InterruptedException {
    log.info("MaximumFunctionExecutor TestCase 10");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "define stream inputStream (price1 long,price2 long, price3 long);";
    String query = ("@info(name = 'query1') from inputStream " + "select maximum(price1, price2, price3) as max " + "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(3675L, event.getData(0));
                        break;
                    case 2:
                        AssertJUnit.assertEquals(3812L, event.getData(0));
                        break;
                    case 3:
                        AssertJUnit.assertEquals(3925L, event.getData(0));
                        break;
                    case 4:
                        AssertJUnit.assertEquals(3775L, event.getData(0));
                        break;
                    case 5:
                        AssertJUnit.assertEquals(3812L, event.getData(0));
                        break;
                    case 6:
                        AssertJUnit.assertEquals(3812L, event.getData(0));
                        break;
                    default:
                        org.junit.Assert.fail();
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 36L, 3675L, 3575L });
    inputHandler.send(new Object[] { 3788L, 3812L, 3762L });
    inputHandler.send(new Object[] { 3900L, 3925L, 3862L });
    inputHandler.send(new Object[] { 3688L, 3775L, 3675L });
    inputHandler.send(new Object[] { 3812L, 3812L, 3775L });
    inputHandler.send(new Object[] { 3812L, 40L, 3775L });
    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 92 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class MaximumFunctionExtensionTestCase method testMaxFunctionExtension5.

@Test
public void testMaxFunctionExtension5() throws InterruptedException {
    log.info("MaximumFunctionExecutor 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 maximum(price1, price2, price3) as max " + "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(74L, event.getData(0));
                        break;
                    case 2:
                        AssertJUnit.assertEquals(78L, event.getData(0));
                        break;
                    case 3:
                        AssertJUnit.assertEquals(39L, 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 93 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class MaximumFunctionExtensionTestCase method testMaxFunctionExtension6.

@Test
public void testMaxFunctionExtension6() throws InterruptedException {
    log.info("MaximumFunctionExecutor TestCase 6");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "define stream inputStream (price1 double,price2 double, price3 double);";
    String query = ("@info(name = 'query1') from inputStream " + "select maximum(*) as max " + "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(36.75, event.getData(0));
                        break;
                    case 2:
                        AssertJUnit.assertEquals(38.12, event.getData(0));
                        break;
                    case 3:
                        AssertJUnit.assertEquals(39.25, event.getData(0));
                        break;
                    case 4:
                        AssertJUnit.assertEquals(37.75, event.getData(0));
                        break;
                    case 5:
                        AssertJUnit.assertEquals(38.12, event.getData(0));
                        break;
                    case 6:
                        AssertJUnit.assertEquals(40.0, event.getData(0));
                        break;
                    default:
                        org.testng.AssertJUnit.fail();
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 36, 36.75, 35.75 });
    inputHandler.send(new Object[] { 37.88, 38.12, 37.62 });
    inputHandler.send(new Object[] { 39.00, 39.25, 38.62 });
    inputHandler.send(new Object[] { 36.88, 37.75, 36.75 });
    inputHandler.send(new Object[] { 38.12, 38.12, 37.75 });
    inputHandler.send(new Object[] { 38.12, 40, 37.75 });
    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 94 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class MinimumFunctionExtensionTestCase method testMinFunctionExtension3.

@Test
public void testMinFunctionExtension3() throws InterruptedException {
    log.info("MinimumFunctionExecutor TestCase 3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "define stream inputStream (price1 int,price2 int, price3 int);";
    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(36, event.getData(0));
                        break;
                    case 2:
                        AssertJUnit.assertEquals(37, event.getData(0));
                        break;
                    case 3:
                        AssertJUnit.assertEquals(9, 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 95 with Event

use of org.wso2.eventing.Event 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)

Aggregations

Test (org.testng.annotations.Test)1150 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1146 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1145 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1119 Event (org.wso2.siddhi.core.event.Event)855 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)587 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)218 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)86 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)79 Query (org.wso2.siddhi.query.api.execution.query.Query)79 ArrayList (java.util.ArrayList)68 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)63 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)38 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)35 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)16 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)16 HashMap (java.util.HashMap)14 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13