use of io.siddhi.core.util.transport.SubscriberUnAvailableException in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryWithFailingSource.
@Test(dependsOnMethods = { "inMemoryWithFailingSink1" })
public void inMemoryWithFailingSource() throws InterruptedException {
log.info("Test failing inMemorySource");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testFailingInMemory', topic='WSO2', @map(type='passThrough')) " + "define stream FooStream (symbol string, price float, volume long); " + "define stream BarStream (symbol string, price float, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("BarStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
wso2Count.incrementAndGet();
}
}
});
siddhiAppRuntime.start();
try {
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 100L }));
} catch (SubscriberUnAvailableException e) {
AssertJUnit.fail();
}
TestFailingInMemorySource.fail = true;
TestFailingInMemorySource.connectionCallback.onError(new ConnectionUnavailableException("Connection Lost"));
Thread.sleep(6000);
try {
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 57.6f, 100L }));
AssertJUnit.fail();
} catch (Throwable e) {
AssertJUnit.assertTrue(e instanceof SubscriberUnAvailableException);
}
TestFailingInMemorySource.fail = false;
Thread.sleep(10000);
try {
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 100L }));
} catch (SubscriberUnAvailableException e) {
AssertJUnit.fail();
}
// assert event count
AssertJUnit.assertEquals("Number of WSO2 events", 2, wso2Count.get());
AssertJUnit.assertEquals("Number of errors", 1, TestFailingInMemorySource.numberOfErrorOccurred);
siddhiAppRuntime.shutdown();
}
Aggregations