use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class StatisticsTestCase method statisticsTest6.
@Test
public void statisticsTest6() throws InterruptedException {
log.info("statistics test 1");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:statistics(reporter = 'console', interval = '2', include='*query2.*,*cseEventStream2*' )" + " " + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select * " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream[volume > 90] " + "select * " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
eventArrived = true;
for (Event event : events) {
count++;
AssertJUnit.assertTrue("IBM".equals(event.getData(0)) || "WSO2".equals(event.getData(0)));
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
Thread.sleep(3010);
siddhiAppRuntime.shutdown();
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(3, count);
System.out.flush();
String output = baos.toString();
AssertJUnit.assertTrue(output.contains("Gauges"));
AssertJUnit.assertTrue(output.contains("org.wso2.siddhi." + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS));
AssertJUnit.assertFalse(output.contains("query1.memory"));
AssertJUnit.assertTrue(output.contains("cseEventStream2.throughput"));
AssertJUnit.assertTrue(output.contains("Meters"));
AssertJUnit.assertTrue(output.contains(SiddhiConstants.METRIC_INFIX_SIDDHI + SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_STREAMS + SiddhiConstants.METRIC_DELIMITER + "cseEventStream"));
AssertJUnit.assertTrue(output.contains("Timers"));
AssertJUnit.assertFalse(output.contains("query1.latency"));
AssertJUnit.assertTrue(output.contains("query2.memory"));
log.info(output);
System.setOut(old);
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class ValidateTestCase method validateTest1.
@Test
public void validateTest1() throws InterruptedException {
log.info("validate test1");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('validateTest') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream[symbol is null] " + "select symbol, price " + "insert into outputStream;";
siddhiManager.validateSiddhiApp(siddhiApp);
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class WindowPartitionTestCase method testWindowPartitionQuery2.
@Test
public void testWindowPartitionQuery2() throws InterruptedException {
log.info("Window Partition test2");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "define stream cseEventStream (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream) begin @info(name = 'query1') from cseEventStream#window" + ".lengthBatch(2) select symbol,sum(price) as price,volume insert all events into OutStockStream ; " + "end ";
SiddhiAppRuntime executionRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
executionRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
inEventCount++;
eventArrived = true;
if (inEventCount == 1) {
AssertJUnit.assertEquals(170.0, event.getData()[1]);
} else if (inEventCount == 2) {
AssertJUnit.assertEquals(1700.0, event.getData()[1]);
}
}
}
});
InputHandler inputHandler = executionRuntime.getInputHandler("cseEventStream");
executionRuntime.start();
inputHandler.send(new Object[] { "IBM", 70f, 100 });
inputHandler.send(new Object[] { "WSO2", 700f, 100 });
inputHandler.send(new Object[] { "IBM", 100f, 100 });
inputHandler.send(new Object[] { "IBM", 200f, 100 });
inputHandler.send(new Object[] { "WSO2", 1000f, 100 });
Thread.sleep(2000);
AssertJUnit.assertEquals(2, inEventCount);
executionRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class FilterTestCase1 method filterTest1.
// Test cases for GREATER_THAN operator
@Test
public void filterTest1() throws InterruptedException {
log.info("filter test1");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('filterTest1') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select symbol, price " + "insert into outputStream;" + "" + "@info(name = 'query2') " + "from outputStream[70 > price] " + "select symbol, price " + "insert into outputStream2 ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
log.info("Running : " + siddhiAppRuntime.getName());
siddhiAppRuntime.addCallback("query1", 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;
}
});
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)));
}
};
siddhiAppRuntime.addCallback("query2", queryCallback);
queryCallback.startProcessing();
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 100L });
inputHandler.send(new Object[] { "WSO2", 60.5f, 200L });
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
AssertJUnit.assertTrue(eventArrived);
queryCallback.stopProcessing();
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery57.
@Test
public void testFilterQuery57() throws InterruptedException {
log.info("Filter test57");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.EQUAL, Expression.value(60L))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
count = count + inEvents.length;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 50f, 60d });
inputHandler.send(new Object[] { "WSO2", 70f, 60d });
inputHandler.send(new Object[] { "WSO2", 60f, 200d });
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
siddhiAppRuntime.shutdown();
}
Aggregations