Implementation of ModuleShardStrategy
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / DistributedDataStoreIntegrationTest.java
1 package org.opendaylight.controller.cluster.datastore;
2
3 import com.google.common.base.Optional;
4 import com.google.common.util.concurrent.ListenableFuture;
5 import org.junit.Test;
6 import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory;
7 import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper;
8 import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration;
9 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
10 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
11 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
12 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
13 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
14
15 import static junit.framework.Assert.assertEquals;
16 import static junit.framework.Assert.assertTrue;
17
18 public class DistributedDataStoreIntegrationTest extends AbstractActorTest {
19
20     @Test
21     public void integrationTest() throws Exception {
22         ShardStrategyFactory.setConfiguration(new MockConfiguration());
23         DistributedDataStore distributedDataStore =
24             new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), new MockConfiguration());
25
26         distributedDataStore.onGlobalContextUpdated(TestModel.createTestContext());
27
28         DOMStoreReadWriteTransaction transaction =
29             distributedDataStore.newReadWriteTransaction();
30
31         transaction.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
32
33         ListenableFuture<Optional<NormalizedNode<?, ?>>> future =
34             transaction.read(TestModel.TEST_PATH);
35
36         Optional<NormalizedNode<?, ?>> optional = future.get();
37
38         NormalizedNode<?, ?> normalizedNode = optional.get();
39
40         assertEquals(TestModel.TEST_QNAME, normalizedNode.getNodeType());
41
42         DOMStoreThreePhaseCommitCohort ready = transaction.ready();
43
44         ListenableFuture<Boolean> canCommit = ready.canCommit();
45
46         assertTrue(canCommit.get());
47
48         ListenableFuture<Void> preCommit = ready.preCommit();
49
50         preCommit.get();
51
52         ListenableFuture<Void> commit = ready.commit();
53
54         commit.get();
55
56     }
57
58 }