1 package org.opendaylight.controller.cluster.datastore;
3 import akka.actor.ActorSystem;
4 import akka.testkit.JavaTestKit;
5 import com.google.common.base.Optional;
6 import com.google.common.util.concurrent.ListenableFuture;
7 import org.junit.After;
8 import org.junit.Before;
10 import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory;
11 import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper;
12 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
13 import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel;
14 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
15 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
21 import java.util.concurrent.ExecutionException;
23 import static junit.framework.Assert.assertEquals;
24 import static junit.framework.Assert.assertTrue;
26 public class DistributedDataStoreIntegrationTest{
28 private static ActorSystem system;
32 System.setProperty("shard.persistent", "false");
33 system = ActorSystem.create("test");
37 public void tearDown() {
38 JavaTestKit.shutdownActorSystem(system);
42 protected ActorSystem getSystem() {
47 public void integrationTest() throws Exception {
48 Configuration configuration = new ConfigurationImpl("module-shards.conf", "modules.conf");
49 ShardStrategyFactory.setConfiguration(configuration);
50 DistributedDataStore distributedDataStore =
51 new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), configuration);
53 distributedDataStore.onGlobalContextUpdated(TestModel.createTestContext());
57 DOMStoreReadWriteTransaction transaction =
58 distributedDataStore.newReadWriteTransaction();
60 transaction.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
62 ListenableFuture<Optional<NormalizedNode<?, ?>>> future =
63 transaction.read(TestModel.TEST_PATH);
65 Optional<NormalizedNode<?, ?>> optional = future.get();
67 NormalizedNode<?, ?> normalizedNode = optional.get();
69 assertEquals(TestModel.TEST_QNAME, normalizedNode.getNodeType());
71 DOMStoreThreePhaseCommitCohort ready = transaction.ready();
73 ListenableFuture<Boolean> canCommit = ready.canCommit();
75 assertTrue(canCommit.get());
77 ListenableFuture<Void> preCommit = ready.preCommit();
81 ListenableFuture<Void> commit = ready.commit();
89 public void integrationTestWithMultiShardConfiguration()
90 throws ExecutionException, InterruptedException {
91 Configuration configuration = new ConfigurationImpl("module-shards.conf", "modules.conf");
93 ShardStrategyFactory.setConfiguration(configuration);
94 DistributedDataStore distributedDataStore =
95 new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), configuration);
98 distributedDataStore.onGlobalContextUpdated(SchemaContextHelper.full());
102 DOMStoreReadWriteTransaction transaction =
103 distributedDataStore.newReadWriteTransaction();
105 transaction.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
106 transaction.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
108 DOMStoreThreePhaseCommitCohort ready = transaction.ready();
110 ListenableFuture<Boolean> canCommit = ready.canCommit();
112 assertTrue(canCommit.get());
114 ListenableFuture<Void> preCommit = ready.preCommit();
118 ListenableFuture<Void> commit = ready.commit();