Search in sources :

Example 1 with SubscriberUnAvailableException

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();
}
Also used : SubscriberUnAvailableException(io.siddhi.core.util.transport.SubscriberUnAvailableException) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException) SiddhiManager(io.siddhi.core.SiddhiManager) StreamCallback(io.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Aggregations

SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)1 SiddhiManager (io.siddhi.core.SiddhiManager)1 Event (io.siddhi.core.event.Event)1 ConnectionUnavailableException (io.siddhi.core.exception.ConnectionUnavailableException)1 StreamCallback (io.siddhi.core.stream.output.StreamCallback)1 SubscriberUnAvailableException (io.siddhi.core.util.transport.SubscriberUnAvailableException)1 Test (org.testng.annotations.Test)1