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