Search in sources :

Example 81 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class PassThroughTestCase method passThroughTest4.

@Test
public void passThroughTest4() throws InterruptedException {
    log.info("pass through test4");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('passThroughTest4') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream " + "insert into outputStream;" + "" + "@info(name = 'query2') " + "from outputStream " + "select * " + "insert into outputStream2 ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    log.info("Running : " + siddhiAppRuntime.getName());
    QueryCallback queryCallback = new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            AssertJUnit.assertTrue("WSO2".equals(inEvents[0].getData(0)));
            count = count + inEvents.length;
            eventArrived = true;
        }
    };
    siddhiAppRuntime.addCallback("query2", queryCallback);
    queryCallback.startProcessing();
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 700f, 100L });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 200L });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    AssertJUnit.assertTrue(eventArrived);
    queryCallback.stopProcessing();
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 82 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class SimpleQueryValidatorTestCase method testQueryWithAggregation.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQueryWithAggregation() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String tables = "define stream TradeStream (symbol string, price double, volume long, timestamp long);\n" + "define aggregation TradeAggregation\n" + "  from TradeStream\n" + "  select symbol, avg(price) as avgPrice, sum(price) as total\n" + "    group by symbol\n" + "    aggregate by symbol every sec ... year; " + "" + "from every TradeAggregation \n" + "select * \n" + "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables);
    siddhiAppRuntime.shutdown();
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 83 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class SimpleQueryValidatorTestCase method testQueryWithEveryAggregation.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQueryWithEveryAggregation() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String tables = "define stream TradeStream (symbol string, price double, volume long, timestamp long);\n" + "define aggregation TradeAggregation\n" + "  from TradeStream\n" + "  select symbol, avg(price) as avgPrice, sum(price) as total\n" + "    group by symbol\n" + "    aggregate by symbol every sec ... year; " + "" + "from every TradeAggregation " + "select * " + "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables);
    siddhiAppRuntime.shutdown();
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 84 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class SimpleQueryValidatorTestCase method testQueryWithEveryTable.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQueryWithEveryTable() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String tables = "define table TestTable(symbol string, volume float);\n" + "" + "from every TestTable " + "select * " + "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables);
    siddhiAppRuntime.shutdown();
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 85 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class TestDebugger method testDebugger4.

@Test
public void testDebugger4() throws InterruptedException {
    log.info("Siddi Debugger Test 4: Test next traversal in a query with time batch window where next call delays" + " 1 sec");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    final String query = "@info(name = 'query1')" + "from cseEventStream#window.timeBatch(1 sec) " + "select symbol, price, volume " + "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            inEventCount.addAndGet(events.length);
            AssertJUnit.assertEquals("Cannot emit all three in one time", 1, events.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
    siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN);
    siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {

        @Override
        public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
            log.info(event);
            int count = debugEventCount.addAndGet(getCount(event));
            if (count != 1 && queryTerminal == SiddhiDebugger.QueryTerminal.IN) {
                try {
                    Thread.sleep(1100);
                } catch (InterruptedException e) {
                }
            }
            // next call will not reach OUT since there is a window
            debugger.next();
        }
    });
    inputHandler.send(new Object[] { "WSO2", 50f, 60 });
    inputHandler.send(new Object[] { "WSO2", 70f, 40 });
    inputHandler.send(new Object[] { "WSO2", 60f, 50 });
    Thread.sleep(1500);
    AssertJUnit.assertEquals("Invalid number of output events", 3, inEventCount.get());
    AssertJUnit.assertEquals("Invalid number of debug events", 3, debugEventCount.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)845 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)841 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)818 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)777 Event (org.wso2.siddhi.core.event.Event)473 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)377 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)100 Query (org.wso2.siddhi.query.api.execution.query.Query)80 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)67 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)65 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 IOException (java.io.IOException)14 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)11 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)11 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)10 Response (javax.ws.rs.core.Response)9 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)8 ObjectOutputStream (java.io.ObjectOutputStream)7 OutputStream (java.io.OutputStream)6