X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDataTreeChangeListenerProxyTest.java;h=7b23260e91f618859524e477dc5a417b5ca01cb7;hp=8cf0d83a79dcfa6239e1b783352173264e924ab2;hb=e9fc7e7ed2b13d274518d6a872ab67749ef4507a;hpb=5464f50be733df1bbbe31cf05665d542d3b7c5e7 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java index 8cf0d83a79..7b23260e91 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java @@ -19,7 +19,7 @@ import akka.actor.Props; import akka.actor.Terminated; import akka.dispatch.ExecutionContexts; import akka.dispatch.Futures; -import akka.testkit.JavaTestKit; +import akka.testkit.javadsl.TestKit; import akka.util.Timeout; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.Uninterruptibles; @@ -27,16 +27,16 @@ import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Test; import org.mockito.stubbing.Answer; +import org.opendaylight.controller.cluster.common.actor.Dispatchers; import org.opendaylight.controller.cluster.datastore.config.Configuration; import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException; -import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeChangeListenerRegistration; +import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeNotificationListenerRegistration; import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; import org.opendaylight.controller.cluster.datastore.messages.LocalShardFound; import org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound; import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener; -import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListenerReply; +import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; -import org.opendaylight.controller.cluster.datastore.utils.Dispatchers; import org.opendaylight.controller.cluster.raft.utils.DoNothingActor; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener; @@ -51,22 +51,16 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test(timeout = 10000) public void testSuccessfulRegistration() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class)); - final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener); - final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); - new Thread() { - @Override - public void run() { - proxy.init("shard-1", path); - } + final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( + actorContext, mockListener, path); - }.start(); + new Thread(() -> proxy.init("shard-1")).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -79,7 +73,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { Assert.assertEquals("getPath", path, registerMsg.getPath()); Assert.assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances()); - reply(new RegisterDataTreeChangeListenerReply(getRef())); + reply(new RegisterDataTreeNotificationListenerReply(getRef())); for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) { Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); @@ -93,7 +87,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { proxy.close(); // The listener registration actor should get a Close message - expectMsgClass(timeout, CloseDataTreeChangeListenerRegistration.class); + expectMsgClass(timeout, CloseDataTreeNotificationListenerRegistration.class); // The DataChangeListener actor should be terminated expectMsgClass(timeout, Terminated.class); @@ -107,7 +101,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test(timeout = 10000) public void testSuccessfulRegistrationForClusteredListener() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class)); @@ -115,17 +109,11 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { ClusteredDOMDataTreeChangeListener mockClusteredListener = mock( ClusteredDOMDataTreeChangeListener.class); - final DataTreeChangeListenerProxy proxy = - new DataTreeChangeListenerProxy<>(actorContext, mockClusteredListener); - final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); - new Thread() { - @Override - public void run() { - proxy.init("shard-1", path); - } + final DataTreeChangeListenerProxy proxy = + new DataTreeChangeListenerProxy<>(actorContext, mockClusteredListener, path); - }.start(); + new Thread(() -> proxy.init("shard-1")).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -145,22 +133,16 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test(timeout = 10000) public void testLocalShardNotFound() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class)); - final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener); - final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); - new Thread() { - @Override - public void run() { - proxy.init("shard-1", path); - } + final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( + actorContext, mockListener, path); - }.start(); + new Thread(() -> proxy.init("shard-1")).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -177,22 +159,16 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test(timeout = 10000) public void testLocalShardNotInitialized() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class)); - final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener); - final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); - new Thread() { - @Override - public void run() { - proxy.init("shard-1", path); - } + final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( + actorContext, mockListener, path); - }.start(); + new Thread(() -> proxy.init("shard-1")).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -200,12 +176,10 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { reply(new NotInitializedException("not initialized")); - new Within(duration("1 seconds")) { - @Override - protected void run() { - expectNoMsg(); - } - }; + within(duration("1 seconds"), () -> { + expectNoMsg(); + return null; + }); proxy.close(); } @@ -214,7 +188,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test public void testFailedRegistration() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorSystem mockActorSystem = mock(ActorSystem.class); @@ -226,11 +200,12 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { 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 proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener); + actorContext, mockListener, path); doReturn(duration("5 seconds")).when(actorContext).getOperationDuration(); doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName)); @@ -238,7 +213,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { .executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class)); doReturn(mock(DatastoreContext.class)).when(actorContext).getDatastoreContext(); - proxy.init("shard-1", path); + proxy.init("shard-1"); Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor()); @@ -249,7 +224,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test public void testCloseBeforeRegistration() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorContext actorContext = mock(ActorContext.class); @@ -265,19 +240,19 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName)); final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener); + actorContext, mockListener, YangInstanceIdentifier.of(TestModel.TEST_QNAME)); Answer> answer = invocation -> { proxy.close(); - return Futures.successful((Object) new RegisterDataTreeChangeListenerReply(getRef())); + return Futures.successful((Object) new RegisterDataTreeNotificationListenerReply(getRef())); }; doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class)); - proxy.init(shardName, YangInstanceIdentifier.of(TestModel.TEST_QNAME)); + proxy.init(shardName); - expectMsgClass(duration("5 seconds"), CloseDataTreeChangeListenerRegistration.class); + expectMsgClass(duration("5 seconds"), CloseDataTreeNotificationListenerRegistration.class); Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor()); }