Fix test to return PrimaryShardInfo when retrieving primary shard 74/19974/1
authorMoiz Raja <moraja@cisco.com>
Wed, 29 Apr 2015 04:00:30 +0000 (21:00 -0700)
committerTom Pantelis <tpanteli@brocade.com>
Sat, 9 May 2015 19:09:34 +0000 (19:09 +0000)
Without these changes the tests log a lot of ClassCastExceptions when
run.

I also removed one method in the test that was unused

Change-Id: I9501dc7cd6be461297052182de79dae831409a8c
Signed-off-by: Moiz Raja <moraja@cisco.com>
(cherry picked from commit 17787472279e0c04061a1ef1ad2b110b1f77b9b3)

opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java

index dd55441c2a22a014d725674379c071c990c051cf..d37a9db394cc3eff2ca1e01216f6df062c873f32 100644 (file)
@@ -41,6 +41,7 @@ import org.opendaylight.controller.cluster.datastore.exceptions.TimeoutException
 import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
 import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction;
 import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply;
+import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
 import org.opendaylight.controller.cluster.datastore.modification.DeleteModification;
 import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
@@ -57,6 +58,7 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCoh
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import scala.concurrent.Promise;
@@ -777,6 +779,10 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest {
         throttleOperation(operation, 1, true);
     }
 
+    private PrimaryShardInfo newPrimaryShardInfo(ActorRef actorRef){
+        return new PrimaryShardInfo(getSystem().actorSelection(actorRef.path()), Optional.<DataTree>absent());
+    }
+
     private void throttleOperation(TransactionProxyOperation operation, int outstandingOpsLimit, boolean shardFound){
         ActorSystem actorSystem = getSystem();
         ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
@@ -787,7 +793,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest {
                 when(mockActorContext).actorSelection(shardActorRef.path().toString());
 
         if(shardFound) {
-            doReturn(Futures.successful(actorSystem.actorSelection(shardActorRef.path()))).
+            doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).
                     when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
         } else {
             doReturn(Futures.failed(new Exception("not found")))
@@ -833,7 +839,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest {
                 when(mockActorContext).actorSelection(shardActorRef.path().toString());
 
         if(shardFound) {
-            doReturn(primaryShardInfoReply(actorSystem, shardActorRef)).
+            doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).
                     when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
         } else {
             doReturn(Futures.failed(new PrimaryNotFoundException("test")))
@@ -867,22 +873,6 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest {
                 expected, (end-start)), (end - start) <= expected);
     }
 
-    public void testWriteThrottling(boolean shardFound){
-
-        throttleOperation(new TransactionProxyOperation() {
-            @Override
-            public void run(TransactionProxy transactionProxy) {
-                NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
-
-                expectBatchedModifications(2);
-
-                transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
-
-                transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
-            }
-        }, 1, shardFound);
-    }
-
     @Test
     public void testWriteThrottlingWhenShardFound(){
         dataStoreContextBuilder.shardBatchedModificationCount(1);