X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDistributedDataStoreIntegrationTest.java;h=0a0c04b91586cbbda3d41dc24c4daca83ae78ae3;hp=b5e3d24ef6d536d6afe2c9a6abc111bbb4b8688b;hb=c5511f1c95ce9ce754e78df840b56e8681bbae2d;hpb=5ffd4b46ca00fc8f3d801050670c890117dc0811 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java index b5e3d24ef6..0a0c04b915 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java @@ -2,8 +2,10 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSystem; import akka.testkit.JavaTestKit; + import com.google.common.base.Optional; import com.google.common.util.concurrent.ListenableFuture; +import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -19,6 +21,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; @@ -52,7 +56,7 @@ public class DistributedDataStoreIntegrationTest{ distributedDataStore.onGlobalContextUpdated(TestModel.createTestContext()); - Thread.sleep(1000); + Thread.sleep(1500); DOMStoreReadWriteTransaction transaction = distributedDataStore.newReadWriteTransaction(); @@ -64,6 +68,8 @@ public class DistributedDataStoreIntegrationTest{ Optional> optional = future.get(); + Assert.assertTrue(optional.isPresent()); + NormalizedNode normalizedNode = optional.get(); assertEquals(TestModel.TEST_QNAME, normalizedNode.getNodeType()); @@ -72,22 +78,21 @@ public class DistributedDataStoreIntegrationTest{ ListenableFuture canCommit = ready.canCommit(); - assertTrue(canCommit.get()); + assertTrue(canCommit.get(5, TimeUnit.SECONDS)); ListenableFuture preCommit = ready.preCommit(); - preCommit.get(); + preCommit.get(5, TimeUnit.SECONDS); ListenableFuture commit = ready.commit(); - commit.get(); - + commit.get(5, TimeUnit.SECONDS); } @Test public void integrationTestWithMultiShardConfiguration() - throws ExecutionException, InterruptedException { + throws ExecutionException, InterruptedException, TimeoutException { Configuration configuration = new ConfigurationImpl("module-shards.conf", "modules.conf"); ShardStrategyFactory.setConfiguration(configuration); @@ -97,7 +102,9 @@ public class DistributedDataStoreIntegrationTest{ distributedDataStore.onGlobalContextUpdated(SchemaContextHelper.full()); - Thread.sleep(1000); + // This sleep is fragile - test can fail intermittently if all Shards aren't updated with + // the SchemaContext in time. Is there any way we can make this deterministic? + Thread.sleep(2000); DOMStoreReadWriteTransaction transaction = distributedDataStore.newReadWriteTransaction(); @@ -109,16 +116,15 @@ public class DistributedDataStoreIntegrationTest{ ListenableFuture canCommit = ready.canCommit(); - assertTrue(canCommit.get()); + assertTrue(canCommit.get(5, TimeUnit.SECONDS)); ListenableFuture preCommit = ready.preCommit(); - preCommit.get(); + preCommit.get(5, TimeUnit.SECONDS); ListenableFuture commit = ready.commit(); - commit.get(); - + commit.get(5, TimeUnit.SECONDS); } }