Search in sources :

Example 1 with CayenneEvent

use of org.apache.cayenne.event.CayenneEvent in project cayenne by apache.

the class ClientChannelTest method testEventBridgeFailure.

@Test
public void testEventBridgeFailure() throws Exception {
    MockClientConnection connection = new MockClientConnection() {

        @Override
        public EventBridge getServerEventBridge() throws CayenneRuntimeException {
            return new EventBridge(Collections.EMPTY_LIST, "ext") {

                @Override
                protected void sendExternalEvent(CayenneEvent localEvent) throws Exception {
                }

                @Override
                protected void shutdownExternal() throws Exception {
                }

                @Override
                protected void startupExternal() throws Exception {
                    // intentionally throw an exception
                    throw new CayenneRuntimeException("Test failure");
                }
            };
        }
    };
    // default constructor must fail
    try {
        new ClientChannel(connection, false, new MockEventManager(), false);
        fail("Channel didn't throw on broken EventBridge");
    } catch (CayenneRuntimeException e) {
    // expected
    }
    try {
        DefaultEventManager manager = new DefaultEventManager(2);
        managers.add(manager);
        new ClientChannel(connection, false, manager, false);
        fail("Channel didn't throw on broken EventBridge");
    } catch (CayenneRuntimeException e) {
    // expected
    }
    try {
        DefaultEventManager manager = new DefaultEventManager(2);
        managers.add(manager);
        new ClientChannel(connection, false, manager, true);
    } catch (CayenneRuntimeException e) {
        fail("Channel threw on broken EventBridge");
    }
}
Also used : DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) CayenneEvent(org.apache.cayenne.event.CayenneEvent) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) EventBridge(org.apache.cayenne.event.EventBridge) MockEventManager(org.apache.cayenne.event.MockEventManager) Test(org.junit.Test)

Aggregations

CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 CayenneEvent (org.apache.cayenne.event.CayenneEvent)1 DefaultEventManager (org.apache.cayenne.event.DefaultEventManager)1 EventBridge (org.apache.cayenne.event.EventBridge)1 MockEventManager (org.apache.cayenne.event.MockEventManager)1 Test (org.junit.Test)1