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=ec8aee2b09d4dfaf4ed4b5b732a9168783beb73c;hb=739927d16b298c15accbff118e38293416a3dfa7;hp=fc527b6bffe13726d89d5923cee71a6c471af055;hpb=c74d5c2399e500fe3e690edc8cee497b1cb6f867;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 fc527b6bff..ec8aee2b09 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 @@ -3,9 +3,12 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSystem; import akka.event.Logging; import akka.testkit.JavaTestKit; + import com.google.common.base.Optional; import com.google.common.util.concurrent.ListenableFuture; + import junit.framework.Assert; + import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; @@ -18,6 +21,7 @@ import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelpe 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.controller.sal.core.spi.data.DOMStoreTransactionChain; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; @@ -69,10 +73,13 @@ public class DistributedDataStoreIntegrationTest { { new Within(duration("10 seconds")) { + @Override protected void run() { try { final DistributedDataStore distributedDataStore = - new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), configuration); + new DistributedDataStore(getSystem(), "config", + new MockClusterWrapper(), configuration, + new DatastoreContext()); distributedDataStore.onGlobalContextUpdated(TestModel.createTestContext()); @@ -80,6 +87,7 @@ public class DistributedDataStoreIntegrationTest { final boolean result = new JavaTestKit.EventFilter(Logging.Info.class ) { + @Override protected Boolean run() { return true; } @@ -137,6 +145,94 @@ public class DistributedDataStoreIntegrationTest { } + @Test + public void transactionChainIntegrationTest() throws Exception { + final Configuration configuration = new ConfigurationImpl("module-shards.conf", "modules.conf"); + ShardStrategyFactory.setConfiguration(configuration); + + + + new JavaTestKit(getSystem()) { + { + + new Within(duration("10 seconds")) { + @Override + protected void run() { + try { + final DistributedDataStore distributedDataStore = + new DistributedDataStore(getSystem(), "config", + new MockClusterWrapper(), configuration, + new DatastoreContext()); + + distributedDataStore.onGlobalContextUpdated(TestModel.createTestContext()); + + // Wait for a specific log message to show up + final boolean result = + new JavaTestKit.EventFilter(Logging.Info.class + ) { + @Override + protected Boolean run() { + return true; + } + }.from("akka://test/user/shardmanager-config/member-1-shard-test-1-config") + .message("Switching from state Candidate to Leader") + .occurrences(1).exec(); + + assertEquals(true, result); + + DOMStoreTransactionChain transactionChain = + distributedDataStore.createTransactionChain(); + + DOMStoreReadWriteTransaction transaction = + transactionChain.newReadWriteTransaction(); + + transaction + .write(TestModel.TEST_PATH, ImmutableNodes + .containerNode(TestModel.TEST_QNAME)); + + ListenableFuture>> + future = + transaction.read(TestModel.TEST_PATH); + + Optional> optional = + future.get(); + + Assert.assertTrue("Node not found", optional.isPresent()); + + NormalizedNode normalizedNode = + optional.get(); + + assertEquals(TestModel.TEST_QNAME, + normalizedNode.getNodeType()); + + 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); + + transactionChain.close(); + } catch (ExecutionException | TimeoutException | InterruptedException e){ + fail(e.getMessage()); + } + } + }; + } + }; + + } + //FIXME : Disabling test because it's flaky //@Test @@ -150,11 +246,12 @@ public class DistributedDataStoreIntegrationTest { { new Within(duration("10 seconds")) { + @Override protected void run() { try { final DistributedDataStore distributedDataStore = new DistributedDataStore(getSystem(), "config", - new MockClusterWrapper(), configuration); + new MockClusterWrapper(), configuration, null); distributedDataStore.onGlobalContextUpdated( SchemaContextHelper.full()); @@ -164,6 +261,7 @@ public class DistributedDataStoreIntegrationTest { new JavaTestKit.EventFilter( Logging.Info.class ) { + @Override protected Boolean run() { return true; }