1 package org.opendaylight.controller.cluster.datastore;
3 import akka.actor.ActorSystem;
4 import akka.testkit.JavaTestKit;
6 import com.google.common.base.Optional;
7 import com.google.common.util.concurrent.ListenableFuture;
9 import org.junit.After;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory;
13 import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper;
14 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
15 import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel;
16 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
17 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
23 import java.util.concurrent.ExecutionException;
24 import java.util.concurrent.TimeUnit;
25 import java.util.concurrent.TimeoutException;
27 import static junit.framework.Assert.assertEquals;
28 import static junit.framework.Assert.assertTrue;
30 public class DistributedDataStoreIntegrationTest{
32 private static ActorSystem system;
36 System.setProperty("shard.persistent", "false");
37 system = ActorSystem.create("test");
41 public void tearDown() {
42 JavaTestKit.shutdownActorSystem(system);
46 protected ActorSystem getSystem() {
51 public void integrationTest() throws Exception {
52 Configuration configuration = new ConfigurationImpl("module-shards.conf", "modules.conf");
53 ShardStrategyFactory.setConfiguration(configuration);
54 DistributedDataStore distributedDataStore =
55 new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), configuration);
57 distributedDataStore.onGlobalContextUpdated(TestModel.createTestContext());
59 // This sleep is fragile - test can fail intermittently if all Shards aren't updated with
60 // the SchemaContext in time. Is there any way we can make this deterministic?
63 DOMStoreReadWriteTransaction transaction =
64 distributedDataStore.newReadWriteTransaction();
66 transaction.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
68 ListenableFuture<Optional<NormalizedNode<?, ?>>> future =
69 transaction.read(TestModel.TEST_PATH);
71 Optional<NormalizedNode<?, ?>> optional = future.get();
73 NormalizedNode<?, ?> normalizedNode = optional.get();
75 assertEquals(TestModel.TEST_QNAME, normalizedNode.getNodeType());
77 DOMStoreThreePhaseCommitCohort ready = transaction.ready();
79 ListenableFuture<Boolean> canCommit = ready.canCommit();
81 assertTrue(canCommit.get(5, TimeUnit.SECONDS));
83 ListenableFuture<Void> preCommit = ready.preCommit();
85 preCommit.get(5, TimeUnit.SECONDS);
87 ListenableFuture<Void> commit = ready.commit();
89 commit.get(5, TimeUnit.SECONDS);
94 public void integrationTestWithMultiShardConfiguration()
95 throws ExecutionException, InterruptedException, TimeoutException {
96 Configuration configuration = new ConfigurationImpl("module-shards.conf", "modules.conf");
98 ShardStrategyFactory.setConfiguration(configuration);
99 DistributedDataStore distributedDataStore =
100 new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), configuration);
103 distributedDataStore.onGlobalContextUpdated(SchemaContextHelper.full());
105 // This sleep is fragile - test can fail intermittently if all Shards aren't updated with
106 // the SchemaContext in time. Is there any way we can make this deterministic?
109 DOMStoreReadWriteTransaction transaction =
110 distributedDataStore.newReadWriteTransaction();
112 transaction.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
113 transaction.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
115 DOMStoreThreePhaseCommitCohort ready = transaction.ready();
117 ListenableFuture<Boolean> canCommit = ready.canCommit();
119 assertTrue(canCommit.get(5, TimeUnit.SECONDS));
121 ListenableFuture<Void> preCommit = ready.preCommit();
123 preCommit.get(5, TimeUnit.SECONDS);
125 ListenableFuture<Void> commit = ready.commit();
127 commit.get(5, TimeUnit.SECONDS);