Initial support for multiple-shards
[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.utils.MockClusterWrapper;
7 import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration;
8 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
9 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
10 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
11 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
12 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
13
14 import static junit.framework.Assert.assertEquals;
15 import static junit.framework.Assert.assertTrue;
16
17 public class DistributedDataStoreIntegrationTest extends AbstractActorTest {
18
19     @Test
20     public void integrationTest() throws Exception {
21         DistributedDataStore distributedDataStore =
22             new DistributedDataStore(getSystem(), "config", new MockClusterWrapper(), new MockConfiguration());
23
24         distributedDataStore.onGlobalContextUpdated(TestModel.createTestContext());
25
26         DOMStoreReadWriteTransaction transaction =
27             distributedDataStore.newReadWriteTransaction();
28
29         transaction.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
30
31         ListenableFuture<Optional<NormalizedNode<?, ?>>> future =
32             transaction.read(TestModel.TEST_PATH);
33
34         Optional<NormalizedNode<?, ?>> optional = future.get();
35
36         NormalizedNode<?, ?> normalizedNode = optional.get();
37
38         assertEquals(TestModel.TEST_QNAME, normalizedNode.getNodeType());
39
40         DOMStoreThreePhaseCommitCohort ready = transaction.ready();
41
42         ListenableFuture<Boolean> canCommit = ready.canCommit();
43
44         assertTrue(canCommit.get());
45
46         ListenableFuture<Void> preCommit = ready.preCommit();
47
48         preCommit.get();
49
50         ListenableFuture<Void> commit = ready.commit();
51
52         commit.get();
53
54     }
55
56 }