use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class DataChangeListenerSupportTest method testInitialChangeListenerEventWhenNotInitiallyLeader.
@Test
public void testInitialChangeListenerEventWhenNotInitiallyLeader() throws Exception {
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> actor = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testInitialChangeListenerEventWhenNotInitiallyLeader");
waitUntilLeader(actor);
final Shard shard = actor.underlyingActor();
mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(outerNode(outerNodeEntry(1, innerNode("one", "two")), outerNodeEntry(2, innerNode("three", "four")))));
final MockDataChangeListener listener = new MockDataChangeListener(0);
final YangInstanceIdentifier path = OUTER_LIST_PATH.node(OUTER_LIST_QNAME).node(INNER_LIST_QNAME).node(INNER_LIST_QNAME);
final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, path), "testInitialChangeListenerEventWhenNotInitiallyLeader-DataChangeListener");
final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
support.onMessage(new RegisterChangeListener(path, dclActor, DataChangeScope.ONE, false), false, true);
listener.expectNoMoreChanges("Unexpected initial change event");
listener.reset(1);
support.onLeadershipChange(true, true);
listener.waitForChangeEvents();
listener.verifyCreatedData(0, innerEntryPath(1, "one"));
listener.verifyCreatedData(0, innerEntryPath(1, "two"));
listener.verifyCreatedData(0, innerEntryPath(2, "three"));
listener.verifyCreatedData(0, innerEntryPath(2, "four"));
}
};
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class DataTreeChangeListenerProxyTest method testLocalShardNotInitialized.
@Test(timeout = 10000)
public void testLocalShardNotInitialized() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
new Thread(() -> proxy.init("shard-1")).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new NotInitializedException("not initialized"));
within(duration("1 seconds"), () -> {
expectNoMsg();
return null;
});
proxy.close();
}
};
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class DataTreeChangeListenerProxyTest method testFailedRegistration.
@Test
public void testFailedRegistration() {
new TestKit(getSystem()) {
{
ActorSystem mockActorSystem = mock(ActorSystem.class);
ActorRef mockActor = getSystem().actorOf(Props.create(DoNothingActor.class), "testFailedRegistration");
doReturn(mockActor).when(mockActorSystem).actorOf(any(Props.class));
ExecutionContextExecutor executor = ExecutionContexts.fromExecutor(MoreExecutors.directExecutor());
ActorContext actorContext = mock(ActorContext.class);
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
doReturn(executor).when(actorContext).getClientDispatcher();
doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
doReturn(mockActorSystem).when(actorContext).getActorSystem();
String shardName = "shard-1";
final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
doReturn(Futures.failed(new RuntimeException("mock"))).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class));
doReturn(mock(DatastoreContext.class)).when(actorContext).getDatastoreContext();
proxy.init("shard-1");
Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
proxy.close();
}
};
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class DataTreeChangeListenerProxyTest method testLocalShardNotFound.
@Test(timeout = 10000)
public void testLocalShardNotFound() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
new Thread(() -> proxy.init("shard-1")).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();
}
};
}
Aggregations