use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase2 method testMultiplyExpressionExecutorDoubleCase.
@Test
public void testMultiplyExpressionExecutorDoubleCase() throws InterruptedException {
log.info("Partition testMultiplyExpressionExecutorDoubleCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testMultiplyExpressionExecutorDoubleCase') " + "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(1154.43, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(1536.21, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(4613.46, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(8821.34, 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();
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase2 method testSubtractExpressionExecutorIntCase1.
@Test
public void testSubtractExpressionExecutorIntCase1() throws InterruptedException {
log.info("Partition testSubtractExpressionExecutorIntCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testSubtractExpressionExecutorIntCase') " + "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(null, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(null, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(null, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(null, event.getData(0));
eventArrived = true;
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", "mm", null, 101.0, 500L, 20L, 11.43, 75.7f, false, true, 23 });
inputHandler.send(new Object[] { "WSO2", "aa", null, 101.0, 501L, 206L, 15.21, 76.7f, false, true, 65 });
inputHandler.send(new Object[] { "IBM", "nn", null, 102.0, 502L, 202L, 45.23, 77.7f, false, true, 12 });
inputHandler.send(new Object[] { "ORACLE", "ss", null, 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 io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase2 method testSubtractExpressionExecutorLongCase.
@Test
public void testSubtractExpressionExecutorLongCase() throws InterruptedException {
log.info("Partition testSubtractExpressionExecutorLongCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testSubtractExpressionExecutorLongCase') " + "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 atr5-atr6 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(480L, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(295L, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(300L, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(293L, 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, 105 });
inputHandler.send(new Object[] { "WSO2", "aa", 100, 101.0, 501L, 206L, 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, 209L, 87.34, 77.7f, false, false, 108 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase2 method testMultiplyExpressionExecutorDoubleCase1.
@Test
public void testMultiplyExpressionExecutorDoubleCase1() throws InterruptedException {
log.info("Partition testMultiplyExpressionExecutorDoubleCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testMultiplyExpressionExecutorDoubleCase') " + "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(null, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(null, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(null, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(null, event.getData(0));
eventArrived = true;
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", "bb", 100, null, 500L, 200L, 11.43, 75.7f, false, true, 105 });
inputHandler.send(new Object[] { "WSO2", "aa", 100, null, 501L, 201L, 15.21, 76.7f, false, true, 106 });
inputHandler.send(new Object[] { "IBM", "cc", 100, 102.0, 502L, 202L, null, 77.7f, false, true, 107 });
inputHandler.send(new Object[] { "ORACLE", "dd", 100, null, 502L, 202L, 87.34, 77.7f, false, false, 108 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PatternPartitionTestCase method testPatternPartitionQuery31.
@Test
public void testPatternPartitionQuery31() throws InterruptedException {
log.info("testPatternComplex5 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int,quantity int); " + "define stream Stream2 (symbol string, price float, volume int,quantity int); ";
String partitionStart = "partition with (quantity of Stream1,quantity of Stream2) begin ";
String partitionEnd = "end";
String query = "" + "@info(name = 'query1') " + "from e1 = Stream1 [ price >= 50 and volume > 100 ] -> e2 = Stream2 [e1.symbol != 'AMBA' ] " + " -> e3 = Stream2 [volume <= 70 ] " + "select e3.symbol as symbol1, e2[0].symbol as symbol2, e3.volume as volume3 " + "insert into StockQuote;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + partitionStart + query + partitionEnd);
siddhiAppRuntime.addCallback("StockQuote", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
if (event.isExpired()) {
removeEventCount.incrementAndGet();
} else {
inEventCount.incrementAndGet();
switch(inEventCount.get()) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "GOOG", 65 }, event.getData());
break;
default:
AssertJUnit.assertSame(1, inEventCount.get());
}
}
eventArrived = true;
}
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "IBM", 75.6f, 105, 1 });
Thread.sleep(100);
stream2.send(new Object[] { "GOOG", 21f, 81, 1 });
stream2.send(new Object[] { "WSO2", 176.6f, 65, 1 });
stream1.send(new Object[] { "BIRT", 21f, 81, 1 });
stream1.send(new Object[] { "AMBA", 126.6f, 165, 1 });
stream2.send(new Object[] { "DDD", 23f, 181, 1 });
stream2.send(new Object[] { "BIRT", 21f, 86, 1 });
stream2.send(new Object[] { "BIRT", 21f, 82, 1 });
stream2.send(new Object[] { "WSO2", 176.6f, 60, 1 });
stream1.send(new Object[] { "AMBA", 126.6f, 165, 1 });
stream2.send(new Object[] { "DOX", 16.2f, 25, 1 });
SiddhiTestHelper.waitForEvents(100, 1, inEventCount, 60000);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount.get());
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount.get());
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations