Search in sources :

Example 31 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class LogSinkTest method testWithAllOptions.

@Test
public void testWithAllOptions() throws Exception {
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "@App:name(\"HelloWorldApp\")\n" + "define stream CargoStream (weight int);";
    String outputStream = "@sink(type='log', prefix='My Log',  priority='info')\n" + "define stream OutputStream(weight int, totalWeight long);";
    String query = ("@info(name='HelloWorldQuery') " + "from CargoStream " + "select weight, sum(weight) as totalWeight " + "insert into OutputStream;");
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + outputStream + query);
    siddhiAppRuntime.start();
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("CargoStream");
    Logger logger = Logger.getLogger(LogSink.class);
    UnitTestAppender appender = new UnitTestAppender();
    logger.addAppender(appender);
    try {
        inputHandler.send(new Object[] { 2 });
        AssertJUnit.assertTrue(appender.getMessages().contains("My Log"));
        AssertJUnit.assertTrue(appender.getMessages().contains("data=[2, 2]"));
        inputHandler.send(new Object[] { 3 });
        AssertJUnit.assertTrue(appender.getMessages().contains("My Log"));
        AssertJUnit.assertTrue(appender.getMessages().contains("data=[3, 5]"));
    } catch (Exception e) {
        Assert.fail("Unexpected exception occurred when testing with all options", e);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) UnitTestAppender(org.wso2.siddhi.core.UnitTestAppender) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Logger(org.apache.log4j.Logger) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 32 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class LogSinkTest method testWithDefaultPrefix.

@Test
public void testWithDefaultPrefix() throws Exception {
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "@App:name(\"HelloWorldApp\")\n" + "define stream CargoStream (weight int);";
    String outputStream = "@sink(type='log',  priority='info')\n" + "define stream OutputStream(weight int, totalWeight long);";
    String query = ("@info(name='HelloWorldQuery') " + "from CargoStream " + "select weight, sum(weight) as totalWeight " + "insert into OutputStream;");
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + outputStream + query);
    siddhiAppRuntime.start();
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("CargoStream");
    Logger logger = Logger.getLogger(LogSink.class);
    UnitTestAppender appender = new UnitTestAppender();
    logger.addAppender(appender);
    try {
        inputHandler.send(new Object[] { 2 });
        AssertJUnit.assertTrue(appender.getMessages().contains("HelloWorldApp : OutputStream"));
        AssertJUnit.assertTrue(appender.getMessages().contains("data=[2, 2]"));
        inputHandler.send(new Object[] { 3 });
        AssertJUnit.assertTrue(appender.getMessages().contains("HelloWorldApp : OutputStream"));
        AssertJUnit.assertTrue(appender.getMessages().contains("data=[3, 5]"));
    } catch (Exception e) {
        Assert.fail("Unexpected exception occurred when testing with default prefix", e);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) UnitTestAppender(org.wso2.siddhi.core.UnitTestAppender) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Logger(org.apache.log4j.Logger) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 33 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class LogSinkTest method testWithDefaultPriority.

@Test
public void testWithDefaultPriority() throws Exception {
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "@App:name(\"HelloWorldApp\")\n" + "define stream CargoStream (weight int);";
    String outputStream = "@sink(type='log', prefix='My Log')\n" + "define stream OutputStream(weight int, totalWeight long);";
    String query = ("@info(name='HelloWorldQuery') " + "from CargoStream " + "select weight, sum(weight) as totalWeight " + "insert into OutputStream;");
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + outputStream + query);
    siddhiAppRuntime.start();
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("CargoStream");
    Logger logger = Logger.getLogger(LogSink.class);
    UnitTestAppender appender = new UnitTestAppender();
    logger.addAppender(appender);
    try {
        inputHandler.send(new Object[] { 2 });
        AssertJUnit.assertTrue(appender.getMessages().contains("My Log"));
        AssertJUnit.assertTrue(appender.getMessages().contains("data=[2, 2]"));
        inputHandler.send(new Object[] { 3 });
        AssertJUnit.assertTrue(appender.getMessages().contains("My Log"));
        AssertJUnit.assertTrue(appender.getMessages().contains("data=[3, 5]"));
    } catch (Exception e) {
        Assert.fail("Unexpected exception occurred when testing with default priority", e);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) UnitTestAppender(org.wso2.siddhi.core.UnitTestAppender) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Logger(org.apache.log4j.Logger) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 34 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitAnonymous_stream.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public AnonymousInputStream visitAnonymous_stream(@NotNull SiddhiQLParser.Anonymous_streamContext ctx) {
    if (ctx.anonymous_stream() != null) {
        return (AnonymousInputStream) visit(ctx.anonymous_stream());
    }
    Set<String> activeStreamsBackup = activeStreams;
    try {
        activeStreams = new HashSet<String>();
        Query query = Query.query().from((InputStream) visit(ctx.query_input()));
        if (ctx.query_section() != null) {
            query.select((Selector) visit(ctx.query_section()));
        }
        if (ctx.output_rate() != null) {
            query.output((OutputRate) visit(ctx.output_rate()));
        }
        if (ctx.output_event_type() != null) {
            query.outStream(new ReturnStream((OutputStream.OutputEventType) visit(ctx.output_event_type())));
        } else {
            query.outStream(new ReturnStream());
        }
        AnonymousInputStream anonymousInputStream = new AnonymousInputStream(query);
        populateQueryContext(anonymousInputStream, ctx);
        return anonymousInputStream;
    } finally {
        activeStreams.clear();
        activeStreams = activeStreamsBackup;
    }
}
Also used : StoreQuery(org.wso2.siddhi.query.api.execution.query.StoreQuery) Query(org.wso2.siddhi.query.api.execution.query.Query) AnonymousInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.AnonymousInputStream) ReturnStream(org.wso2.siddhi.query.api.execution.query.output.stream.ReturnStream)

Example 35 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitJoin_source.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Object visitJoin_source(@NotNull SiddhiQLParser.Join_sourceContext ctx) {
    // join_source
    // :io (basic_source_stream_handler)* window? (AS alias)?
    // ;
    Source source = (Source) visit(ctx.source());
    String streamAlias = null;
    if (ctx.alias() != null) {
        streamAlias = (String) visit(ctx.alias());
        activeStreams.remove(ctx.source().getText());
        activeStreams.add(streamAlias);
    }
    BasicSingleInputStream basicSingleInputStream = new BasicSingleInputStream(streamAlias, source.streamId, source.isInnerStream);
    if (ctx.basic_source_stream_handlers() != null) {
        basicSingleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.basic_source_stream_handlers()));
    }
    if (ctx.window() != null) {
        SingleInputStream inputStream = new SingleInputStream(basicSingleInputStream, (Window) visit(ctx.window()));
        populateQueryContext(inputStream, ctx);
        return inputStream;
    } else {
        populateQueryContext(basicSingleInputStream, ctx);
        return basicSingleInputStream;
    }
}
Also used : BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) StreamHandler(org.wso2.siddhi.query.api.execution.query.input.handler.StreamHandler)

Aggregations

Test (org.testng.annotations.Test)80 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)67 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)58 InputStream (java.io.InputStream)54 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)54 Event (org.wso2.siddhi.core.event.Event)48 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)47 IOException (java.io.IOException)32 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)20 API (org.wso2.carbon.apimgt.core.models.API)18 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)17 FileInputStream (java.io.FileInputStream)15 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)13 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)12 Response (javax.ws.rs.core.Response)11 HashMap (java.util.HashMap)9 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 File (java.io.File)7 Connection (java.sql.Connection)7