Fix DistributedDataStoreIntegrationTest failure 95/28395/3
authorTom Pantelis <tpanteli@brocade.com>
Wed, 14 Oct 2015 05:42:08 +0000 (01:42 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 14 Oct 2015 17:10:20 +0000 (17:10 +0000)
Fixed a timing issue with a test just started causing failures pretty
regularly on jenkins builds for some reason.

Change-Id: I40273574376804034fd6f14f56384cb8cae26900
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java

index c4df54778763f0f1bbb39aa0702a7da367c62007..c64c295ceaefe19333f5c49e144a7899d5b5ca1e 100644 (file)
@@ -103,6 +103,10 @@ public class DefaultConfigParamsImpl implements ConfigParams {
         this.customRaftPolicyImplementationClass = customRaftPolicyImplementationClass;
     }
 
+    public String getCustomRaftPolicyImplementationClass() {
+        return customRaftPolicyImplementationClass;
+    }
+
     @Override
     public long getSnapshotBatchCount() {
         return snapshotBatchCount;
index 4d952a725f5492bfd8cb92eb5fc36f315fe11e58..7b91705bf3f5a8e8492e53ff6e90f9de3c1cd772 100644 (file)
@@ -69,7 +69,6 @@ public class DatastoreContext {
     private boolean writeOnlyTransactionOptimizationsEnabled = true;
     private long shardCommitQueueExpiryTimeoutInMillis = DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS;
     private boolean transactionDebugContextEnabled = false;
-    private String customRaftPolicyImplementation = "";
 
     public static Set<String> getGlobalDatastoreTypes() {
         return globalDatastoreTypes;
@@ -102,7 +101,6 @@ public class DatastoreContext {
         this.writeOnlyTransactionOptimizationsEnabled = other.writeOnlyTransactionOptimizationsEnabled;
         this.shardCommitQueueExpiryTimeoutInMillis = other.shardCommitQueueExpiryTimeoutInMillis;
         this.transactionDebugContextEnabled = other.transactionDebugContextEnabled;
-        this.customRaftPolicyImplementation = other.customRaftPolicyImplementation;
 
         setShardJournalRecoveryLogBatchSize(other.raftConfig.getJournalRecoveryLogBatchSize());
         setSnapshotBatchCount(other.raftConfig.getSnapshotBatchCount());
@@ -110,7 +108,7 @@ public class DatastoreContext {
         setIsolatedLeaderCheckInterval(other.raftConfig.getIsolatedCheckIntervalInMillis());
         setSnapshotDataThresholdPercentage(other.raftConfig.getSnapshotDataThresholdPercentage());
         setElectionTimeoutFactor(other.raftConfig.getElectionTimeoutFactor());
-        setCustomRaftPolicyImplementation(other.customRaftPolicyImplementation);
+        setCustomRaftPolicyImplementation(other.raftConfig.getCustomRaftPolicyImplementationClass());
         setShardSnapshotChunkSize(other.raftConfig.getSnapshotChunkSize());
         setPeerAddressResolver(other.raftConfig.getPeerAddressResolver());
     }
index 67c3f50a5814f399629369596dcc5e81d3a8d16b..fa066ee32e5973347c6ff1fc9d22b31add12bd44 100644 (file)
@@ -616,15 +616,17 @@ public class DistributedDataStoreIntegrationTest {
         }};
     }
 
-    private void testTransactionCommitFailureWithNoShardLeader(final boolean writeOnly) throws Throwable {
+    private void testTransactionCommitFailureWithNoShardLeader(final boolean writeOnly, final String testName) throws Throwable {
         new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            String testName = "testTransactionCommitFailureWithNoShardLeader";
             String shardName = "default";
 
-            // We don't want the shard to become the leader so prevent shard election from completing
-            // by setting the election timeout, which is based on the heartbeat interval, really high.
+            // We don't want the shard to become the leader so prevent shard elections.
+            datastoreContextBuilder.customRaftPolicyImplementation(
+                    "org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy");
 
-            datastoreContextBuilder.shardHeartbeatIntervalInMillis(30000);
+            // The ShardManager uses the election timeout for FindPrimary so reset it low so it will timeout quickly.
+            datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1).
+                    shardInitializationTimeout(200, TimeUnit.MILLISECONDS);
 
             DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName);
 
@@ -632,11 +634,6 @@ public class DistributedDataStoreIntegrationTest {
                     new FindLocalShard(shardName, true));
             assertTrue("Expected LocalShardFound. Actual: " + result, result instanceof LocalShardFound);
 
-            // The ShardManager uses the election timeout for FindPrimary so reset it low so it will timeout quickly.
-
-            datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1);
-            dataStore.onDatastoreContextUpdated(datastoreContextBuilder.build());
-
             // Create the write Tx.
 
             final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction() :
@@ -692,12 +689,12 @@ public class DistributedDataStoreIntegrationTest {
     @Test(expected=NoShardLeaderException.class)
     public void testWriteOnlyTransactionCommitFailureWithNoShardLeader() throws Throwable {
         datastoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
-        testTransactionCommitFailureWithNoShardLeader(true);
+        testTransactionCommitFailureWithNoShardLeader(true, "testWriteOnlyTransactionCommitFailureWithNoShardLeader");
     }
 
     @Test(expected=NoShardLeaderException.class)
     public void testReadWriteTransactionCommitFailureWithNoShardLeader() throws Throwable {
-        testTransactionCommitFailureWithNoShardLeader(false);
+        testTransactionCommitFailureWithNoShardLeader(false, "testReadWriteTransactionCommitFailureWithNoShardLeader");
     }
 
     @Test