use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery67.
// ************************************************************************************************************
// Test cases for less than or equal
@Test
public void testFilterQuery67() throws InterruptedException {
log.info("Filter test67");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.LONG);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(60d))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
count = count + inEvents.length;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 50d, 60L });
inputHandler.send(new Object[] { "WSO2", 70d, 40L });
inputHandler.send(new Object[] { "WSO2", 44d, 200L });
Thread.sleep(100);
AssertJUnit.assertEquals(2, count);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery75.
@Test
public void testFilterQuery75() throws InterruptedException {
log.info("Filter test75");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE).attribute("quantity", Attribute.Type.INT);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(3L))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("quantity", Expression.variable("quantity")));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
count = count + inEvents.length;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 500f, 60d, 6 });
inputHandler.send(new Object[] { "WSO2", 70f, 60d, 2 });
inputHandler.send(new Object[] { "WSO2", 60f, 300d, 4 });
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery7.
@Test
public void testEventOutputRateLimitQuery7() throws InterruptedException {
log.info("EventOutputRateLimit test7");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest7') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "output last every 4 events " + "insert into uniqueIps ;";
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);
if (inEvents != null) {
count += inEvents.length;
AssertJUnit.assertTrue("192.10.1.4".equals(inEvents[0].getData(0)));
} else {
AssertJUnit.fail("Remove events emitted");
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 1, count);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery1.
@Test
public void testEventOutputRateLimitQuery1() throws InterruptedException {
log.info("EventOutputRateLimit test1");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest1') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "output all every 2 events " + "insert into uniqueIps ;";
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);
if (inEvents != null) {
count += inEvents.length;
} else {
AssertJUnit.fail("Remove events emitted");
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 4, count);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery6.
@Test
public void testEventOutputRateLimitQuery6() throws InterruptedException {
log.info("EventOutputRateLimit test6");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest6') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "output last every 2 events " + "insert into uniqueIps ;";
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);
if (inEvents != null) {
count += inEvents.length;
AssertJUnit.assertTrue("192.10.1.5".equals(inEvents[0].getData(0)) || "192.10.1.4".equals(inEvents[0].getData(0)));
} else {
AssertJUnit.fail("Remove events emitted");
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 2, count);
siddhiAppRuntime.shutdown();
}
Aggregations