use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class StatisticsTestCase method statisticsTest5.
/**
* To not enable stats if no Stats manager enabled
*/
@Test
public void statisticsTest5() throws InterruptedException {
log.info("statistics test 5");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "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.enableStats(true);
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.assertFalse(output.contains("Gauges"));
log.info(output);
System.setOut(old);
}
use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class JoinPartitionTestCase method testJoinPartition6.
@Test
public void testJoinPartition6() throws InterruptedException {
log.info("Join partition test6");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int); define stream " + "twitterStream (user string, tweet string, company string);" + "partition with (user of cseEventStream) begin " + "@info(name = 'query2') from cseEventStream select symbol, user, sum(volume) as volume insert all " + "events into #cseEventStream;" + "@info(name = 'query1') from #cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec)" + " " + "on twitterStream.company== #cseEventStream.symbol " + "select #cseEventStream.user as user,twitterStream.tweet as tweet, twitterStream.company, " + "#cseEventStream.volume , #cseEventStream.symbol " + "insert all events into outputStream ;" + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 200 });
cseEventStreamHandler.send(new Object[] { "IBM", "User2", 500 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "IBM" });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
SiddhiTestHelper.waitForEvents(100, 4, count, 6000);
AssertJUnit.assertEquals(4, count.get());
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class JoinPartitionTestCase method testJoinPartition10.
@Test
public void testJoinPartition10() throws InterruptedException {
log.info("Join partition test10");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "" + "define stream cseEventStream (symbol string, user string,volume int); " + "define stream twitterStream (user string, tweet string, company string); " + "" + "partition with (user of cseEventStream, user of twitterStream) " + "begin " + " @info(name = 'query1') " + " from cseEventStream#window.length(1) unidirectional join twitterStream#window.length(1) " + " select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.volume, " + "cseEventStream.user" + " insert all events into outputStream1 ;" + "" + "end;" + "" + "partition with (user of outputStream1) " + "begin " + " @info(name = 'query2') " + " from outputStream1#window.length(1) join twitterStream#window.length(1) " + " select outputStream1.symbol as symbol, twitterStream.tweet, outputStream1.volume " + " insert all events into outputStream ;" + "" + "end;" + " ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
cseEventStreamHandler.send(new Object[] { "WSO2", "User2", 100 });
twitterStreamHandler.send(new Object[] { "User2", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User3", "Hello World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "WSO2", "User3", 100 });
SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
AssertJUnit.assertEquals(3, count.get());
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class JoinPartitionTestCase method testJoinPartition4.
@Test
public void testJoinPartition4() throws InterruptedException {
log.info("Join partition test4");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int); define stream " + "twitterStream (user string, tweet string, company string);" + "partition with (user of cseEventStream, user of twitterStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, cseEventStream.user as user,twitterStream.tweet, " + "cseEventStream.volume " + "insert all events into #outputStream ;" + "@info(name = 'query2') from #outputStream select symbol,user insert all events into outputStream;" + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
InputHandler outputStreamStreamHandler = siddhiAppRuntime.getInputHandler("outputStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User1", "World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "IBM", "User1", 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "IBM" });
twitterStreamHandler.send(new Object[] { "User1", "World", "IBM" });
outputStreamStreamHandler.send(new Object[] { "GOOG", "new_user_1" });
outputStreamStreamHandler.send(new Object[] { "GOOG", "new_user_2" });
SiddhiTestHelper.waitForEvents(100, 10, count, 6000);
AssertJUnit.assertEquals(10, count.get());
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class JoinPartitionTestCase method testJoinPartition8.
@Test
public void testJoinPartition8() throws InterruptedException {
log.info("Join partition test8");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int); define stream " + "twitterStream (user string, tweet string, company string);" + "partition with (user of cseEventStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.volume " + "insert all events into outputStream ;" + "" + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User2", "Hellno World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User3", "Hellno World", "WSO2" });
SiddhiTestHelper.waitForEvents(100, 6, count, 6000);
AssertJUnit.assertEquals(6, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations