Fix DistributedEntityOwnershipIntegrationTest failure 24/28024/1
authorTom Pantelis <tpanteli@brocade.com>
Tue, 6 Oct 2015 13:43:55 +0000 (09:43 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Wed, 7 Oct 2015 17:52:47 +0000 (17:52 +0000)
Fixed intermittent failure due the follower2MockListener getting
an ownershipChanged with "false, false, true" if if the original
ownership change with "member-2 is replicated to follower2 after
the listener is registered. The test ran 100 times successfully.

Change-Id: I1f0333e3bc69cc28521bc7388d64b56d18b55544
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
(cherry picked from commit de587f935016a300cdbeb85926c2eb677f383fc2)

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

index 0ea7b75..1bb5798 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.cluster.datastore.entityownership;
 
 import static org.junit.Assert.assertEquals;
 import static org.mockito.AdditionalMatchers.or;
+import static org.mockito.Mockito.atMost;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
@@ -198,11 +199,17 @@ public class DistributedEntityOwnershipIntegrationTest {
         // Unregister follower1 candidate for entity2 and verify follower2 becomes owner
 
         follower1EntityOwnershipService.unregisterCandidate(ENTITY2);
+        verifyCandidates(leaderDistributedDataStore, ENTITY2, "member-3");
         verifyOwner(leaderDistributedDataStore, ENTITY2, "member-3");
-        verify(follower2MockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY2, false, true, true));
         verify(follower1MockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY2, true, false, true));
         verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY2, false, false, true));
-        verifyCandidates(leaderDistributedDataStore, ENTITY2, "member-3");
+
+        // Depending on timing, follower2MockListener could get ownershipChanged with "false, false, true" if
+        // if the original ownership change with "member-2 is replicated to follower2 after the listener is
+        // registered.
+        Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
+        verify(follower2MockListener, atMost(1)).ownershipChanged(ownershipChange(ENTITY2, false, false, true));
+        verify(follower2MockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY2, false, true, true));
 
         // Register follower1 candidate for entity3 and verify it becomes owner