use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class GroupByTestCase method testGroupByQuery1.
@Test
public void testGroupByQuery1() throws InterruptedException {
log.info("GroupBy test1");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('GroupByTest1') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream#window.time(1 sec) " + "select symbol, sum(volume) as totalVolume, avg(price) as avgPrice " + " group by symbol " + "insert into outputStream;" + "";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
log.info("Running : " + siddhiAppRuntime.getName());
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
count = count + inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 50f, 200L });
inputHandler.send(new Object[] { "WSO2", 50f, 200L });
Thread.sleep(200);
inputHandler.send(new Object[] { "WSO2", 50f, 200L });
inputHandler.send(new Object[] { "IBM", 50f, 200L });
Thread.sleep(4200);
inputHandler.send(new Object[] { "WSO2", 50f, 200L });
inputHandler.send(new Object[] { "WSO2", 50f, 200L });
Thread.sleep(100);
AssertJUnit.assertEquals(6, count);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class OrderByLimitTestCase method limitTest10.
@Test
public void limitTest10() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(4) " + "select symbol, sum(price) as totalPrice, volume " + "group by symbol " + "order by totalPrice desc " + "limit 2 " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
Assert.assertEquals(2, inEvents.length);
Assert.assertTrue(inEvents[0].getData(2).equals(2) || inEvents[0].getData(2).equals(4));
inEventCount = inEventCount + inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "IBM", 60.5f, 1 });
inputHandler.send(new Object[] { "WSO2", 7060.5f, 2 });
inputHandler.send(new Object[] { "XYZ", 60.5f, 3 });
inputHandler.send(new Object[] { "IBM", 700f, 4 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 7 });
Thread.sleep(500);
AssertJUnit.assertEquals(4, inEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class OrderByLimitTestCase method limitTest9.
@Test
public void limitTest9() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.length(4) " + "select symbol, price, volume " + "group by symbol " + "order by price " + "limit 2 " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
Assert.assertEquals(1, inEvents.length);
inEventCount = inEventCount + inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "IBM", 60.5f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "XYZ", 60.5f, 3 });
inputHandler.send(new Object[] { "IBM", 700f, 4 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 7 });
Thread.sleep(500);
AssertJUnit.assertEquals(8, inEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class OrderByLimitTestCase method limitTest7.
@Test
public void limitTest7() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(4) " + "select symbol, price, volume " + "group by symbol " + "order by price " + "limit 2 " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
Assert.assertEquals(2, inEvents.length);
Assert.assertTrue(inEvents[0].getData(2).equals(1) || inEvents[0].getData(2).equals(7));
inEventCount = inEventCount + inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "IBM", 60.5f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "XYZ", 60.5f, 3 });
inputHandler.send(new Object[] { "IBM", 700f, 4 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 7 });
Thread.sleep(500);
AssertJUnit.assertEquals(4, inEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class OrderByLimitTestCase method limitTest5.
@Test
public void limitTest5() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(4) " + "select symbol, sum(volume) as totalVolume, volume, price " + "group by symbol " + "order by price, totalVolume " + "limit 2 " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
Assert.assertEquals(2, inEvents.length);
Assert.assertTrue(inEvents[0].getData(2).equals(0) || inEvents[0].getData(2).equals(4));
inEventCount = inEventCount + inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 60.5f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "XYZ", 60.5f, 3 });
inputHandler.send(new Object[] { "IBM", 60.5f, 4 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 7 });
Thread.sleep(500);
AssertJUnit.assertEquals(4, inEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations