Search in sources :

Example 1 with NextAction

use of org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar.NextAction in project genius by opendaylight.

the class DataTreeEventCallbackRegistrarTest method testExceptionInCallbackMustBeLogged.

@Test
public void testExceptionInCallbackMustBeLogged() throws TransactionCommitFailedException, InterruptedException {
    logCaptureRule.expectLastErrorMessageContains("TestConsumer");
    AtomicBoolean added = new AtomicBoolean(false);
    DataTreeEventCallbackRegistrar dataTreeEventCallbackRegistrar = new DataTreeEventCallbackRegistrarImpl(db);
    dataTreeEventCallbackRegistrar.onAdd(OPERATIONAL, FOO_PATH, new Function<TopLevelList, NextAction>() {

        @Override
        public NextAction apply(TopLevelList topLevelList) {
            added.set(true);
            throw new IllegalStateException("TEST");
        }

        @Override
        public String toString() {
            return "TestConsumer";
        }
    });
    db1.syncWrite(OPERATIONAL, FOO_PATH, FOO_DATA);
    await().untilTrue(added);
    // TODO see above we can remove this once we can await DataBroker listeners
    // The sleep () is required :( so that the throw new IllegalStateException really leads to an ERROR log,
    // because the (easily) await().untilTrue(...) could theoretically complete immediately after added.set(true)
    // but before the throw new IllegalStateException("TEST") and LOG.  To make this more reliable and without sleep
    // would require more work inside DataBroker to be able to await listener event processing.
    Thread.sleep(100);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) NextAction(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar.NextAction) DataTreeEventCallbackRegistrarImpl(org.opendaylight.genius.datastoreutils.listeners.internal.DataTreeEventCallbackRegistrarImpl) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 DataTreeEventCallbackRegistrar (org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar)1 NextAction (org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar.NextAction)1 DataTreeEventCallbackRegistrarImpl (org.opendaylight.genius.datastoreutils.listeners.internal.DataTreeEventCallbackRegistrarImpl)1 TopLevelList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList)1