Migrate from JavaTestKit to javadsl.TestKit
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / DataTreeChangeListenerProxyTest.java
index 820fe5614fadaf96d970a40e0722196a2c0e8ef7..7b23260e91f618859524e477dc5a417b5ca01cb7 100644 (file)
@@ -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,6 +27,7 @@ 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.CloseDataTreeNotificationListenerRegistration;
@@ -34,9 +35,8 @@ 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,7 +51,7 @@ 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));
@@ -60,13 +60,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest {
                 final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(
                         actorContext, mockListener, path);
 
-                new Thread() {
-                    @Override
-                    public void run() {
-                        proxy.init("shard-1");
-                    }
-
-                }.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);
@@ -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));
@@ -119,13 +113,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest {
                 final DataTreeChangeListenerProxy<ClusteredDOMDataTreeChangeListener> proxy =
                         new DataTreeChangeListenerProxy<>(actorContext, mockClusteredListener, path);
 
-                new Thread() {
-                    @Override
-                    public void run() {
-                        proxy.init("shard-1");
-                    }
-
-                }.start();
+                new Thread(() -> proxy.init("shard-1")).start();
 
                 FiniteDuration timeout = duration("5 seconds");
                 FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
@@ -145,7 +133,7 @@ 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));
@@ -154,13 +142,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest {
                 final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(
                         actorContext, mockListener, path);
 
-                new Thread() {
-                    @Override
-                    public void run() {
-                        proxy.init("shard-1");
-                    }
-
-                }.start();
+                new Thread(() -> proxy.init("shard-1")).start();
 
                 FiniteDuration timeout = duration("5 seconds");
                 FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
@@ -177,7 +159,7 @@ 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));
@@ -186,13 +168,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest {
                 final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(
                         actorContext, mockListener, path);
 
-                new Thread() {
-                    @Override
-                    public void run() {
-                        proxy.init("shard-1");
-                    }
-
-                }.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);
 
@@ -250,7 +224,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest {
 
     @Test
     public void testCloseBeforeRegistration() {
-        new JavaTestKit(getSystem()) {
+        new TestKit(getSystem()) {
             {
                 ActorContext actorContext = mock(ActorContext.class);
 
@@ -270,7 +244,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest {
 
                 Answer<Future<Object>> 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),