use of org.wso2.siddhi.core.trigger.Trigger in project siddhi by wso2.
the class TriggerTestCase method testFilterQuery7.
@Test
public void testFilterQuery7() throws InterruptedException {
log.info("testTrigger7 - OUT 2");
SiddhiManager siddhiManager = new SiddhiManager();
String plan = "" + "define stream cseEventStream (symbol string, price float, volume long);" + "define trigger triggerStream at '*/1 * * * * ?' ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(plan);
siddhiAppRuntime.addCallback("triggerStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
long timestamp = event.getTimestamp();
count++;
if (count > 1) {
float triggerTimeDiff = timestamp / 1000 - lastTimeStamp / 1000;
AssertJUnit.assertTrue(1.0f == triggerTimeDiff);
}
lastTimeStamp = timestamp;
}
eventArrived = true;
}
});
siddhiAppRuntime.start();
Thread.sleep(1000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(true, eventArrived);
}
use of org.wso2.siddhi.core.trigger.Trigger in project siddhi by wso2.
the class TriggerTestCase method testFilterQuery6.
@Test
public void testFilterQuery6() throws InterruptedException {
log.info("testTrigger6 - OUT 2");
SiddhiManager siddhiManager = new SiddhiManager();
String plan = "" + "define stream cseEventStream (symbol string, price float, volume long);" + "define trigger triggerStream at every 500 milliseconds ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(plan);
siddhiAppRuntime.addCallback("triggerStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count += events.length;
eventArrived = true;
}
});
siddhiAppRuntime.start();
Thread.sleep(1100);
AssertJUnit.assertEquals(2, count);
AssertJUnit.assertEquals(true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.trigger.Trigger in project siddhi by wso2.
the class TriggerTestCase method testFilterQuery5.
@Test
public void testFilterQuery5() throws InterruptedException {
log.info("testTrigger5 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String plan = "" + "define stream cseEventStream (symbol string, price float, volume long);" + "define trigger triggerStream at 'start';";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(plan);
siddhiAppRuntime.addCallback("triggerStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count += events.length;
eventArrived = true;
}
});
siddhiAppRuntime.start();
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
AssertJUnit.assertEquals(true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.trigger.Trigger in project siddhi by wso2.
the class ExternalTimeBatchWindowTestCase method test01DownSampling.
@Test
public void test01DownSampling() throws Exception {
siddhiManager = new SiddhiManager();
String stream = "define stream jmxMetric(cpu int, memory int, bytesIn long, bytesOut long, timestamp long);";
String query = "@info(name = 'downSample') " + "from jmxMetric#window.externalTimeBatch(timestamp, 10 sec) " + "select " + "avg(cpu) as avgCpu, max(cpu) as maxCpu, min(cpu) as minCpu, " + " '|' as s, " + " avg(memory) as avgMem, max(memory) as maxMem, min(memory) as minMem, " + " '|' as s1, " + " avg(bytesIn) as avgBytesIn, max(bytesIn) as maxBytesIn, min(bytesIn) as minBytesIn, " + " '|' as s2, " + " avg(bytesOut) as avgBytesOut, max(bytesOut) as maxBytesOut, min(bytesOut) as minBytesOut, " + " '|' as s3, " + " timestamp as timeWindowEnds, " + " '|' as s4, " + " count(1) as metric_count " + " INSERT INTO tmp;";
SiddhiManager sm = new SiddhiManager();
SiddhiAppRuntime plan = sm.createSiddhiAppRuntime(stream + query);
InputHandler input = plan.getInputHandler("jmxMetric");
// stream call back doesn't follow the counter
final AtomicInteger counter = new AtomicInteger();
{
// stream callback
plan.addCallback("jmxMetric", new StreamCallback() {
@Override
public void receive(Event[] arg0) {
counter.addAndGet(arg0.length);
}
});
}
final AtomicInteger queryWideCounter = new AtomicInteger();
{
plan.addCallback("downSample", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inevents, Event[] removevents) {
int currentCount = queryWideCounter.addAndGet(inevents.length);
log.info(MessageFormat.format("Round {0} ====", currentCount));
log.info(" events count " + inevents.length);
EventPrinter.print(inevents);
}
});
}
plan.start();
int round = 4;
int eventsPerRound = 0;
long externalTs = System.currentTimeMillis();
for (int i = 0; i < round; i++) {
eventsPerRound = sendEvent(input, i, externalTs);
Thread.sleep(3000);
}
// trigger next round
sendEvent(input, round, externalTs);
plan.shutdown();
Thread.sleep(1000);
AssertJUnit.assertEquals(round * eventsPerRound + eventsPerRound, counter.get());
AssertJUnit.assertEquals(round, queryWideCounter.get());
}
Aggregations