use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery34.
@Test
public void testPartitionQuery34() throws InterruptedException {
log.info("Partition test33");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest33') " + "define stream cseEventStream (atr1 string, atr2 float, atr3 int, atr4 double, " + "atr5 long, atr6 long, atr7 double, atr8 float , atr9 bool, atr10 bool, atr11 int);" + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[700>atr5 OR atr8 >= atr3 OR atr6 >= atr2 OR atr4 " + ">= atr6 OR atr2 >= atr7 OR atr3 >= atr4 OR atr4 >= atr3 OR atr6 >= atr3 OR atr3" + ">= atr2 OR atr8 >= atr5 OR atr6 >= atr4 OR atr3 >= atr6 OR atr7 >= atr8 OR atr7 " + ">= atr4 OR atr6 >= atr5 OR atr11 >= atr3 OR atr8 >= atr2] select" + " atr1 as symbol, sum(atr2) as price" + " insert into " + "OutStockStream ; end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100, 101.0, 500L, 200L, 102.0, 75.7f, false, true, 105 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100, 101.0, 501L, 201L, 103.0, 76.7f, false, true, 106 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100, 102.0, 502L, 202L, 104.0, 77.7f, false, true, 107 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100, 101.0, 502L, 202L, 104.0, 77.7f, false, true, 108 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery42.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testPartitionQuery42() throws InterruptedException {
log.info("Partition test");
SiddhiApp siddhiApp = SiddhiApp.siddhiApp("Test").defineStream(StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT));
Query query = Query.query();
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.from(InputStream.stream("streamA"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("StockQuote");
Partition partition = Partition.partition();
partition.addQuery(query);
siddhiApp.addPartition(partition);
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
StreamCallback streamCallback = new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
count.addAndGet(events.length);
eventArrived = true;
}
};
siddhiAppRuntime.addCallback("StockQuote", streamCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
siddhiAppRuntime.start();
inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
Thread.sleep(1000);
AssertJUnit.assertEquals(0, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery16.
@Test
public void testPartitionQuery16() throws InterruptedException {
log.info("partition test16");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest16') " + "define stream streamA (symbol string, price int);" + "partition with (symbol of streamA) begin @info(name = 'query1') from streamA select symbol,price " + "insert into StockQuote ;" + "@info(name = 'query2') from streamA select symbol,price insert into StockQuote ; end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("StockQuote", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700 });
inputHandler.send(new Object[] { "WSO2", 60 });
inputHandler.send(new Object[] { "WSO2", 60 });
SiddhiTestHelper.waitForEvents(100, 6, count, 60000);
AssertJUnit.assertEquals(6, count.get());
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery37.
@Test
public void testPartitionQuery37() throws InterruptedException {
log.info("Partition test36");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest36') " + "define stream cseEventStream (atr1 string, atr2 object, atr3 int, atr4 double, " + "atr5 long, atr6 long, atr7 double, atr8 float , atr9 bool, atr10 bool, atr11 int);" + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[atr5 < 700 AND atr10] select atr5 as threshold, atr1 as symbol, cast" + "(atr2, 'double') as priceInDouble, sum(atr7) as summedValue insert into " + "OutStockStream ; end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6, 100, 101.0, 500L, 200L, 102.0, 75.7f, false, true, 105 });
inputHandler.send(new Object[] { "WSO2", 75.6, 100, 101.0, 501L, 201L, 103.0, 76.7f, false, true, 106 });
inputHandler.send(new Object[] { "IBM", 75.6, 100, 102.0, 502L, 202L, 104.0, 77.7f, false, true, 107 });
inputHandler.send(new Object[] { "ORACLE", 75.6, 100, 101.0, 502L, 202L, 104.0, 77.7f, false, false, 108 });
SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
AssertJUnit.assertEquals(3, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery.
@Test
public void testPartitionQuery() throws InterruptedException {
log.info("Partition test");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest') " + "define stream streamA (symbol string, price int);" + "partition with (symbol of streamA) " + "begin " + "@info(name = 'query1') " + "from streamA select symbol,price insert into StockQuote ; " + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
StreamCallback streamCallback = new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
count.addAndGet(events.length);
eventArrived = true;
}
};
siddhiAppRuntime.addCallback("StockQuote", streamCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700 });
inputHandler.send(new Object[] { "WSO2", 60 });
inputHandler.send(new Object[] { "WSO2", 60 });
SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(3, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations