Fix intermittent RaftActorLeadershipTransferCohortTest failure 58/36158/2
authorTom Pantelis <tpanteli@brocade.com>
Fri, 11 Mar 2016 23:44:55 +0000 (18:44 -0500)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 12 Mar 2016 20:09:04 +0000 (20:09 +0000)
Change-Id: I4c58f6545d7ef7667c7fcf42f5dda82345ab1167
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorLeadershipTransferCohortTest.java

index c7d9e3d..45c797c 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.base.Function;
 import org.junit.After;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.raft.RaftActorLeadershipTransferCohort.OnComplete;
+import org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy;
 
 /**
  * Unit tests for RaftActorLeadershipTransferCohort.
@@ -35,8 +36,8 @@ public class RaftActorLeadershipTransferCohortTest extends AbstractActorTest {
         factory.close();
     }
 
-    private void setup() {
-        String persistenceId = factory.generateActorId("leader-");
+    private void setup(String testName) {
+        String persistenceId = factory.generateActorId(testName + "-leader-");
         mockRaftActor = factory.<MockRaftActor>createTestActor(MockRaftActor.builder().id(persistenceId).config(
                 config).pauseLeaderFunction(pauseLeaderFunction).props().withDispatcher(Dispatchers.DefaultDispatcherId()),
                 persistenceId).underlyingActor();
@@ -47,7 +48,7 @@ public class RaftActorLeadershipTransferCohortTest extends AbstractActorTest {
 
     @Test
     public void testOnNewLeader() {
-        setup();
+        setup("testOnNewLeader");
         cohort.setNewLeaderTimeoutInMillis(20000);
 
         cohort.onNewLeader("new-leader");
@@ -64,23 +65,23 @@ public class RaftActorLeadershipTransferCohortTest extends AbstractActorTest {
 
     @Test
     public void testNewLeaderTimeout() {
-        setup();
+        setup("testNewLeaderTimeout");
         cohort.setNewLeaderTimeoutInMillis(200);
         cohort.transferComplete();
         verify(onComplete, timeout(3000)).onSuccess(mockRaftActor.self(), null);
     }
 
     @Test
-    public void testNotLeaderOnRun() {
-        config.setElectionTimeoutFactor(10000);
-        setup();
+    public void testNotLeaderOnDoTransfer() {
+        config.setCustomRaftPolicyImplementationClass(DisableElectionsRaftPolicy.class.getName());
+        setup("testNotLeaderOnDoTransfer");
         cohort.doTransfer();
         verify(onComplete).onSuccess(mockRaftActor.self(), null);
     }
 
     @Test
     public void testAbortTransfer() {
-        setup();
+        setup("testAbortTransfer");
         cohort.abortTransfer();
         verify(onComplete).onFailure(mockRaftActor.self(), null);
     }
@@ -94,7 +95,7 @@ public class RaftActorLeadershipTransferCohortTest extends AbstractActorTest {
             }
         };
 
-        setup();
+        setup("testPauseLeaderTimeout");
         cohort.init();
         verify(onComplete, timeout(2000)).onFailure(mockRaftActor.self(), null);
     }