use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class PartitionTestCase2 method testSubtractExpressionExecutorIntCase.
@Test
public void testSubtractExpressionExecutorIntCase() 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(77, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(35, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(88, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(66, 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.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class PartitionTestCase2 method testMultiplyExpressionExecutorLongCase.
@Test
public void testMultiplyExpressionExecutorLongCase() throws InterruptedException {
log.info("Partition testMultiplyExpressionExecutorLongCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testMultiplyExpressionExecutorLongCase') " + "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(10000L, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(103206L, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(101404L, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(104918L, 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 org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class PartitionTestCase2 method testModExpressionExecutorLongCase.
@Test
public void testModExpressionExecutorLongCase() throws InterruptedException {
log.info("Partition testModExpressionExecutorLongCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testModExpressionExecutorLongCase') " + "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(0L, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(89L, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(98L, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(84L, 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 org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class PatternPartitionTestCase method testPatternPartitionQuery18.
@Test
public void testPatternPartitionQuery18() throws InterruptedException {
log.info("testPatternCount10 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream EventStream (symbol string, price float, volume int,quantity int); ";
String partitionStart = "partition with (quantity of EventStream) begin ";
String query = "" + "@info(name = 'query1') " + "from e1 = EventStream [price >= 50 and volume > 100] -> e2 = EventStream [price <= 40] <:5> " + " -> e3 = EventStream [volume <= 70] " + "select e1.symbol as symbol1, e2[0].symbol as symbol2, e3.symbol as symbol3 " + "insert into StockQuote;";
String partitionEnd = "end";
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[] { "IBM", null, "GOOG" }, event.getData());
break;
default:
AssertJUnit.assertSame(1, inEventCount.get());
}
}
eventArrived = true;
}
}
});
InputHandler eventStream = siddhiAppRuntime.getInputHandler("EventStream");
siddhiAppRuntime.start();
eventStream.send(new Object[] { "IBM", 75.6f, 105, 2 });
Thread.sleep(100);
eventStream.send(new Object[] { "GOOG", 21f, 61, 2 });
eventStream.send(new Object[] { "WSO2", 21f, 61, 2 });
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