use of org.wso2.siddhi.core.ExecutionPlanRuntime in project carbon-apimgt by wso2.
the class ThrottleTimeBatchWindowTestCase method throttleTimeWindowBatchTest3.
@Test
public void throttleTimeWindowBatchTest3() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#throttler:timeBatch(1 min , 0) " + "select symbol,sum(price) as sumPrice,volume, expiryTimeStamp " + "insert all events into outputStream ;";
ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(cseEventStream + query);
executionPlanRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
lastCurrentEvent = inEvents[inEvents.length - 1];
} else if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
lastRemoveEvent = removeEvents[removeEvents.length - 1];
}
eventArrived = true;
}
});
InputHandler inputHandler = executionPlanRuntime.getInputHandler("cseEventStream");
executionPlanRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(260000);
inputHandler.send(new Object[] { "IBM", 700f, 0 });
Assert.assertEquals(3, inEventCount);
Assert.assertTrue("Event expiry time is not valid for the current batch", (Long) (lastCurrentEvent.getData()[3]) >= System.currentTimeMillis());
Assert.assertTrue(eventArrived);
executionPlanRuntime.shutdown();
}
use of org.wso2.siddhi.core.ExecutionPlanRuntime in project carbon-apimgt by wso2.
the class ThrottleTimeBatchWindowTestCase method throttleTimeWindowBatchTest2.
@Test
public void throttleTimeWindowBatchTest2() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#throttler:timeBatch(5 sec , 0) " + "select symbol,sum(price) as sumPrice,volume, expiryTimeStamp " + "insert all events into outputStream ;";
ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(cseEventStream + query);
executionPlanRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
} else if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
lastRemoveEvent = removeEvents[removeEvents.length - 1];
}
eventArrived = true;
}
});
InputHandler inputHandler = executionPlanRuntime.getInputHandler("cseEventStream");
executionPlanRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(10000);
Assert.assertEquals(2, inEventCount);
Assert.assertEquals(0.0d, lastRemoveEvent.getData()[1]);
Assert.assertTrue(eventArrived);
executionPlanRuntime.shutdown();
}
use of org.wso2.siddhi.core.ExecutionPlanRuntime in project carbon-apimgt by wso2.
the class ThrottleTimeBatchWindowTestCase method throttleTimeWindowBatchTest1.
@Test
public void throttleTimeWindowBatchTest1() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#throttler:timeBatch(5 sec) " + "select symbol,sum(price) as sumPrice,volume, expiryTimeStamp " + "insert all events into outputStream ;";
ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(cseEventStream + query);
executionPlanRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
} else if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = executionPlanRuntime.getInputHandler("cseEventStream");
executionPlanRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
Thread.sleep(500);
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(6000);
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(6000);
Assert.assertEquals(4, inEventCount);
Assert.assertEquals(2, removeEventCount);
Assert.assertTrue(eventArrived);
executionPlanRuntime.shutdown();
}
use of org.wso2.siddhi.core.ExecutionPlanRuntime in project carbon-apimgt by wso2.
the class ThrottlingTimeLengthWindowTestCase method throttleTimeLengthWindowTest2.
@Test
public void throttleTimeLengthWindowTest2() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String requestStream = "" + "define stream RequestStream (messageID string, isEligible bool, throttleKey string);";
String query = "" + "@info(name = 'query1') " + "from RequestStream#throttler:timeLength(5 sec,0, 3) " + "select throttleKey, isThrottled, expiryTimeStamp group by throttleKey " + "insert all events into outputStream ;";
ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(requestStream + query);
executionPlanRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
for (Event event : inEvents) {
switch(count.incrementAndGet()) {
case 1:
case 2:
case 3:
case 5:
Assert.assertEquals(false, event.getData(1));
break;
case 4:
Assert.assertEquals(true, event.getData(1));
break;
default:
Assert.fail("Received more than expected number of events. Expected maximum : 4," + "Received : " + count.get());
}
}
}
eventArrived = true;
}
});
InputHandler inputHandler = executionPlanRuntime.getInputHandler("RequestStream");
executionPlanRuntime.start();
inputHandler.send(new Object[] { "message123", true, "message123:1234" });
inputHandler.send(new Object[] { "message123", true, "message123:1234" });
inputHandler.send(new Object[] { "message123", true, "message123:1234" });
inputHandler.send(new Object[] { "message123", true, "message123:1234" });
Thread.sleep(6000);
inputHandler.send(new Object[] { "message123", true, "message123:1234" });
Thread.sleep(1000);
Assert.assertEquals(5, inEventCount);
Assert.assertTrue(eventArrived);
executionPlanRuntime.shutdown();
}
use of org.wso2.siddhi.core.ExecutionPlanRuntime in project carbon-apimgt by wso2.
the class ThrottlingTimeLengthWindowTestCase method throttleTimeLengthWindowTest1.
@Test
public void throttleTimeLengthWindowTest1() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String requestStream = "" + "define stream RequestStream (messageID string, isEligible bool, throttleKey string);";
String query = "" + "@info(name = 'query1') " + "from RequestStream#throttler:timeLength(10 sec,0, 2) " + "select throttleKey, isThrottled, expiryTimeStamp group by throttleKey " + "insert all events into outputStream ;";
ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(requestStream + query);
executionPlanRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
for (Event event : inEvents) {
switch(count.incrementAndGet()) {
case 1:
case 2:
case 4:
Assert.assertEquals(false, event.getData(1));
break;
case 3:
Assert.assertEquals(true, event.getData(1));
break;
default:
Assert.fail("Received more than expected number of events. Expected maximum : 4," + "Received : " + count.get());
}
}
}
eventArrived = true;
}
});
InputHandler inputHandler = executionPlanRuntime.getInputHandler("RequestStream");
executionPlanRuntime.start();
inputHandler.send(new Object[] { "message123", true, "message123:1234" });
inputHandler.send(new Object[] { "message123", true, "message123:1234" });
inputHandler.send(new Object[] { "message123", true, "message123:1234" });
inputHandler.send(new Object[] { "message456", true, "message456:1234" });
Assert.assertEquals(4, inEventCount);
Assert.assertTrue(eventArrived);
executionPlanRuntime.shutdown();
}
Aggregations