Search in sources :

Example 1 with DataTreeEventCallbackRegistrar

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

the class DataTreeEventCallbackRegistrarTest method checkAdd.

private void checkAdd(NextAction nextAction) throws TransactionCommitFailedException {
    AtomicBoolean added = new AtomicBoolean(false);
    DataTreeEventCallbackRegistrar dataTreeEventCallbackRegistrar = new DataTreeEventCallbackRegistrarImpl(db);
    dataTreeEventCallbackRegistrar.onAdd(OPERATIONAL, FOO_PATH, topLevelList -> {
        if (topLevelList.equals(FOO_DATA)) {
            added.set(true);
        } else {
            LOG.error("Expected: {} but was: {}", FOO_DATA, topLevelList);
            assertThat(topLevelList).isEqualTo(FOO_DATA);
        }
        return nextAction;
    });
    db1.syncWrite(OPERATIONAL, FOO_PATH, FOO_DATA);
    await().untilTrue(added);
    added.set(false);
    db1.syncDelete(OPERATIONAL, FOO_PATH);
    db1.syncWrite(OPERATIONAL, FOO_PATH, FOO_DATA);
    if (nextAction.equals(NextAction.CALL_AGAIN)) {
        await().untilTrue(added);
    } else {
        // TODO see above; this actually isn't really reliable.. it could test "too soon"
        await().untilFalse(added);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) DataTreeEventCallbackRegistrarImpl(org.opendaylight.genius.datastoreutils.listeners.internal.DataTreeEventCallbackRegistrarImpl)

Example 2 with DataTreeEventCallbackRegistrar

use of org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar 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)

Example 3 with DataTreeEventCallbackRegistrar

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

the class DataTreeEventCallbackRegistrarTest method testAddOrUpdateUpdate.

@Test
public void testAddOrUpdateUpdate() throws TransactionCommitFailedException {
    DataTreeEventCallbackRegistrar dataTreeEventCallbackRegistrar = new DataTreeEventCallbackRegistrarImpl(db);
    AtomicBoolean updated = new AtomicBoolean(false);
    dataTreeEventCallbackRegistrar.onAddOrUpdate(OPERATIONAL, FOO_PATH, (first, second) -> {
        if (first != null && second != null) {
            updated.set(true);
            return NextAction.UNREGISTER;
        }
        return NextAction.CALL_AGAIN;
    });
    db1.syncWrite(OPERATIONAL, FOO_PATH, FOO_DATA);
    db1.syncWrite(OPERATIONAL, FOO_PATH, FOO_DATA);
    await().untilTrue(updated);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) DataTreeEventCallbackRegistrarImpl(org.opendaylight.genius.datastoreutils.listeners.internal.DataTreeEventCallbackRegistrarImpl) Test(org.junit.Test)

Example 4 with DataTreeEventCallbackRegistrar

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

the class DataTreeEventCallbackRegistrarTest method testAddOrUpdateAdd.

@Test
public void testAddOrUpdateAdd() throws TransactionCommitFailedException {
    DataTreeEventCallbackRegistrar dataTreeEventCallbackRegistrar = new DataTreeEventCallbackRegistrarImpl(db);
    AtomicBoolean added = new AtomicBoolean(false);
    dataTreeEventCallbackRegistrar.onAddOrUpdate(OPERATIONAL, FOO_PATH, (first, second) -> {
        if (first == null && second != null) {
            added.set(true);
        }
        return NextAction.UNREGISTER;
    });
    db1.syncWrite(OPERATIONAL, FOO_PATH, FOO_DATA);
    await().untilTrue(added);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) DataTreeEventCallbackRegistrarImpl(org.opendaylight.genius.datastoreutils.listeners.internal.DataTreeEventCallbackRegistrarImpl) Test(org.junit.Test)

Aggregations

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