use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
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.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
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.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class JoinPartitionTestCase method testJoinPartition2.
@Test
public void testJoinPartition2() throws InterruptedException {
log.info("Join partition test2");
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 ;" + "" + "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[] { "User1", "World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "IBM", "User2", 100 });
twitterStreamHandler.send(new Object[] { "User2", "Hello World", "IBM" });
twitterStreamHandler.send(new Object[] { "User2", "World", "IBM" });
SiddhiTestHelper.waitForEvents(1000, 8, count, 12000);
AssertJUnit.assertEquals(8, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class JoinPartitionTestCase method testJoinPartition5.
@Test
public void testJoinPartition5() throws InterruptedException {
log.info("Join partition test5");
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 #cseInnerStream;" + "@info(name = 'query1') from #cseInnerStream#window.time(1 sec) join twitterStream#window.time(1 sec)" + " " + "on twitterStream.company== #cseInnerStream.symbol " + "select #cseInnerStream.user as user,twitterStream.tweet as tweet, twitterStream.company, " + "#cseInnerStream.volume , #cseInnerStream.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", "WSO2" });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "IBM" });
twitterStreamHandler.send(new Object[] { "User3", "Hello World", "GOOG" });
SiddhiTestHelper.waitForEvents(100, 4, count, 6000);
AssertJUnit.assertEquals(4, count.get());
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionTestCase1 method testModExpressionExecutorDoubleCase.
@Test
public void testModExpressionExecutorDoubleCase() throws InterruptedException {
log.info("Partition testModExpressionExecutorDoubleCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testModExpressionExecutorDoubleCase') " + "define stream cseEventStream (atr1 string, atr2 string, atr3 int, atr4 double, " + "atr5 long, atr6 long, atr7 double, atr8 float , atr9 bool, atr10 bool, atr11 int);" + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[atr5 < 700 ] select atr4%atr7 as dividedVal, atr5 as threshold, atr1 as" + " symbol, " + "cast(atr2, 'double') as priceInDouble, sum(atr7) as summedValue insert " + "into OutStockStream ; end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
count.incrementAndGet();
if (count.get() == 1) {
AssertJUnit.assertEquals(9.560000000000002, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(9.739999999999995, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(11.540000000000006, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(13.659999999999997, event.getData(0));
eventArrived = true;
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", null, 100, 101.0, 500L, 200L, 11.43, 75.7f, false, true, 105 });
inputHandler.send(new Object[] { "WSO2", "aa", 100, 101.0, 501L, 201L, 15.21, 76.7f, false, true, 106 });
inputHandler.send(new Object[] { "IBM", null, 100, 102.0, 502L, 202L, 45.23, 77.7f, false, true, 107 });
inputHandler.send(new Object[] { "ORACLE", null, 100, 101.0, 502L, 202L, 87.34, 77.7f, false, false, 108 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations