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.cluster.datastore.utils.MockConfiguration;
13 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
14 import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel;
15 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
16 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
22 import java.util.concurrent.ExecutionException;
24 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertTrue;
27 public class DistributedDataStoreIntegrationTest{
29 private static ActorSystem system;
33 System.setProperty("shard.persistent", "false");
34 system = ActorSystem.create("test");
38 public void tearDown() {
39 JavaTestKit.shutdownActorSystem(system);
43 protected ActorSystem getSystem() {
48 public void integrationTest() throws Exception {
49 ShardStrategyFactory.setConfiguration(new MockConfiguration());
50 DistributedDataStore distributedDataStore =
51 new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), new MockConfiguration());
53 distributedDataStore.onGlobalContextUpdated(TestModel.createTestContext());
55 DOMStoreReadWriteTransaction transaction =
56 distributedDataStore.newReadWriteTransaction();
58 transaction.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
60 ListenableFuture<Optional<NormalizedNode<?, ?>>> future =
61 transaction.read(TestModel.TEST_PATH);
63 Optional<NormalizedNode<?, ?>> optional = future.get();
65 NormalizedNode<?, ?> normalizedNode = optional.get();
67 assertEquals(TestModel.TEST_QNAME, normalizedNode.getNodeType());
69 DOMStoreThreePhaseCommitCohort ready = transaction.ready();
71 ListenableFuture<Boolean> canCommit = ready.canCommit();
73 assertTrue(canCommit.get());
75 ListenableFuture<Void> preCommit = ready.preCommit();
79 ListenableFuture<Void> commit = ready.commit();
87 public void integrationTestWithMultiShardConfiguration()
88 throws ExecutionException, InterruptedException {
89 Configuration configuration = new ConfigurationImpl("module-shards.conf", "modules.conf");
91 ShardStrategyFactory.setConfiguration(configuration);
92 DistributedDataStore distributedDataStore =
93 new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), configuration);
96 distributedDataStore.onGlobalContextUpdated(SchemaContextHelper.full());
98 DOMStoreReadWriteTransaction transaction =
99 distributedDataStore.newReadWriteTransaction();
101 transaction.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
102 transaction.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
104 DOMStoreThreePhaseCommitCohort ready = transaction.ready();
106 ListenableFuture<Boolean> canCommit = ready.canCommit();
108 assertTrue(canCommit.get());
110 ListenableFuture<Void> preCommit = ready.preCommit();
114 ListenableFuture<Void> commit = ready.commit();