X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDistributedDataStoreIntegrationTest.java;h=0a0c04b91586cbbda3d41dc24c4daca83ae78ae3;hb=c5511f1c95ce9ce754e78df840b56e8681bbae2d;hp=636c835fde85452192178ce1e6d9d1798ccf39f9;hpb=1e59825dbec7b354d76bd7efa6a61e4ad802c802;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 636c835fde..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 @@ -1,28 +1,63 @@ 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; +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; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; 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; -public class DistributedDataStoreIntegrationTest extends AbstractActorTest { +public class DistributedDataStoreIntegrationTest{ + + private static ActorSystem system; + + @Before + public void setUp() { + System.setProperty("shard.persistent", "false"); + system = ActorSystem.create("test"); + } + + @After + public void tearDown() { + JavaTestKit.shutdownActorSystem(system); + system = null; + } + + protected ActorSystem getSystem() { + return system; + } @Test public void integrationTest() throws Exception { + 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()); + Thread.sleep(1500); + DOMStoreReadWriteTransaction transaction = distributedDataStore.newReadWriteTransaction(); @@ -33,6 +68,8 @@ public class DistributedDataStoreIntegrationTest extends AbstractActorTest { Optional> optional = future.get(); + Assert.assertTrue(optional.isPresent()); + NormalizedNode normalizedNode = optional.get(); assertEquals(TestModel.TEST_QNAME, normalizedNode.getNodeType()); @@ -41,16 +78,53 @@ public class DistributedDataStoreIntegrationTest extends AbstractActorTest { 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, TimeoutException { + Configuration configuration = new ConfigurationImpl("module-shards.conf", "modules.conf"); + + ShardStrategyFactory.setConfiguration(configuration); + DistributedDataStore distributedDataStore = + new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), configuration); + + + 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(); + + transaction.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()); + transaction.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer()); + + DOMStoreThreePhaseCommitCohort ready = transaction.ready(); + + ListenableFuture canCommit = ready.canCommit(); + + assertTrue(canCommit.get(5, TimeUnit.SECONDS)); + + ListenableFuture preCommit = ready.preCommit(); + + preCommit.get(5, TimeUnit.SECONDS); + + ListenableFuture commit = ready.commit(); + commit.get(5, TimeUnit.SECONDS); } }