X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDistributedDataStoreIntegrationTest.java;h=5f4ac57da04d2163f30ac519b7aa6c6e72da3752;hb=b584e686fdeba863643f80c0894d7fbd2dcaa540;hp=116e5e75b50d261e3d9673378ee643cfe2f2e31f;hpb=98f72d6e38e62500bbad181acf522511d384565c;p=controller.git 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 116e5e75b5..5f4ac57da0 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,14 +2,15 @@ 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 org.junit.After; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory; import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper; -import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; @@ -20,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; @@ -46,12 +49,17 @@ public class DistributedDataStoreIntegrationTest{ @Test public void integrationTest() throws Exception { - ShardStrategyFactory.setConfiguration(new MockConfiguration()); + Configuration configuration = new ConfigurationImpl("module-shards.conf", "modules.conf"); + ShardStrategyFactory.setConfiguration(configuration); DistributedDataStore distributedDataStore = - new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), new MockConfiguration()); + new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), configuration); distributedDataStore.onGlobalContextUpdated(TestModel.createTestContext()); + // 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(); @@ -70,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); @@ -95,6 +102,10 @@ public class DistributedDataStoreIntegrationTest{ distributedDataStore.onGlobalContextUpdated(SchemaContextHelper.full()); + // 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(); @@ -105,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); } }