use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery15.
@Test
public void testPartitionQuery15() throws InterruptedException {
log.info("Partition test15");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('PartitionTest15') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "define stream StockStream (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream) " + "begin " + " @info(name = 'query') " + " from cseEventStream " + " select symbol,price as price,volume " + " insert into #StockStream ;" + " " + " @info(name = 'query1') " + " from #StockStream " + " select symbol,price,volume " + " insert into OutStockStream ;" + "" + " @info(name = 'query2') " + " from #StockStream " + " select symbol,price,volume " + " insert into StockStream ; " + "end ;" + "" + "partition with (symbol of cseEventStream1) " + "begin " + " @info(name = 'query3') " + " from cseEventStream1 " + " select symbol, price + 5 as price, volume " + " insert into #StockStream ;" + "" + " @info(name = 'query4') " + " from #StockStream " + " select symbol,price,volume " + " insert into OutStockStream ; " + "end ;" + "" + "@info(name = 'query5') " + "from StockStream " + "select symbol,price+15 as price,volume " + "group by symbol " + "insert into OutStockStream ;" + "";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("StockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
stockStreamEventCount = stockStreamEventCount + events.length;
}
});
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler inputHandler2 = siddhiAppRuntime.getInputHandler("cseEventStream1");
InputHandler inputHandler3 = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
inputHandler2.send(new Object[] { "IBM1", 75.6f, 100 });
inputHandler2.send(new Object[] { "WSO21", 75.6f, 100 });
inputHandler2.send(new Object[] { "IBM1", 75.6f, 100 });
inputHandler2.send(new Object[] { "ORACLE1", 75.6f, 100 });
inputHandler3.send(new Object[] { "ABC", 75.6d, 100 });
inputHandler3.send(new Object[] { "DEF", 75.6d, 100 });
inputHandler3.send(new Object[] { "KLM", 75.6d, 100 });
inputHandler3.send(new Object[] { "ABC", 75.6d, 100 });
SiddhiTestHelper.waitForEvents(100, 16, count, 60000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(16, count.get());
AssertJUnit.assertEquals(8, stockStreamEventCount);
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase1 method testDivideExpressionExecutorFloatCase.
@Test
public void testDivideExpressionExecutorFloatCase() throws InterruptedException {
log.info("Partition testDivideExpressionExecutorFloatCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testDivideExpressionExecutorFloatCase') " + "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(8.836395f, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(6.640368f, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(2.2551403f, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(1.1564003f, 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 PartitionTestCase1 method testPartitionQuery10.
@Test
public void testPartitionQuery10() throws InterruptedException {
log.info("Partition test10");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest10') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream select symbol,avg(price) as avgPrice,volume 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(75.0, event.getData()[1]);
} else if (count.get() == 2) {
AssertJUnit.assertEquals(705.0, event.getData()[1]);
} else if (count.get() == 3) {
AssertJUnit.assertEquals(55.0, event.getData()[1]);
} else if (count.get() == 4) {
AssertJUnit.assertEquals(50.0, event.getData()[1]);
}
eventArrived = true;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75f, 100 });
inputHandler.send(new Object[] { "WSO2", 705f, 100 });
inputHandler.send(new Object[] { "IBM", 35f, 100 });
inputHandler.send(new Object[] { "ORACLE", 50.0f, 100 });
SiddhiTestHelper.waitForEvents(200, 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 PartitionTestCase1 method testPartitionQuery43.
public void testPartitionQuery43() throws InterruptedException {
log.info("Partition test43");
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiApp siddhiApp = new SiddhiApp("plan43");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
Partition partition = Partition.partition().with("cseEventStream", Expression.variable("symbol"));
Query query = Query.query();
query.from(InputStream.stream("cseEventStream"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query.insertIntoInner("StockStream", OutputStream.OutputEventType.CURRENT_EVENTS);
Query query1 = Query.query();
query1.from(InputStream.innerStream("StockStream"));
query1.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query1.insertInto("OutStockStream", OutputStream.OutputEventType.CURRENT_EVENTS);
partition.addQuery(query);
partition.addQuery(query1);
siddhiApp.addPartition(partition);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(4, count.get());
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery11.
@Test
public void testPartitionQuery11() throws InterruptedException {
log.info("Partition test11");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest11') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream select count() as entries 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(1L, event.getData()[0]);
} else if (count.get() == 2) {
AssertJUnit.assertEquals(1L, event.getData()[0]);
} else if (count.get() == 3) {
AssertJUnit.assertEquals(2L, event.getData()[0]);
} else if (count.get() == 4) {
AssertJUnit.assertEquals(1L, event.getData()[0]);
}
eventArrived = true;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75f, 100 });
inputHandler.send(new Object[] { "WSO2", 705f, 100 });
inputHandler.send(new Object[] { "IBM", 35f, 100 });
inputHandler.send(new Object[] { "ORACLE", 50.0f, 100 });
SiddhiTestHelper.waitForEvents(200, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations