Search in sources :

Example 11 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project siddhi by wso2.

the class PlaybackTestCase method playbackTest3.

@Test
public void playbackTest3() throws InterruptedException {
    log.info("Playback Test 3: Playback with heartbeat enabled");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "@app:playback(idle.time = '100 millisecond', increment = '2 sec') " + "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(2 sec , 0) " + "select symbol, sum(price) as sumPrice, 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);
            if (inEventCount == 0) {
                AssertJUnit.assertTrue("Remove Events will only arrive after the second time period. ", removeEvents == null);
            }
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            } else if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    // Start sending events in the beginning of a cycle
    long timestamp = 0;
    inputHandler.send(timestamp, new Object[] { "IBM", 700f, 0 });
    inputHandler.send(timestamp, new Object[] { "WSO2", 60.5f, 1 });
    timestamp += 8500;
    inputHandler.send(timestamp, new Object[] { "WSO2", 60.5f, 1 });
    inputHandler.send(timestamp, new Object[] { "II", 60.5f, 1 });
    timestamp += 13000;
    inputHandler.send(timestamp, new Object[] { "TT", 60.5f, 1 });
    inputHandler.send(timestamp, new Object[] { "YY", 60.5f, 1 });
    // Anything more than 100 is enough. Used 200 to be on safe side
    Thread.sleep(200);
    AssertJUnit.assertEquals(3, inEventCount);
    AssertJUnit.assertEquals(0, 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 12 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project siddhi by wso2.

the class TestSiddhiLatency method isThrottled.

public static boolean isThrottled(Object[] throttleRequest) {
    log.info("Start latency =" + (System.currentTimeMillis() - (Long) throttleRequest[7]));
    if (ruleCount.get() != 0) {
        String uniqueKey = (String) throttleRequest[0];
        ResultContainer result = new ResultContainer(ruleCount.get());
        resultMap.put(uniqueKey.toString(), result);
        for (InputHandler inputHandler : requestStreamInputHandlerMap.values()) {
            try {
                inputHandler.send(Arrays.copyOf(throttleRequest, throttleRequest.length));
            } catch (InterruptedException e) {
                // interrupt current thread so that interrupt can propagate
                Thread.currentThread().interrupt();
                log.error(e.getMessage(), e);
            }
        }
        log.info("sending latency =" + (System.currentTimeMillis() - (Long) throttleRequest[7]));
        // Blocked call to return synchronous result
        boolean isThrottled = false;
        try {
            isThrottled = result.isThrottled();
            log.info("After result latency =" + (System.currentTimeMillis() - (Long) throttleRequest[7]));
            if (log.isDebugEnabled()) {
                log.debug("Throttling status for request to API " + throttleRequest[2] + " is " + isThrottled);
            }
        } catch (InterruptedException e) {
            // interrupt current thread so that interrupt can propagate
            Thread.currentThread().interrupt();
        // log.error(e.getMessage(), e);
        }
        if (!isThrottled) {
            // Converting properties map into json compatible String
            if (throttleRequest[6] != null) {
                throttleRequest[6] = (throttleRequest[6]).toString();
            }
        // Only send served throttleRequest to global throttler
        // sendToGlobalThrottler(throttleRequest);
        }
        resultMap.remove(uniqueKey);
        log.info("Return latency =" + (System.currentTimeMillis() - (Long) throttleRequest[7]));
        return isThrottled;
    } else {
        return false;
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler)

Example 13 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project siddhi by wso2.

the class TimeBatchWindowTestCase method timeWindowBatchTest7.

@Test
public void timeWindowBatchTest7() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(2 sec , 0) " + "select symbol, sum(price) as sumPrice, 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);
            if (inEventCount == 0) {
                AssertJUnit.assertTrue("Remove Events will only arrive after the second time period. ", removeEvents == null);
            }
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            } else if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    // Start sending events in the beginning of a cycle
    while (System.currentTimeMillis() % 2000 != 0) {
        ;
    }
    inputHandler.send(new Object[] { "IBM", 700f, 0 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
    Thread.sleep(8500);
    inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
    inputHandler.send(new Object[] { "II", 60.5f, 1 });
    Thread.sleep(13000);
    inputHandler.send(new Object[] { "TT", 60.5f, 1 });
    inputHandler.send(new Object[] { "YY", 60.5f, 1 });
    Thread.sleep(5000);
    AssertJUnit.assertEquals(3, inEventCount);
    AssertJUnit.assertEquals(0, 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 14 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project siddhi by wso2.

the class TimeBatchWindowTestCase method timeWindowBatchTest8.

@Test
public void timeWindowBatchTest8() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseEventWindow (symbol string, price float, volume int) timeBatch(2 sec , 0); ";
    String query = "" + "@info(name = 'query0') " + "from cseEventStream " + "insert into cseEventWindow; " + "" + "@info(name = 'query1') " + "from cseEventWindow " + "select symbol, sum(price) as sumPrice, 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);
            if (inEventCount == 0) {
                AssertJUnit.assertTrue("Remove Events will only arrive after the second time period. ", removeEvents == null);
            }
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            } else if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    // Start sending events in the beginning of a cycle
    while (System.currentTimeMillis() % 2000 != 0) {
    }
    inputHandler.send(new Object[] { "IBM", 700f, 0 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
    Thread.sleep(8500);
    inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
    inputHandler.send(new Object[] { "II", 60.5f, 1 });
    Thread.sleep(13000);
    inputHandler.send(new Object[] { "TT", 60.5f, 1 });
    inputHandler.send(new Object[] { "YY", 60.5f, 1 });
    Thread.sleep(5000);
    AssertJUnit.assertEquals(3, inEventCount);
    AssertJUnit.assertEquals(0, 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 15 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project siddhi by wso2.

the class JoinTableTestCase method testTableJoinQuery6.

@Test
public void testTableJoinQuery6() throws InterruptedException {
    log.info("testTableJoinQuery6 recursive join");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream RequestStream (start string, end string); " + "define stream TimeTableStream (start string, end string, elapsedTime int, startTime string); " + "define stream ResultStream (totalElapsedTime int); " + "define table TimeTable (start string, end string, elapsedTime int, startTime string);";
    String query = "" + "from TimeTableStream " + "select * " + "insert into TimeTable; " + "" + "from RequestStream join TimeTable " + "on TimeTable.start == RequestStream.start " + "select TimeTable.start as start, TimeTable.end as end, TimeTable.elapsedTime as elapsedTime, " + "RequestStream.end as destination " + "insert into intermediateResultStream;" + "" + "@info(name = 'query1') " + "from intermediateResultStream[end==destination] " + "select intermediateResultStream.elapsedTime as totalElapsedTime " + "insert into ResultStream;" + "" + "from intermediateResultStream[end!=destination] " + "insert into intermediateResultStream2; " + "" + "from intermediateResultStream2 join TimeTable " + "on TimeTable.start == intermediateResultStream2.end " + "select TimeTable.start as start, TimeTable.end as end, (intermediateResultStream2.elapsedTime + " + "TimeTable.elapsedTime) as elapsedTime, destination " + "insert into intermediateResultStream; ";
    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);
            eventArrived = true;
        }
    });
    InputHandler timeTableStream = siddhiAppRuntime.getInputHandler("TimeTableStream");
    InputHandler requestStream = siddhiAppRuntime.getInputHandler("RequestStream");
    siddhiAppRuntime.start();
    timeTableStream.send(new Object[] { "A", "B", 25, "1.27PM" });
    timeTableStream.send(new Object[] { "B", "C", 10, "1.52PM" });
    timeTableStream.send(new Object[] { "C", "D", 60, "2.52PM" });
    Thread.sleep(1000);
    requestStream.send(new Object[] { "A", "D" });
    Thread.sleep(1000);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertTrue("Events arrived", eventArrived);
}
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

SVGCoordinates (org.wso2.carbon.bpel.ui.bpel2svg.SVGCoordinates)57 ActivityInterface (org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface)47 Test (org.testng.annotations.Test)17 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)17 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)17 Event (org.wso2.siddhi.core.event.Event)17 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)13 SVGDimension (org.wso2.carbon.bpel.ui.bpel2svg.SVGDimension)11 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)11 ArrayList (java.util.ArrayList)10 OMElement (org.apache.axiom.om.OMElement)10 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)10 Element (org.w3c.dom.Element)9 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)9 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)7 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)7 ZoneId (java.time.ZoneId)5 HashMap (java.util.HashMap)5 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)5 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)5