use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope in project controller by opendaylight.
the class DataChangeListenerRegistrationProxyTest method testSuccessfulRegistrationForClusteredListener.
@Test(timeout = 10000)
public void testSuccessfulRegistrationForClusteredListener() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> mockClusteredListener = Mockito.mock(ClusteredDOMDataChangeListener.class);
final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockClusteredListener);
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
new Thread(() -> proxy.init(path, scope)).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new LocalShardFound(getRef()));
RegisterChangeListener registerMsg = expectMsgClass(timeout, RegisterChangeListener.class);
Assert.assertEquals("getPath", path, registerMsg.getPath());
Assert.assertEquals("getScope", scope, registerMsg.getScope());
Assert.assertEquals("isRegisterOnAllInstances", true, registerMsg.isRegisterOnAllInstances());
reply(new RegisterDataTreeNotificationListenerReply(getRef()));
for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) {
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()), proxy.getListenerRegistrationActor());
watch(proxy.getDataChangeListenerActor());
proxy.close();
// The listener registration actor should get a Close message
expectMsgClass(timeout, CloseDataTreeNotificationListenerRegistration.class);
// The DataChangeListener actor should be terminated
expectMsgClass(timeout, Terminated.class);
proxy.close();
expectNoMsg();
}
};
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope in project controller by opendaylight.
the class DataChangeListenerRegistrationProxyTest method testLocalShardNotInitialized.
@Test(timeout = 10000)
public void testLocalShardNotInitialized() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockListener);
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
new Thread(() -> proxy.init(path, scope)).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new NotInitializedException("not initialized"));
expectNoMsg(duration("1 seconds"));
proxy.close();
}
};
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope in project controller by opendaylight.
the class DataChangeListenerRegistrationProxyTest method testLocalShardNotFound.
@Test(timeout = 10000)
public void testLocalShardNotFound() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockListener);
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
new Thread(() -> proxy.init(path, scope)).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new LocalShardNotFound("shard-1"));
expectNoMsg(duration("1 seconds"));
proxy.close();
}
};
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope in project controller by opendaylight.
the class ResolveDataChangeEventsTask method resolveSubtreeChangeEvent.
private boolean resolveSubtreeChangeEvent(final ResolveDataChangeState state, final DataTreeCandidateNode modification) {
final Optional<NormalizedNode<?, ?>> maybeBefore = modification.getDataBefore();
final Optional<NormalizedNode<?, ?>> maybeAfter = modification.getDataAfter();
Preconditions.checkArgument(maybeBefore.isPresent(), "Subtree change with before-data not present at path %s", state.getPath());
Preconditions.checkArgument(maybeAfter.isPresent(), "Subtree change with after-data not present at path %s", state.getPath());
if (!state.needsProcessing()) {
LOG.trace("Not processing modified subtree {}", state.getPath());
return true;
}
DataChangeScope scope = null;
for (DataTreeCandidateNode childMod : modification.getChildNodes()) {
final ResolveDataChangeState childState = state.child(childMod.getIdentifier());
switch(childMod.getModificationType()) {
case APPEARED:
case DELETE:
case DISAPPEARED:
case WRITE:
if (resolveAnyChangeEvent(childState, childMod)) {
scope = DataChangeScope.ONE;
}
break;
case SUBTREE_MODIFIED:
if (resolveSubtreeChangeEvent(childState, childMod) && scope == null) {
scope = DataChangeScope.SUBTREE;
}
break;
case UNMODIFIED:
// no-op
break;
default:
break;
}
}
final NormalizedNode<?, ?> before = maybeBefore.get();
final NormalizedNode<?, ?> after = maybeAfter.get();
if (scope != null) {
DOMImmutableDataChangeEvent one = DOMImmutableDataChangeEvent.builder(scope).addUpdated(state.getPath(), before, after).build();
state.addEvent(one);
}
state.collectEvents(before, after, collectedEvents);
return scope != null;
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope in project controller by opendaylight.
the class DataChangeListenerRegistrationProxyTest method testSuccessfulRegistration.
@Test(timeout = 10000)
public void testSuccessfulRegistration() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockListener);
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
new Thread(() -> proxy.init(path, scope)).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new LocalShardFound(getRef()));
RegisterChangeListener registerMsg = expectMsgClass(timeout, RegisterChangeListener.class);
Assert.assertEquals("getPath", path, registerMsg.getPath());
Assert.assertEquals("getScope", scope, registerMsg.getScope());
Assert.assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances());
reply(new RegisterDataTreeNotificationListenerReply(getRef()));
for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) {
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()), proxy.getListenerRegistrationActor());
watch(proxy.getDataChangeListenerActor());
proxy.close();
// The listener registration actor should get a Close message
expectMsgClass(timeout, CloseDataTreeNotificationListenerRegistration.class);
// The DataChangeListener actor should be terminated
expectMsgClass(timeout, Terminated.class);
proxy.close();
expectNoMsg();
}
};
}
Aggregations