Merge changes I1d768b2b,I9302e88a
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / DistributedDataStoreTest.java
1 package org.opendaylight.controller.cluster.datastore;
2
3 import akka.actor.ActorRef;
4 import akka.actor.Props;
5 import junit.framework.Assert;
6
7 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListenerReply;
8 import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor;
9 import org.opendaylight.controller.cluster.datastore.utils.MockActorContext;
10 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
11 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
12 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
14 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages.CreateTransactionReply;
15 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22
23 public class DistributedDataStoreTest extends AbstractActorTest{
24
25     private DistributedDataStore distributedDataStore;
26     private MockActorContext mockActorContext;
27     private ActorRef doNothingActorRef;
28
29     @org.junit.Before
30     public void setUp() throws Exception {
31         final Props props = Props.create(DoNothingActor.class);
32
33         doNothingActorRef = getSystem().actorOf(props);
34
35         mockActorContext = new MockActorContext(getSystem(), doNothingActorRef);
36         distributedDataStore = new DistributedDataStore(mockActorContext, "config");
37         distributedDataStore.onGlobalContextUpdated(
38             TestModel.createTestContext());
39
40         // Make CreateTransactionReply as the default response. Will need to be
41         // tuned if a specific test requires some other response
42         mockActorContext.setExecuteShardOperationResponse(
43             CreateTransactionReply.newBuilder()
44                 .setTransactionActorPath(doNothingActorRef.path().toString())
45                 .setTransactionId("txn-1 ")
46                 .build());
47     }
48
49     @org.junit.After
50     public void tearDown() throws Exception {
51
52     }
53
54     @org.junit.Test
55     public void testRegisterChangeListener() throws Exception {
56         mockActorContext.setExecuteShardOperationResponse(new RegisterChangeListenerReply(doNothingActorRef.path()).toSerializable());
57         ListenerRegistration registration =
58                 distributedDataStore.registerChangeListener(TestModel.TEST_PATH, new AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>() {
59             @Override
60             public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {
61                 throw new UnsupportedOperationException("onDataChanged");
62             }
63         }, AsyncDataBroker.DataChangeScope.BASE);
64
65         Assert.assertNotNull(registration);
66     }
67
68     @org.junit.Test
69     public void testCreateTransactionChain() throws Exception {
70         final DOMStoreTransactionChain transactionChain = distributedDataStore.createTransactionChain();
71         Assert.assertNotNull(transactionChain);
72     }
73
74     @org.junit.Test
75     public void testNewReadOnlyTransaction() throws Exception {
76         final DOMStoreReadTransaction transaction = distributedDataStore.newReadOnlyTransaction();
77         Assert.assertNotNull(transaction);
78     }
79
80     @org.junit.Test
81     public void testNewWriteOnlyTransaction() throws Exception {
82         final DOMStoreWriteTransaction transaction = distributedDataStore.newWriteOnlyTransaction();
83         Assert.assertNotNull(transaction);
84     }
85
86     @org.junit.Test
87     public void testNewReadWriteTransaction() throws Exception {
88         final DOMStoreReadWriteTransaction transaction = distributedDataStore.newReadWriteTransaction();
89         Assert.assertNotNull(transaction);
90     }
91 }