BUG 3232 : Fix intermittent failure in ShardTest 82/20582/2
authorMoiz Raja <moraja@cisco.com>
Sat, 16 May 2015 00:44:11 +0000 (17:44 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 16 May 2015 12:22:43 +0000 (12:22 +0000)
Change-Id: Ia556fe4833614080d891dd1edcfa8878152bc595
Signed-off-by: Moiz Raja <moraja@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java

index 14a20da247f5138b17e3c30e437bf3c661e5ec25..c2cc1ac05b5dd0bb51a363b66d27d5398042f401 100644 (file)
@@ -84,6 +84,9 @@ public class Shard extends RaftActor {
 
     private static final Object TX_COMMIT_TIMEOUT_CHECK_MESSAGE = "txCommitTimeoutCheck";
 
+    @VisibleForTesting
+    static final Object GET_SHARD_MBEAN_MESSAGE = "getShardMBeanMessage";
+
     @VisibleForTesting
     static final String DEFAULT_NAME = "default";
 
@@ -256,9 +259,11 @@ public class Shard extends RaftActor {
                 onDatastoreContext((DatastoreContext)message);
             } else if(message instanceof RegisterRoleChangeListener){
                 roleChangeNotifier.get().forward(message, context());
-            } else if (message instanceof FollowerInitialSyncUpStatus){
+            } else if (message instanceof FollowerInitialSyncUpStatus) {
                 shardMBean.setFollowerInitialSyncStatus(((FollowerInitialSyncUpStatus) message).isInitialSyncDone());
                 context().parent().tell(message, self());
+            } else if(GET_SHARD_MBEAN_MESSAGE.equals(message)){
+                sender().tell(getShardMBean(), self());
             } else {
                 super.onReceiveCommand(message);
             }
index 40227e056bfff82351c8e19eafb237e93f4d7580..ee543164de51e41e711b424da8a29a271c1d5382 100644 (file)
@@ -41,6 +41,7 @@ import org.mockito.InOrder;
 import org.opendaylight.controller.cluster.DataPersistenceProvider;
 import org.opendaylight.controller.cluster.DelegatingPersistentDataProvider;
 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
+import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
 import org.opendaylight.controller.cluster.datastore.messages.AbortTransaction;
 import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply;
 import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
@@ -1264,12 +1265,15 @@ public class ShardTest extends AbstractShardTest {
                 inOrder.verify(cohort).preCommit();
                 inOrder.verify(cohort).commit();
 
+                shard.tell(Shard.GET_SHARD_MBEAN_MESSAGE, getRef());
+                ShardStats shardStats = expectMsgClass(duration, ShardStats.class);
+
                 // Use MBean for verification
                 // Committed transaction count should increase as usual
-                assertEquals(1,shard.underlyingActor().getShardMBean().getCommittedTransactionsCount());
+                assertEquals(1,shardStats.getCommittedTransactionsCount());
 
                 // Commit index should not advance because this does not go into the journal
-                assertEquals(-1, shard.underlyingActor().getShardMBean().getCommitIndex());
+                assertEquals(-1, shardStats.getCommitIndex());
 
                 shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
 
@@ -1320,12 +1324,15 @@ public class ShardTest extends AbstractShardTest {
                 inOrder.verify(cohort).preCommit();
                 inOrder.verify(cohort).commit();
 
+                shard.tell(Shard.GET_SHARD_MBEAN_MESSAGE, getRef());
+                ShardStats shardStats = expectMsgClass(duration, ShardStats.class);
+
                 // Use MBean for verification
                 // Committed transaction count should increase as usual
-                assertEquals(1, shard.underlyingActor().getShardMBean().getCommittedTransactionsCount());
+                assertEquals(1, shardStats.getCommittedTransactionsCount());
 
                 // Commit index should advance as we do not have an empty modification
-                assertEquals(0, shard.underlyingActor().getShardMBean().getCommitIndex());
+                assertEquals(0, shardStats.getCommitIndex());
 
                 shard.tell(PoisonPill.getInstance(), ActorRef.noSender());