use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class FaultStreamTestCase method faultStreamTest6.
@Test(dependsOnMethods = "faultStreamTest5")
public void faultStreamTest6() throws InterruptedException {
log.info("faultStreamTest6-Tests logging by default when fault handling is not configured " + "explicitly at sink level during publishing failures.");
UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null);
final Logger logger = (Logger) LogManager.getRootLogger();
logger.setLevel(Level.ALL);
logger.addAppender(appender);
appender.start();
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@OnError(action='stream')" + "define stream cseEventStream (symbol string, price float, volume long);" + "\n" + "@sink(type='inMemory', topic='{{symbol}}', @map(type='passThrough')) " + "define stream outputStream (symbol string, price float, sym1 string);" + "\n" + "@info(name = 'query1') " + "from cseEventStream " + "select symbol, price , symbol as sym1 " + "insert into outputStream ;" + "";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
Assert.assertTrue(events[0].getData(0) != null);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
try {
inputHandler.send(new Object[] { "IBM", 0f, 100L });
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages().contains("Dropping event at Sink 'inMemory' at"));
} catch (Exception e) {
Assert.fail("Unexpected exception occurred when testing.", e);
} finally {
logger.removeAppender(appender);
siddhiAppRuntime.shutdown();
}
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery40.
@Test
public void testPartitionQuery40() throws InterruptedException {
log.info("Partition test");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('PartitionTest') " + "@app:statistics('true') " + "define stream streamA (symbol string, price int);" + "@info(name = 'partitionB')" + "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 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 }));
SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(3, count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.output.StreamCallback 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 io.siddhi.core.stream.output.StreamCallback 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();
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery2.
@Test
public void testPartitionQuery2() throws InterruptedException {
log.info("Partition test2");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest2') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream StockStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream , symbol of StockStream1) begin @info(name = 'query1') " + "from cseEventStream[700>price] select symbol,sum(price) as price,volume 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 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations