Bug-2277: fix the Leader test failing in jenkins 70/12970/3
authorKamal Rameshan <kramesha@cisco.com>
Thu, 20 Nov 2014 03:21:14 +0000 (19:21 -0800)
committerKamal Rameshan <kramesha@cisco.com>
Thu, 20 Nov 2014 22:02:12 +0000 (14:02 -0800)
Change-Id: I149d643b517df5010595962cbdf616c2b2fb9945
Signed-off-by: Kamal Rameshan <kramesha@cisco.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformation.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImpl.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/Leader.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java

index c0cfd7e..7df80af 100644 (file)
@@ -80,4 +80,11 @@ public class FollowerLogInformationImpl implements FollowerLogInformation{
         }
         stopwatch.start();
     }
+
+    @Override
+    public void markFollowerInActive() {
+        if (stopwatch.isRunning()) {
+            stopwatch.stop();
+        }
+    }
 }
index 0dd3900..97ecef3 100644 (file)
@@ -113,4 +113,9 @@ public class Leader extends AbstractLeader {
     void markFollowerActive(String followerId) {
         followerToLog.get(followerId).markFollowerActive();
     }
+
+    @VisibleForTesting
+    void markFollowerInActive(String followerId) {
+        followerToLog.get(followerId).markFollowerInActive();
+    }
 }
index 6b534de..0fc0b4c 100644 (file)
@@ -6,7 +6,6 @@ import akka.actor.Props;
 import akka.actor.Terminated;
 import akka.testkit.JavaTestKit;
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.Uninterruptibles;
 import com.google.protobuf.ByteString;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -994,10 +993,7 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest {
             final Terminated termMsg1 = probe.expectMsgClass(Terminated.class);
             assertEquals(termMsg1.getActor(), followerActor1);
 
-            //sleep enough for all the follower stopwatches to lapse
-            Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().
-                getElectionTimeOutInterval().toMillis(), TimeUnit.MILLISECONDS);
-
+            leader.markFollowerInActive("follower-1");
             leader.markFollowerActive("follower-2");
             behavior = leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
             Assert.assertTrue("Behavior not instance of Leader when majority of followers are active",
@@ -1010,10 +1006,7 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest {
             final Terminated termMsg2 = probe.expectMsgClass(Terminated.class);
             assertEquals(termMsg2.getActor(), followerActor2);
 
-            //sleep enough for the remaining the follower stopwatches to lapse
-            Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().
-                getElectionTimeOutInterval().toMillis(), TimeUnit.MILLISECONDS);
-
+            leader.markFollowerInActive("follower-2");
             behavior = leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
             Assert.assertTrue("Behavior not instance of IsolatedLeader when majority followers are inactive",
                 behavior instanceof IsolatedLeader);
index 2a79c8f..9fbdd45 100644 (file)
@@ -29,7 +29,7 @@ public class MessageCollectorActor extends UntypedActor {
     @Override public void onReceive(Object message) throws Exception {
         if(message instanceof String){
             if("get-all-messages".equals(message)){
-                getSender().tell(messages, getSelf());
+                getSender().tell(new ArrayList(messages), getSelf());
             }
         } else {
             messages.add(message);

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.