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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.