use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase2 method testModExpressionExecutorFloatCase.
@Test
public void testModExpressionExecutorFloatCase() throws InterruptedException {
log.info("Partition testModExpressionExecutorFloatCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testModExpressionExecutorFloatCase') " + "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(9.559998f, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(9.74f, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(11.540001f, 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 io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
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 io.siddhi.core.stream.output.StreamCallback 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 io.siddhi.core.stream.output.StreamCallback 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 io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase2 method testPartitionQuery50.
@Test
public void testPartitionQuery50() throws InterruptedException {
log.info("Partition test50");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('PartitionTest50') " + "" + "" + "define stream cseEventStream (symbol string, price float, volume int); " + "" + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "define stream cseEventStreamTwo (symbol string, price float,volume int);" + "" + "@info(name = 'query')" + "from cseEventStreamOne " + "select symbol, price, volume " + "insert into cseEventStream;" + " " + "partition with (price>=100 as 'large' or " + " price<100 and price>=50 as 'medium' or " + " price<50 as 'small' of cseEventStream, " + " symbol of cseEventStreamTwo ) " + " begin" + " @info(name = 'query1') " + " from cseEventStream " + " insert into #OutStockStream1 ; " + "" + " @info(name = 'query2') " + " from cseEventStreamTwo " + " insert into #OutStockStream1 ; " + " " + " @info(name = 'query3') " + " from #OutStockStream1 " + " select symbol, sum(price) as price " + " insert into #OutStockStream2 ;" + " " + " @info(name = 'query4') " + " from #OutStockStream2 " + " 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();
eventArrived = true;
if (count.get() == 1) {
AssertJUnit.assertEquals(25.0, event.getData()[1]);
} else if (count.get() == 2) {
AssertJUnit.assertEquals(30.0, event.getData()[1]);
} else if (count.get() == 3) {
AssertJUnit.assertEquals(7005.60009765625, event.getData()[1]);
} else if (count.get() == 4) {
AssertJUnit.assertEquals(50.0, event.getData()[1]);
} else if (count.get() == 5) {
AssertJUnit.assertEquals(55.0, event.getData()[1]);
} else if (count.get() == 6) {
AssertJUnit.assertEquals(7000.000097751617, event.getData()[1]);
}
}
}
});
InputHandler inputHandlerOne = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
InputHandler inputHandlerTwo = siddhiAppRuntime.getInputHandler("cseEventStreamTwo");
siddhiAppRuntime.start();
inputHandlerOne.send(new Object[] { "IBM", 25f, 100 });
inputHandlerTwo.send(new Object[] { "small", 5f, 100 });
inputHandlerOne.send(new Object[] { "WSO2", 7005.6f, 100 });
inputHandlerOne.send(new Object[] { "IBM", 50f, 100 });
inputHandlerOne.send(new Object[] { "ORACLE", 25f, 100 });
inputHandlerTwo.send(new Object[] { "large", -5.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 5, count, 60000);
AssertJUnit.assertTrue(6 >= count.get());
siddhiAppRuntime.shutdown();
}
Aggregations