use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase2 method testSubtractExpressionExecutorFloatCase.
@Test
public void testSubtractExpressionExecutorFloatCase() throws InterruptedException {
log.info("Partition testSubtractExpressionExecutorFloatCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testSubtractExpressionExecutorFloatCase') " + "define stream cseEventStream (atr1 string, atr2 string, atr3 int, atr4 float, " + "atr5 long, atr6 long, atr7 float, 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(89.57f, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(85.79f, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(56.77f, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(13.660004f, event.getData(0));
eventArrived = true;
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", null, 100, 101.0f, 500L, 200L, 11.43f, 75.7f, false, true, 105 });
inputHandler.send(new Object[] { "WSO2", "aa", 100, 101.0f, 501L, 201L, 15.21f, 76.7f, false, true, 106 });
inputHandler.send(new Object[] { "IBM", null, 100, 102.0f, 502L, 202L, 45.23f, 77.7f, false, true, 107 });
inputHandler.send(new Object[] { "ORACLE", null, 100, 101.0f, 502L, 202L, 87.34f, 77.7f, false, false, 108 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase2 method testMultiplyExpressionExecutorIntCase.
@Test
public void testMultiplyExpressionExecutorIntCase() throws InterruptedException {
log.info("Partition testMultiplyExpressionExecutorIntCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testMultiplyExpressionExecutorIntCase') " + "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 atr3*atr11 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(2300, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(6500, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(1200, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(3400, event.getData(0));
eventArrived = true;
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", null, 100, 101.0, 500L, 20L, 11.43, 75.7f, false, true, 23 });
inputHandler.send(new Object[] { "WSO2", "aa", 100, 101.0, 501L, 206L, 15.21, 76.7f, false, true, 65 });
inputHandler.send(new Object[] { "IBM", null, 100, 102.0, 502L, 202L, 45.23, 77.7f, false, true, 12 });
inputHandler.send(new Object[] { "ORACLE", null, 100, 101.0, 502L, 209L, 87.34, 77.7f, false, false, 34 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class TablePartitionTestCase method testPartitionQuery2.
@Test
public void testPartitionQuery2() throws InterruptedException {
log.info("Table Partition test 2");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('PartitionTest') " + "define stream streamA (symbol string, price int);" + "define stream streamB (symbol string);" + "define table tableA (symbol string, price int);" + "partition with (symbol of streamA, symbol of streamB) " + "begin " + " @info(name = 'query1') " + " from streamA " + " select symbol, price " + " insert into tableA; " + "" + "end ;" + "" + "@info(name = 'query2') " + "from streamB[(symbol==tableA.symbol) in tableA] " + "select symbol " + "insert into outputStream; " + "";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
count.incrementAndGet();
}
eventArrived = true;
}
});
InputHandler streamAInputHandler = siddhiAppRuntime.getInputHandler("streamA");
InputHandler streamBInputHandler = siddhiAppRuntime.getInputHandler("streamB");
siddhiAppRuntime.start();
streamAInputHandler.send(new Object[] { "IBM", 700 });
streamAInputHandler.send(new Object[] { "WSO2", 60 });
streamAInputHandler.send(new Object[] { "WSO2", 60 });
streamBInputHandler.send(new Object[] { "WSO2" });
streamBInputHandler.send(new Object[] { "FB" });
streamBInputHandler.send(new Object[] { "IBM" });
SiddhiTestHelper.waitForEvents(100, 2, count, 60000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(2, count.get());
AssertJUnit.assertEquals(true, eventArrived);
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
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();
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class JoinPartitionTestCase method testJoinPartition3.
@Test
public void testJoinPartition3() throws InterruptedException {
log.info("Join partition test3");
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 outStream;" + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outStream", 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(100, 8, count, 6000);
AssertJUnit.assertEquals(8, count.get());
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations