1 package org.opendaylight.controller.cluster.datastore;
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;
22 public class DistributedDataStoreTest extends AbstractActorTest{
24 private DistributedDataStore distributedDataStore;
25 private MockActorContext mockActorContext;
26 private ActorRef doNothingActorRef;
29 public void setUp() throws Exception {
30 final Props props = Props.create(DoNothingActor.class);
32 doNothingActorRef = getSystem().actorOf(props);
34 mockActorContext = new MockActorContext(getSystem(), doNothingActorRef);
35 distributedDataStore = new DistributedDataStore(mockActorContext, "config");
36 distributedDataStore.onGlobalContextUpdated(
37 TestModel.createTestContext());
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 "));
46 public void tearDown() throws Exception {
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<?, ?>>() {
56 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {
57 throw new UnsupportedOperationException("onDataChanged");
59 }, AsyncDataBroker.DataChangeScope.BASE);
61 Assert.assertNotNull(registration);
65 public void testCreateTransactionChain() throws Exception {
66 final DOMStoreTransactionChain transactionChain = distributedDataStore.createTransactionChain();
67 Assert.assertNotNull(transactionChain);
71 public void testNewReadOnlyTransaction() throws Exception {
72 final DOMStoreReadTransaction transaction = distributedDataStore.newReadOnlyTransaction();
73 Assert.assertNotNull(transaction);
77 public void testNewWriteOnlyTransaction() throws Exception {
78 final DOMStoreWriteTransaction transaction = distributedDataStore.newWriteOnlyTransaction();
79 Assert.assertNotNull(transaction);
83 public void testNewReadWriteTransaction() throws Exception {
84 final DOMStoreReadWriteTransaction transaction = distributedDataStore.newReadWriteTransaction();
85 Assert.assertNotNull(transaction);