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);
}
}
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);
}
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);
}
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);
}
Aggregations