Remove use of {String,UUID}Identifier
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / ActorContextTest.java
index 2b9b9d635e4f4e0861d71ba00c833efff002ad44..405fe5221b64255e086db7b37eb1af1679e4da18 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
 package org.opendaylight.controller.cluster.datastore.utils;
 
 import static org.junit.Assert.assertEquals;
@@ -23,19 +31,20 @@ import akka.util.Timeout;
 import com.google.common.base.Optional;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.Uninterruptibles;
 import com.typesafe.config.ConfigFactory;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.opendaylight.controller.cluster.datastore.AbstractActorTest;
 import org.opendaylight.controller.cluster.datastore.ClusterWrapper;
-import org.opendaylight.controller.cluster.datastore.Configuration;
 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
+import org.opendaylight.controller.cluster.datastore.DatastoreContextFactory;
+import org.opendaylight.controller.cluster.datastore.config.Configuration;
 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
 import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException;
 import org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException;
@@ -46,6 +55,9 @@ import org.opendaylight.controller.cluster.datastore.messages.LocalShardFound;
 import org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound;
 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.yangtools.yang.data.api.schema.tree.DataTree;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -281,53 +293,6 @@ public class ActorContextTest extends AbstractActorTest{
         assertEquals(false, actorContext.isPathLocal("akka.tcp://system@127.0.0.1:2551/"));
     }
 
-    @Test
-    public void testResolvePathForRemoteActor() {
-        ActorContext actorContext =
-                new ActorContext(getSystem(), mock(ActorRef.class), mock(
-                        ClusterWrapper.class),
-                        mock(Configuration.class));
-
-        String actual = actorContext.resolvePath(
-                "akka.tcp://system@127.0.0.1:2550/user/shardmanager/shard",
-                "akka://system/user/shardmanager/shard/transaction");
-
-        String expected = "akka.tcp://system@127.0.0.1:2550/user/shardmanager/shard/transaction";
-
-        assertEquals(expected, actual);
-    }
-
-    @Test
-    public void testResolvePathForLocalActor() {
-        ActorContext actorContext =
-                new ActorContext(getSystem(), mock(ActorRef.class), mock(ClusterWrapper.class),
-                        mock(Configuration.class));
-
-        String actual = actorContext.resolvePath(
-                "akka://system/user/shardmanager/shard",
-                "akka://system/user/shardmanager/shard/transaction");
-
-        String expected = "akka://system/user/shardmanager/shard/transaction";
-
-        assertEquals(expected, actual);
-    }
-
-    @Test
-    public void testResolvePathForRemoteActorWithProperRemoteAddress() {
-        ActorContext actorContext =
-                new ActorContext(getSystem(), mock(ActorRef.class), mock(ClusterWrapper.class),
-                        mock(Configuration.class));
-
-        String actual = actorContext.resolvePath(
-                "akka.tcp://system@7.0.0.1:2550/user/shardmanager/shard",
-                "akka.tcp://system@7.0.0.1:2550/user/shardmanager/shard/transaction");
-
-        String expected = "akka.tcp://system@7.0.0.1:2550/user/shardmanager/shard/transaction";
-
-        assertEquals(expected, actual);
-    }
-
-
     @Test
     public void testClientDispatcherIsGlobalDispatcher(){
         ActorContext actorContext =
@@ -366,9 +331,12 @@ public class ActorContextTest extends AbstractActorTest{
             DatastoreContext newContext = DatastoreContext.newBuilder().operationTimeoutInSeconds(6).
                     shardTransactionCommitTimeoutInSeconds(8).build();
 
-            actorContext.setDatastoreContext(newContext);
+            DatastoreContextFactory mockContextFactory = mock(DatastoreContextFactory.class);
+            Mockito.doReturn(newContext).when(mockContextFactory).getBaseDatastoreContext();
+
+            actorContext.setDatastoreContext(mockContextFactory);
 
-            expectMsgClass(duration("5 seconds"), DatastoreContext.class);
+            expectMsgClass(duration("5 seconds"), DatastoreContextFactory.class);
 
             Assert.assertSame("getDatastoreContext", newContext, actorContext.getDatastoreContext());
 
@@ -384,7 +352,8 @@ public class ActorContextTest extends AbstractActorTest{
             TestActorRef<MessageCollectorActor> shardManager =
                     TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class));
 
-            DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config").
+            DatastoreContext dataStoreContext = DatastoreContext.newBuilder().
+                    logicalStoreType(LogicalDatastoreType.CONFIGURATION).
                     shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build();
 
             final String expPrimaryPath = "akka://test-system/find-primary-shard";
@@ -426,7 +395,8 @@ public class ActorContextTest extends AbstractActorTest{
             TestActorRef<MessageCollectorActor> shardManager =
                     TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class));
 
-            DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config").
+            DatastoreContext dataStoreContext = DatastoreContext.newBuilder().
+                    logicalStoreType(LogicalDatastoreType.CONFIGURATION).
                     shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build();
 
             final DataTree mockDataTree = Mockito.mock(DataTree.class);
@@ -477,7 +447,8 @@ public class ActorContextTest extends AbstractActorTest{
         TestActorRef<MessageCollectorActor> shardManager =
             TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class));
 
-        DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config").
+        DatastoreContext dataStoreContext = DatastoreContext.newBuilder().
+            logicalStoreType(LogicalDatastoreType.CONFIGURATION).
             shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build();
 
         ActorContext actorContext =
@@ -527,27 +498,16 @@ public class ActorContextTest extends AbstractActorTest{
                     mock(ClusterWrapper.class), mockConfig,
                     DatastoreContext.newBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), new PrimaryShardInfoFutureCache());
 
-            actorContext.broadcast(new TestMessage());
+            actorContext.broadcast(new Function<Short, Object>() {
+                @Override
+                public Object apply(Short v) {
+                    return new TestMessage();
+                }
+            });
 
-            expectFirstMatching(shardActorRef1, TestMessage.class);
-            expectFirstMatching(shardActorRef2, TestMessage.class);
+            MessageCollectorActor.expectFirstMatching(shardActorRef1, TestMessage.class);
+            MessageCollectorActor.expectFirstMatching(shardActorRef2, TestMessage.class);
         }};
     }
 
-    private <T> T expectFirstMatching(ActorRef actor, Class<T> clazz) {
-        int count = 5000 / 50;
-        for(int i = 0; i < count; i++) {
-            try {
-                T message = (T) MessageCollectorActor.getFirstMatching(actor, clazz);
-                if(message != null) {
-                    return message;
-                }
-            } catch (Exception e) {}
-
-            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
-        }
-
-        Assert.fail("Did not receive message of type " + clazz);
-        return null;
-    }
 }