Search in sources :

Example 71 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class WindowDefinitionTestCase method testEventWindow7.

@Test(expectedExceptions = SiddhiParserException.class)
public void testEventWindow7() throws InterruptedException {
    log.info("WindowDefinitionTestCase Test7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "define window CheckStockWindow(symbol string) output; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
    siddhiAppRuntime.shutdown();
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 72 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class WindowDefinitionTestCase method testEventWindow4.

@Test
public void testEventWindow4() throws InterruptedException {
    log.info("WindowDefinitionTestCase Test4");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "define window CheckStockWindow(symbol string) length(1) output current events; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
    assertTrue(true);
    siddhiAppRuntime.shutdown();
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 73 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest13.

@Test
public void externalTimeBatchWindowTest13() throws InterruptedException {
    log.info("externalTimeBatchWindow Test13");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream cseEventStream (timestamp long, symbol string, price float, volume int); " + "define stream twitterStream (timestamp long, user string, tweet string, company string); ";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.externalTimeBatch(timestamp, 1 sec, 0) join twitterStream#window" + ".externalTimeBatch(timestamp, 1 sec, 0) " + "on cseEventStream.symbol== twitterStream.company " + "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);
                if (inEvents != null) {
                    inEventCount += (inEvents.length);
                }
                if (removeEvents != null) {
                    removeEventCount += (removeEvents.length);
                }
                eventArrived = true;
            }
        });
        InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
        InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
        siddhiAppRuntime.start();
        cseEventStreamHandler.send(new Object[] { 1366335804341L, "WSO2", 55.6f, 100 });
        twitterStreamHandler.send(new Object[] { 1366335804341L, "User1", "Hello World", "WSO2" });
        twitterStreamHandler.send(new Object[] { 1366335805301L, "User2", "Hello World2", "WSO2" });
        cseEventStreamHandler.send(new Object[] { 1366335805341L, "WSO2", 75.6f, 100 });
        cseEventStreamHandler.send(new Object[] { 1366335806541L, "WSO2", 57.6f, 100 });
        Thread.sleep(1000);
        org.testng.AssertJUnit.assertEquals(2, inEventCount);
        org.testng.AssertJUnit.assertEquals(1, removeEventCount);
        org.testng.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)

Example 74 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class ExternalTimeBatchWindowTestCase method test05EdgeCase.

@Test
public void test05EdgeCase() throws Exception {
    siddhiManager = new SiddhiManager();
    // every 10 sec
    SiddhiAppRuntime runtime = simpleQueryRuntime();
    final AtomicInteger recCount = new AtomicInteger(0);
    runtime.addCallback("query", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            AssertJUnit.assertEquals(1, inEvents.length);
            recCount.incrementAndGet();
            double avgCpu = (Double) inEvents[0].getData()[0];
            if (recCount.get() == 1) {
                AssertJUnit.assertEquals(15, avgCpu, 0);
            } else if (recCount.get() == 2) {
                AssertJUnit.assertEquals(85, avgCpu, 0);
            }
            long count = (Long) inEvents[0].getData()[1];
            AssertJUnit.assertEquals(3, count);
        }
    });
    InputHandler input = runtime.getInputHandler("jmxMetric");
    runtime.start();
    // external events' time stamp less than the window, should not have event recieved in call back.
    long now = 0;
    int length = 3;
    for (int i = 0; i < length; i++) {
        input.send(new Object[] { 15, now + i * 10 });
    }
    // if the trigger event mix with the last window, we should see the avgValue is not expected
    for (int i = 0; i < length; i++) {
        // the first entity of the second round
        input.send(new Object[] { 85, now + 10000 + i * 10 });
    }
    // to trigger second round
    input.send(new Object[] { 10000, now + 10 * 10000 });
    // latch.await();// for debug
    Thread.sleep(1000);
    AssertJUnit.assertEquals(2, recCount.get());
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 75 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class LengthBatchWindowTestCase method lengthBatchWindowTest1.

@Test
public void lengthBatchWindowTest1() throws InterruptedException {
    log.info("Testing length batch window with no of events smaller than window size");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(4) " + "select symbol,price,volume " + "insert 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);
            AssertJUnit.fail("No events should arrive");
            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(0, inEventCount);
    AssertJUnit.assertFalse(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)161 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)130 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)130 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)118 Event (org.wso2.siddhi.core.event.Event)117 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)82 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)35 Query (org.wso2.siddhi.query.api.execution.query.Query)32 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)14 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)12 ArrayList (java.util.ArrayList)10 InMemoryPersistenceStore (org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore)10 PersistenceStore (org.wso2.siddhi.core.util.persistence.PersistenceStore)10 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)9 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)9 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)8 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)8 Window (org.wso2.siddhi.core.window.Window)7 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)6 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)6