use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class StdDevAttributeAggregatorTestCase method stdDevAggregatorTest3.
@Test
public void stdDevAggregatorTest3() throws InterruptedException {
log.info("stdDevAggregator Test #3: All the events in the stream are equal");
SiddhiManager siddhiManager = new SiddhiManager();
String execPlan = "" + "@app:name('stdDevAggregatorTests') " + "" + "define stream cseEventStream (symbol string, price double);" + "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(3) " + "select stdDev(price) as deviation " + "group by symbol " + "insert into outputStream;";
SiddhiAppRuntime execPlanRunTime = siddhiManager.createSiddhiAppRuntime(execPlan);
execPlanRunTime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
AssertJUnit.assertTrue(Math.abs((Double) inEvents[0].getData(0) - 0) < epsilon);
}
});
InputHandler inputHandler = execPlanRunTime.getInputHandler("cseEventStream");
execPlanRunTime.start();
inputHandler.send(new Object[] { "WSO2", 1.0 });
inputHandler.send(new Object[] { "WSO2", 1.0 });
inputHandler.send(new Object[] { "WSO2", 1.0 });
Thread.sleep(300);
execPlanRunTime.shutdown();
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class SequenceTestCase method testTimeBatchAndSequence.
@Test
public void testTimeBatchAndSequence() throws Exception {
log.info("testTimeBatchAndSequence OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream received_reclamations (timestamp long, product_id string, defect_category string);";
String query = "" + "@info(name = 'query1') " + "from received_reclamations#window.timeBatch(1 sec) " + "select product_id, defect_category, count(product_id) as num " + "group by product_id, defect_category " + "insert into reclamation_averages;" + "" + "@info(name = 'query2') " + "from a=reclamation_averages[num > 1], b=reclamation_averages[num > a.num and product_id == a" + ".product_id and defect_category == a.defect_category] " + "select a.product_id, a.defect_category, a.num as oldNum, b.num as newNum " + "insert into increased_reclamations;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("increased_reclamations", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
if (events != null) {
for (Event event : events) {
inEventCount++;
switch(inEventCount) {
case 1:
String product = (String) event.getData()[0];
String defectCategory = (String) event.getData()[1];
long oldNum = (Long) event.getData()[2];
long newNum = (Long) event.getData()[3];
AssertJUnit.assertTrue(product.equals("abc"));
AssertJUnit.assertTrue(defectCategory.equals("123"));
AssertJUnit.assertTrue(oldNum < newNum);
break;
default:
AssertJUnit.assertSame(1, inEventCount);
}
}
}
eventArrived = true;
}
});
InputHandler i1 = siddhiAppRuntime.getInputHandler("received_reclamations");
siddhiAppRuntime.start();
for (int i = 0; i < 5; i++) {
i1.send(new Object[] { System.currentTimeMillis(), "abc", "123" });
Thread.sleep(100);
}
Thread.sleep(500);
for (int i = 0; i < 8; i++) {
i1.send(new Object[] { System.currentTimeMillis(), "abc", "123" });
Thread.sleep(100);
}
Thread.sleep(1000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class CustomJoinWindowTestCase method testGroupByUseCase.
@Test
public void testGroupByUseCase() throws InterruptedException {
log.info("Test joining a single window by multiple streams");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream SensorStream (name string, value float, roomNo int, deviceID string); " + "define window SensorWindow (name string, value float, roomNo int, deviceID string) timeBatch(1 " + "second); ";
String query = "" + "@info(name = 'query0') " + "from SensorStream " + "insert into SensorWindow; " + "@info(name = 'query1') " + "from SensorWindow " + "select name, max(value) as maxValue, roomNo " + "group by name, roomNo " + "insert into MaxSensorReadingPerRoomStream; " + "@info(name = 'query2') " + "from SensorWindow " + "select name, max(value) as maxValue " + "group by name " + "insert into OverallMaxSensorReadingStream; " + "@info(name = 'query3') " + "from SensorWindow " + "select name, avg(value) as avgValue " + "group by name " + "insert into OverallAverageSensorReadingStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("MaxSensorReadingPerRoomStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
System.out.print("MaxSensorReadingPerRoomStream: ");
EventPrinter.print(events);
}
});
siddhiAppRuntime.addCallback("OverallMaxSensorReadingStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
System.out.print("OverallMaxSensorReadingStream: ");
EventPrinter.print(events);
}
});
siddhiAppRuntime.addCallback("OverallAverageSensorReadingStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
System.out.print("OverallAverageSensorReadingStream: ");
EventPrinter.print(events);
}
});
siddhiAppRuntime.start();
InputHandler sensorStreamInputHandler = siddhiAppRuntime.getInputHandler("SensorStream");
sensorStreamInputHandler.send(new Object[] { "Temperature", 23.0f, 1, "T001A" });
sensorStreamInputHandler.send(new Object[] { "Pressure", 20.0f, 1, "P001" });
sensorStreamInputHandler.send(new Object[] { "Temperature", 25.0f, 2, "T002" });
sensorStreamInputHandler.send(new Object[] { "Temperature", 24.0f, 3, "T003" });
sensorStreamInputHandler.send(new Object[] { "Pressure", 45.0f, 3, "P003" });
sensorStreamInputHandler.send(new Object[] { "Temperature", 23.5f, 1, "T001B" });
sensorStreamInputHandler.send(new Object[] { "Humidity", 15.0f, 2, "H002" });
sensorStreamInputHandler.send(new Object[] { "Humidity", 10.0f, 3, "H003" });
Thread.sleep(1000);
Thread.sleep(500);
siddhiAppRuntime.shutdown();
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class StoreQueryTableTestCase method test5.
@Test(expectedExceptions = StoreQueryCreationException.class)
public void test5() throws InterruptedException {
log.info("Test5 table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
try {
siddhiAppRuntime.start();
Event[] events = siddhiAppRuntime.query("" + "from StockTable1 " + "on price > 5 " + "select symbol1, sum(volume) as totalVolume " + "group by symbol " + "having totalVolume >150 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(200L, events[0].getData(1));
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class StoreQueryTableTestCase method test4.
@Test(expectedExceptions = StoreQueryCreationException.class)
public void test4() throws InterruptedException {
log.info("Test4 table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
Thread.sleep(500);
Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol1, sum(volume) as totalVolume " + "group by symbol " + "having totalVolume >150 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(200L, events[0].getData(1));
} finally {
siddhiAppRuntime.shutdown();
}
}
Aggregations