1 package org.opendaylight.controller.cluster.datastore;
3 import akka.actor.ActorRef;
4 import akka.actor.Props;
5 import junit.framework.Assert;
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;
23 public class DistributedDataStoreTest extends AbstractActorTest{
25 private DistributedDataStore distributedDataStore;
26 private MockActorContext mockActorContext;
27 private ActorRef doNothingActorRef;
30 public void setUp() throws Exception {
31 final Props props = Props.create(DoNothingActor.class);
33 doNothingActorRef = getSystem().actorOf(props);
35 mockActorContext = new MockActorContext(getSystem(), doNothingActorRef);
36 distributedDataStore = new DistributedDataStore(mockActorContext, "config");
37 distributedDataStore.onGlobalContextUpdated(
38 TestModel.createTestContext());
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 ")
50 public void tearDown() throws Exception {
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<?, ?>>() {
60 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {
61 throw new UnsupportedOperationException("onDataChanged");
63 }, AsyncDataBroker.DataChangeScope.BASE);
65 Assert.assertNotNull(registration);
69 public void testCreateTransactionChain() throws Exception {
70 final DOMStoreTransactionChain transactionChain = distributedDataStore.createTransactionChain();
71 Assert.assertNotNull(transactionChain);
75 public void testNewReadOnlyTransaction() throws Exception {
76 final DOMStoreReadTransaction transaction = distributedDataStore.newReadOnlyTransaction();
77 Assert.assertNotNull(transaction);
81 public void testNewWriteOnlyTransaction() throws Exception {
82 final DOMStoreWriteTransaction transaction = distributedDataStore.newWriteOnlyTransaction();
83 Assert.assertNotNull(transaction);
87 public void testNewReadWriteTransaction() throws Exception {
88 final DOMStoreReadWriteTransaction transaction = distributedDataStore.newReadWriteTransaction();
89 Assert.assertNotNull(transaction);