X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDataTreeChangeListenerProxyTest.java;h=373d4d7188b155a6e6da9ba0a861cc7cf576da1f;hb=9b319f491af1c65705b69e8a182aab5006a2f959;hp=545b976ee820f1eac74174ccd2f8ada8bd8bfbbc;hpb=bf887b0ecebf65746684691a0cd4d448ad8606f1;p=controller.git 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 545b976ee8..373d4d7188 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 @@ -8,8 +8,10 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -24,6 +26,7 @@ import akka.testkit.javadsl.TestKit; import akka.util.Timeout; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.Uninterruptibles; +import java.time.Duration; import java.util.concurrent.TimeUnit; import org.junit.Test; import org.mockito.stubbing.Answer; @@ -36,7 +39,7 @@ 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.RegisterDataTreeNotificationListenerReply; -import org.opendaylight.controller.cluster.datastore.utils.ActorContext; +import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; import org.opendaylight.controller.cluster.raft.utils.DoNothingActor; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener; @@ -44,7 +47,6 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import scala.concurrent.ExecutionContextExecutor; import scala.concurrent.Future; -import scala.concurrent.duration.FiniteDuration; public class DataTreeChangeListenerProxyTest extends AbstractActorTest { private final DOMDataTreeChangeListener mockListener = mock(DOMDataTreeChangeListener.class); @@ -52,16 +54,16 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test(timeout = 10000) public void testSuccessfulRegistration() { final TestKit kit = new TestKit(getSystem()); - ActorContext actorContext = new ActorContext(getSystem(), kit.getRef(), mock(ClusterWrapper.class), + ActorUtils actorUtils = new ActorUtils(getSystem(), kit.getRef(), mock(ClusterWrapper.class), mock(Configuration.class)); final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener, path); + actorUtils, mockListener, path); new Thread(() -> proxy.init("shard-1")).start(); - FiniteDuration timeout = kit.duration("5 seconds"); + Duration timeout = Duration.ofSeconds(5); FindLocalShard findLocalShard = kit.expectMsgClass(timeout, FindLocalShard.class); assertEquals("getShardName", "shard-1", findLocalShard.getShardName()); @@ -70,7 +72,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { RegisterDataTreeChangeListener registerMsg = kit.expectMsgClass(timeout, RegisterDataTreeChangeListener.class); assertEquals("getPath", path, registerMsg.getPath()); - assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances()); + assertFalse("isRegisterOnAllInstances", registerMsg.isRegisterOnAllInstances()); kit.reply(new RegisterDataTreeNotificationListenerReply(kit.getRef())); @@ -99,7 +101,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test(timeout = 10000) public void testSuccessfulRegistrationForClusteredListener() { final TestKit kit = new TestKit(getSystem()); - ActorContext actorContext = new ActorContext(getSystem(), kit.getRef(), mock(ClusterWrapper.class), + ActorUtils actorUtils = new ActorUtils(getSystem(), kit.getRef(), mock(ClusterWrapper.class), mock(Configuration.class)); ClusteredDOMDataTreeChangeListener mockClusteredListener = mock( @@ -107,11 +109,11 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); final DataTreeChangeListenerProxy proxy = - new DataTreeChangeListenerProxy<>(actorContext, mockClusteredListener, path); + new DataTreeChangeListenerProxy<>(actorUtils, mockClusteredListener, path); new Thread(() -> proxy.init("shard-1")).start(); - FiniteDuration timeout = kit.duration("5 seconds"); + Duration timeout = Duration.ofSeconds(5); FindLocalShard findLocalShard = kit.expectMsgClass(timeout, FindLocalShard.class); assertEquals("getShardName", "shard-1", findLocalShard.getShardName()); @@ -120,7 +122,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { RegisterDataTreeChangeListener registerMsg = kit.expectMsgClass(timeout, RegisterDataTreeChangeListener.class); assertEquals("getPath", path, registerMsg.getPath()); - assertEquals("isRegisterOnAllInstances", true, registerMsg.isRegisterOnAllInstances()); + assertTrue("isRegisterOnAllInstances", registerMsg.isRegisterOnAllInstances()); proxy.close(); } @@ -128,22 +130,22 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test(timeout = 10000) public void testLocalShardNotFound() { final TestKit kit = new TestKit(getSystem()); - ActorContext actorContext = new ActorContext(getSystem(), kit.getRef(), mock(ClusterWrapper.class), + ActorUtils actorUtils = new ActorUtils(getSystem(), kit.getRef(), mock(ClusterWrapper.class), mock(Configuration.class)); final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener, path); + actorUtils, mockListener, path); new Thread(() -> proxy.init("shard-1")).start(); - FiniteDuration timeout = kit.duration("5 seconds"); + Duration timeout = Duration.ofSeconds(5); FindLocalShard findLocalShard = kit.expectMsgClass(timeout, FindLocalShard.class); assertEquals("getShardName", "shard-1", findLocalShard.getShardName()); kit.reply(new LocalShardNotFound("shard-1")); - kit.expectNoMessage(kit.duration("1 seconds")); + kit.expectNoMessage(Duration.ofSeconds(1)); proxy.close(); } @@ -151,22 +153,22 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test(timeout = 10000) public void testLocalShardNotInitialized() { final TestKit kit = new TestKit(getSystem()); - ActorContext actorContext = new ActorContext(getSystem(), kit.getRef(), mock(ClusterWrapper.class), + ActorUtils actorUtils = new ActorUtils(getSystem(), kit.getRef(), mock(ClusterWrapper.class), mock(Configuration.class)); final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener, path); + actorUtils, mockListener, path); new Thread(() -> proxy.init("shard-1")).start(); - FiniteDuration timeout = kit.duration("5 seconds"); + Duration timeout = Duration.ofSeconds(5); FindLocalShard findLocalShard = kit.expectMsgClass(timeout, FindLocalShard.class); assertEquals("getShardName", "shard-1", findLocalShard.getShardName()); kit.reply(new NotInitializedException("not initialized")); - kit.within(kit.duration("1 seconds"), () -> { + kit.within(Duration.ofSeconds(1), () -> { kit.expectNoMessage(); return null; }); @@ -183,22 +185,22 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { doReturn(mockActor).when(mockActorSystem).actorOf(any(Props.class)); ExecutionContextExecutor executor = ExecutionContexts.fromExecutor(MoreExecutors.directExecutor()); - ActorContext actorContext = mock(ActorContext.class); + ActorUtils actorUtils = mock(ActorUtils.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(); + doReturn(executor).when(actorUtils).getClientDispatcher(); + doReturn(DatastoreContext.newBuilder().build()).when(actorUtils).getDatastoreContext(); + doReturn(mockActorSystem).when(actorUtils).getActorSystem(); String shardName = "shard-1"; final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener, path); + actorUtils, mockListener, path); - doReturn(kit.duration("5 seconds")).when(actorContext).getOperationDuration(); - doReturn(Futures.successful(kit.getRef())).when(actorContext).findLocalShardAsync(eq(shardName)); - doReturn(Futures.failed(new RuntimeException("mock"))).when(actorContext).executeOperationAsync( + doReturn(kit.duration("5 seconds")).when(actorUtils).getOperationDuration(); + doReturn(Futures.successful(kit.getRef())).when(actorUtils).findLocalShardAsync(eq(shardName)); + doReturn(Futures.failed(new RuntimeException("mock"))).when(actorUtils).executeOperationAsync( any(ActorRef.class), any(Object.class), any(Timeout.class)); - doReturn(mock(DatastoreContext.class)).when(actorContext).getDatastoreContext(); + doReturn(mock(DatastoreContext.class)).when(actorUtils).getDatastoreContext(); proxy.init("shard-1"); @@ -210,33 +212,33 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { @Test public void testCloseBeforeRegistration() { final TestKit kit = new TestKit(getSystem()); - ActorContext actorContext = mock(ActorContext.class); + ActorUtils actorUtils = mock(ActorUtils.class); String shardName = "shard-1"; - doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext(); - doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorContext).getClientDispatcher(); - doReturn(getSystem()).when(actorContext).getActorSystem(); - doReturn(Dispatchers.DEFAULT_DISPATCHER_PATH).when(actorContext).getNotificationDispatcherPath(); - doReturn(getSystem().actorSelection(kit.getRef().path())).when(actorContext).actorSelection( + doReturn(DatastoreContext.newBuilder().build()).when(actorUtils).getDatastoreContext(); + doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorUtils).getClientDispatcher(); + doReturn(getSystem()).when(actorUtils).getActorSystem(); + doReturn(Dispatchers.DEFAULT_DISPATCHER_PATH).when(actorUtils).getNotificationDispatcherPath(); + doReturn(getSystem().actorSelection(kit.getRef().path())).when(actorUtils).actorSelection( kit.getRef().path()); - doReturn(kit.duration("5 seconds")).when(actorContext).getOperationDuration(); - doReturn(Futures.successful(kit.getRef())).when(actorContext).findLocalShardAsync(eq(shardName)); + doReturn(kit.duration("5 seconds")).when(actorUtils).getOperationDuration(); + doReturn(Futures.successful(kit.getRef())).when(actorUtils).findLocalShardAsync(eq(shardName)); final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( - actorContext, mockListener, YangInstanceIdentifier.of(TestModel.TEST_QNAME)); + actorUtils, mockListener, YangInstanceIdentifier.of(TestModel.TEST_QNAME)); Answer> answer = invocation -> { proxy.close(); return Futures.successful((Object) new RegisterDataTreeNotificationListenerReply(kit.getRef())); }; - doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class), + doAnswer(answer).when(actorUtils).executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class)); proxy.init(shardName); - kit.expectMsgClass(kit.duration("5 seconds"), CloseDataTreeNotificationListenerRegistration.class); + kit.expectMsgClass(Duration.ofSeconds(5), CloseDataTreeNotificationListenerRegistration.class); assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor()); }