use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery20.
@Test
public void testPartitionQuery20() throws InterruptedException {
log.info("Partition test20");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('PartitionTest20') " + "" + "" + "define stream cseEventStream (symbol string, price float,volume int); " + "" + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "" + "@info(name = 'query')" + "from cseEventStreamOne " + "select symbol, price, volume " + "insert into cseEventStream;" + " " + "partition with (price>=100 as 'large' or price<100 as 'medium' or price<50 as 'small' of " + "cseEventStream) " + " begin" + " @info(name = 'query1') " + " from cseEventStream " + " select symbol, sum(price) as price " + " insert into #OutStockStream1 ; " + " " + " @info(name = 'query2') " + " from #OutStockStream1 " + " insert into #OutStockStream2 ;" + " " + " @info(name = 'query3') " + " from #OutStockStream2 " + " insert into OutStockStream ;" + " " + " end ; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
count.incrementAndGet();
eventArrived = true;
if (count.get() == 1) {
AssertJUnit.assertEquals(25.0, event.getData()[1]);
} else if (count.get() == 2) {
AssertJUnit.assertEquals(25.0, event.getData()[1]);
} else if (count.get() == 3) {
AssertJUnit.assertEquals(7005.60009765625, event.getData()[1]);
} else if (count.get() == 4) {
AssertJUnit.assertTrue(event.getData()[1].equals(75.0) || event.getData()[1].equals(100.0));
} else if (count.get() == 5) {
AssertJUnit.assertTrue(event.getData()[1].equals(50.0) || event.getData()[1].equals(100.0));
} else if (count.get() == 6) {
AssertJUnit.assertEquals(50.0, event.getData()[1]);
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 25f, 100 });
inputHandler.send(new Object[] { "WSO2", 7005.6f, 100 });
inputHandler.send(new Object[] { "IBM", 50f, 100 });
inputHandler.send(new Object[] { "ORACLE", 25f, 100 });
SiddhiTestHelper.waitForEvents(100, 5, count, 60000);
AssertJUnit.assertTrue(6 >= count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class FilterTestCase2 method testFilterQuery112.
// ****************************************************************************************************************
// Expression Multiply
@Test
public void testFilterQuery112() throws InterruptedException {
log.info("Filter test112");
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).attribute("awards", Attribute.Type.LONG);
Query query = new Query();
query.from(InputStream.stream("cseEventStream"));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("multipliedQuantity", Expression.multiply(Expression.variable("quantity"), Expression.value(4))).select("multipliedPrice", Expression.multiply(Expression.variable("price"), Expression.value(2))).select("multipliedVolume", Expression.multiply(Expression.variable("volume"), Expression.value(3))).select("multipliedAwards", Expression.multiply(Expression.variable("awards"), Expression.value(5))));
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);
AssertJUnit.assertTrue("20".equals(inEvents[0].getData()[1].toString()));
AssertJUnit.assertTrue("111.0".equals(inEvents[0].getData()[2].toString()));
AssertJUnit.assertTrue("300.0".equals(inEvents[0].getData()[3].toString()));
AssertJUnit.assertTrue("15".equals(inEvents[0].getData()[4].toString()));
count = count + inEvents.length;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.5f, 100d, 5, 3L });
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class FilterTestCase2 method testFilterQuery87.
@Test
public void testFilterQuery87() throws InterruptedException {
log.info("Filter test87");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN, Expression.value(50d))));
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", 50f, 60d });
inputHandler.send(new Object[] { "WSO2", 70f, 40d });
inputHandler.send(new Object[] { "WSO2", 44f, 200d });
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class FilterTestCase2 method testFilterQuery110.
// *****************************************************************************************************************
// Expression-subtract
@Test
public void testFilterQuery110() throws InterruptedException {
log.info("Filter test110");
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).attribute("awards", Attribute.Type.LONG);
Query query = new Query();
query.from(InputStream.stream("cseEventStream"));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("decreasedPrice", Expression.subtract(Expression.variable("price"), Expression.value(20))).select("decreasedVolume", Expression.subtract(Expression.variable("volume"), Expression.value(50))).select("decreasedQuantity", Expression.subtract(Expression.variable("quantity"), Expression.value(4))).select("decreasedAwards", Expression.subtract(Expression.variable("awards"), Expression.value(10))));
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);
AssertJUnit.assertTrue("35.5".equals(inEvents[0].getData()[1].toString()));
AssertJUnit.assertTrue("50.0".equals(inEvents[0].getData()[2].toString()));
AssertJUnit.assertTrue("1".equals(inEvents[0].getData()[3].toString()));
AssertJUnit.assertTrue("0".equals(inEvents[0].getData()[4].toString()));
count = count + inEvents.length;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.5f, 100d, 5, 10L });
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class FilterTestCase2 method testFilterQuery90.
@Test
public void testFilterQuery90() throws InterruptedException {
log.info("Filter test90");
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, Expression.value(10f))));
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", 50f, 60d, 6 });
inputHandler.send(new Object[] { "WSO2", 70f, 40d, 10 });
inputHandler.send(new Object[] { "WSO2", 44f, 200d, 56 });
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
siddhiAppRuntime.shutdown();
}
Aggregations