Migrate to expectNoMessage()
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / ActorContextTest.java
index 78a00fb00ea169a75314940a7294f8b8437eda0a..a1ff319c36803009c744975834b9310c3eba6091 100644 (file)
@@ -23,11 +23,11 @@ import akka.actor.ActorSelection;
 import akka.actor.ActorSystem;
 import akka.actor.Address;
 import akka.actor.Props;
-import akka.actor.UntypedActor;
+import akka.actor.UntypedAbstractActor;
 import akka.dispatch.Futures;
 import akka.japi.Creator;
-import akka.testkit.JavaTestKit;
 import akka.testkit.TestActorRef;
+import akka.testkit.javadsl.TestKit;
 import akka.util.Timeout;
 import com.google.common.base.Optional;
 import com.google.common.collect.Maps;
@@ -57,7 +57,7 @@ import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
 import org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound;
 import org.opendaylight.controller.cluster.raft.utils.EchoActor;
 import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -73,7 +73,7 @@ public class ActorContextTest extends AbstractActorTest {
     private static class TestMessage {
     }
 
-    private static class MockShardManager extends UntypedActor {
+    private static final class MockShardManager extends UntypedAbstractActor {
 
         private final boolean found;
         private final ActorRef actorRef;
@@ -85,7 +85,7 @@ public class ActorContextTest extends AbstractActorTest {
             this.actorRef = actorRef;
         }
 
-        @Override public void onReceive(final Object message) throws Exception {
+        @Override public void onReceive(final Object message) {
             if (message instanceof FindPrimary) {
                 FindPrimary fp = (FindPrimary)message;
                 Object resp = findPrimaryResponses.get(fp.getShardName());
@@ -110,11 +110,11 @@ public class ActorContextTest extends AbstractActorTest {
         }
 
         private static Props props(final boolean found, final ActorRef actorRef) {
-            return Props.create(new MockShardManagerCreator(found, actorRef) );
+            return Props.create(new MockShardManagerCreator(found, actorRef));
         }
 
         private static Props props() {
-            return Props.create(new MockShardManagerCreator() );
+            return Props.create(new MockShardManagerCreator());
         }
 
         @SuppressWarnings("serial")
@@ -133,7 +133,7 @@ public class ActorContextTest extends AbstractActorTest {
             }
 
             @Override
-            public MockShardManager create() throws Exception {
+            public MockShardManager create() {
                 return new MockShardManager(found, actorRef);
             }
         }
@@ -141,27 +141,24 @@ public class ActorContextTest extends AbstractActorTest {
 
     @Test
     public void testFindLocalShardWithShardFound() {
-        new JavaTestKit(getSystem()) {
+        new TestKit(getSystem()) {
             {
-                new Within(duration("1 seconds")) {
-                    @Override
-                    protected void run() {
+                within(duration("1 seconds"), () -> {
+                    ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));
 
-                        ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));
+                    ActorRef shardManagerActorRef = getSystem()
+                            .actorOf(MockShardManager.props(true, shardActorRef));
 
-                        ActorRef shardManagerActorRef = getSystem()
-                                .actorOf(MockShardManager.props(true, shardActorRef));
-
-                        ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef,
-                                mock(ClusterWrapper.class), mock(Configuration.class));
+                    ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef,
+                        mock(ClusterWrapper.class), mock(Configuration.class));
 
-                        Optional<ActorRef> out = actorContext.findLocalShard("default");
+                    Optional<ActorRef> out = actorContext.findLocalShard("default");
 
-                        assertEquals(shardActorRef, out.get());
+                    assertEquals(shardActorRef, out.get());
 
-                        expectNoMsg();
-                    }
-                };
+                    expectNoMessage();
+                    return null;
+                });
             }
         };
 
@@ -169,7 +166,7 @@ public class ActorContextTest extends AbstractActorTest {
 
     @Test
     public void testFindLocalShardWithShardNotFound() {
-        new JavaTestKit(getSystem()) {
+        new TestKit(getSystem()) {
             {
                 ActorRef shardManagerActorRef = getSystem().actorOf(MockShardManager.props(false, null));
 
@@ -185,7 +182,7 @@ public class ActorContextTest extends AbstractActorTest {
 
     @Test
     public void testExecuteRemoteOperation() {
-        new JavaTestKit(getSystem()) {
+        new TestKit(getSystem()) {
             {
                 ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));
 
@@ -206,7 +203,7 @@ public class ActorContextTest extends AbstractActorTest {
     @Test
     @SuppressWarnings("checkstyle:IllegalCatch")
     public void testExecuteRemoteOperationAsync() {
-        new JavaTestKit(getSystem()) {
+        new TestKit(getSystem()) {
             {
                 ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));
 
@@ -256,13 +253,13 @@ public class ActorContextTest extends AbstractActorTest {
         assertEquals(true, actorContext.isPathLocal("akka://test/user/token2/token3/$a"));
 
         // self address of remote format,but Tx path local format.
-        clusterWrapper.setSelfAddress(new Address("akka.tcp", "system", "127.0.0.1", 2550));
+        clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
         actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
         assertEquals(true, actorContext.isPathLocal(
             "akka://system/user/shardmanager/shard/transaction"));
 
         // self address of local format,but Tx path remote format.
-        clusterWrapper.setSelfAddress(new Address("akka.tcp", "system"));
+        clusterWrapper.setSelfAddress(new Address("akka", "system"));
         actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
         assertEquals(false, actorContext.isPathLocal(
             "akka://system@127.0.0.1:2550/user/shardmanager/shard/transaction"));
@@ -273,24 +270,24 @@ public class ActorContextTest extends AbstractActorTest {
         assertEquals(true, actorContext.isPathLocal("akka://test1/user/$a"));
 
         //ip and port same
-        clusterWrapper.setSelfAddress(new Address("akka.tcp", "system", "127.0.0.1", 2550));
+        clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
         actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
-        assertEquals(true, actorContext.isPathLocal("akka.tcp://system@127.0.0.1:2550/"));
+        assertEquals(true, actorContext.isPathLocal("akka://system@127.0.0.1:2550/"));
 
         // forward-slash missing in address
-        clusterWrapper.setSelfAddress(new Address("akka.tcp", "system", "127.0.0.1", 2550));
+        clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
         actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
-        assertEquals(false, actorContext.isPathLocal("akka.tcp://system@127.0.0.1:2550"));
+        assertEquals(false, actorContext.isPathLocal("akka://system@127.0.0.1:2550"));
 
         //ips differ
-        clusterWrapper.setSelfAddress(new Address("akka.tcp", "system", "127.0.0.1", 2550));
+        clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
         actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
-        assertEquals(false, actorContext.isPathLocal("akka.tcp://system@127.1.0.1:2550/"));
+        assertEquals(false, actorContext.isPathLocal("akka://system@127.1.0.1:2550/"));
 
         //ports differ
-        clusterWrapper.setSelfAddress(new Address("akka.tcp", "system", "127.0.0.1", 2550));
+        clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
         actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
-        assertEquals(false, actorContext.isPathLocal("akka.tcp://system@127.0.0.1:2551/"));
+        assertEquals(false, actorContext.isPathLocal("akka://system@127.0.0.1:2551/"));
     }
 
     @Test
@@ -316,7 +313,7 @@ public class ActorContextTest extends AbstractActorTest {
 
     @Test
     public void testSetDatastoreContext() {
-        new JavaTestKit(getSystem()) {
+        new TestKit(getSystem()) {
             {
                 ActorContext actorContext = new ActorContext(getSystem(), getRef(),
                         mock(ClusterWrapper.class), mock(Configuration.class), DatastoreContext.newBuilder()
@@ -349,8 +346,7 @@ public class ActorContextTest extends AbstractActorTest {
     @Test
     public void testFindPrimaryShardAsyncRemotePrimaryFound() throws Exception {
 
-        TestActorRef<MessageCollectorActor> shardManager = TestActorRef.create(getSystem(),
-                Props.create(MessageCollectorActor.class));
+        ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props());
 
         DatastoreContext dataStoreContext = DatastoreContext.newBuilder()
                 .logicalStoreType(LogicalDatastoreType.CONFIGURATION)
@@ -391,8 +387,7 @@ public class ActorContextTest extends AbstractActorTest {
     @Test
     public void testFindPrimaryShardAsyncLocalPrimaryFound() throws Exception {
 
-        TestActorRef<MessageCollectorActor> shardManager = TestActorRef.create(getSystem(),
-                Props.create(MessageCollectorActor.class));
+        ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props());
 
         DatastoreContext dataStoreContext = DatastoreContext.newBuilder()
                 .logicalStoreType(LogicalDatastoreType.CONFIGURATION)
@@ -432,19 +427,18 @@ public class ActorContextTest extends AbstractActorTest {
     }
 
     @Test
-    public void testFindPrimaryShardAsyncPrimaryNotFound() throws Exception {
+    public void testFindPrimaryShardAsyncPrimaryNotFound() {
         testFindPrimaryExceptions(new PrimaryNotFoundException("not found"));
     }
 
     @Test
-    public void testFindPrimaryShardAsyncActorNotInitialized() throws Exception {
+    public void testFindPrimaryShardAsyncActorNotInitialized() {
         testFindPrimaryExceptions(new NotInitializedException("not initialized"));
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
-    private static void testFindPrimaryExceptions(final Object expectedException) throws Exception {
-        TestActorRef<MessageCollectorActor> shardManager =
-            TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class));
+    private static void testFindPrimaryExceptions(final Object expectedException) {
+        ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props());
 
         DatastoreContext dataStoreContext = DatastoreContext.newBuilder()
                 .logicalStoreType(LogicalDatastoreType.CONFIGURATION)
@@ -477,10 +471,10 @@ public class ActorContextTest extends AbstractActorTest {
 
     @Test
     public void testBroadcast() {
-        new JavaTestKit(getSystem()) {
+        new TestKit(getSystem()) {
             {
-                ActorRef shardActorRef1 = getSystem().actorOf(Props.create(MessageCollectorActor.class));
-                ActorRef shardActorRef2 = getSystem().actorOf(Props.create(MessageCollectorActor.class));
+                ActorRef shardActorRef1 = getSystem().actorOf(MessageCollectorActor.props());
+                ActorRef shardActorRef2 = getSystem().actorOf(MessageCollectorActor.props());
 
                 TestActorRef<MockShardManager> shardManagerActorRef = TestActorRef.create(getSystem(),
                         MockShardManager.props());