use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class PartitionTestCase1 method testPartitionQuery2.
@Test
public void testPartitionQuery2() throws InterruptedException {
log.info("Partition test2");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest2') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream StockStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream , symbol of StockStream1) begin @info(name = 'query1') " + "from cseEventStream[700>price] select symbol,sum(price) as price,volume insert into OutStockStream ;" + " end ";
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);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class PartitionTestCase1 method testPartitionQuery22.
@Test
public void testPartitionQuery22() throws InterruptedException {
log.info("Partition test22");
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#window.time(1 sec) " + "select symbol, avg(price) as avgPrice, volume " + "having avgPrice > 10" + "insert expired events 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]);
}
eventArrived = true;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75f, 100 });
inputHandler.send(new Object[] { "IBM", 75f, 100 });
SiddhiTestHelper.waitForEvents(200, 1, count, 60000);
AssertJUnit.assertTrue(1 <= count.get());
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
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 org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class PartitionTestCase1 method testPartitionQuery20.
@Test
public void testPartitionQuery20() throws InterruptedException {
log.info("Partition test20");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('PartitionTest20') " + "" + "" + "define stream cseEventStream (symbol string, price float,volume int); " + "" + "define stream cseEventStreamOne (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 as 'medium' or price<50 as 'small' of " + "cseEventStream) " + " begin" + " @info(name = 'query1') " + " from cseEventStream " + " select symbol, sum(price) as price " + " insert into #OutStockStream1 ; " + " " + " @info(name = 'query2') " + " from #OutStockStream1 " + " insert into #OutStockStream2 ;" + " " + " @info(name = 'query3') " + " 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(25.0, event.getData()[1]);
} else if (count.get() == 3) {
AssertJUnit.assertEquals(7005.60009765625, event.getData()[1]);
} else if (count.get() == 4) {
AssertJUnit.assertTrue(event.getData()[1].equals(75.0) || event.getData()[1].equals(100.0));
} else if (count.get() == 5) {
AssertJUnit.assertTrue(event.getData()[1].equals(50.0) || event.getData()[1].equals(100.0));
} else if (count.get() == 6) {
AssertJUnit.assertEquals(50.0, event.getData()[1]);
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 25f, 100 });
inputHandler.send(new Object[] { "WSO2", 7005.6f, 100 });
inputHandler.send(new Object[] { "IBM", 50f, 100 });
inputHandler.send(new Object[] { "ORACLE", 25f, 100 });
SiddhiTestHelper.waitForEvents(100, 5, count, 60000);
AssertJUnit.assertTrue(6 >= count.get());
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.stream.output.StreamCallback in project ballerina by ballerina-lang.
the class PartitionTestCase1 method testPartitionQuery19.
@Test
public void testPartitionQuery19() throws InterruptedException {
log.info("Partition test19");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest19') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStreamOne (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 as 'medium' or price<50 as 'small' of " + "cseEventStream) begin @info(name = 'query1') from cseEventStream select symbol,sum(price) as price " + "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(25.0, event.getData()[1]);
} else if (count.get() == 3) {
AssertJUnit.assertEquals(7005.60009765625, event.getData()[1]);
} else if (count.get() == 4) {
AssertJUnit.assertTrue(event.getData()[1].equals(75.0) || event.getData()[1].equals(100.0));
} else if (count.get() == 5) {
AssertJUnit.assertTrue(event.getData()[1].equals(50.0) || event.getData()[1].equals(100.0));
} else if (count.get() == 6) {
AssertJUnit.assertEquals(50.0, event.getData()[1]);
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 25f, 100 });
inputHandler.send(new Object[] { "WSO2", 7005.6f, 100 });
inputHandler.send(new Object[] { "IBM", 50f, 100 });
inputHandler.send(new Object[] { "ORACLE", 25f, 100 });
SiddhiTestHelper.waitForEvents(100, 5, count, 60000);
AssertJUnit.assertTrue(6 >= count.get());
siddhiAppRuntime.shutdown();
}
Aggregations