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.shardstrategy.ShardStrategyFactory;
9 import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor;
10 import org.opendaylight.controller.cluster.datastore.utils.MockActorContext;
11 import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration;
12 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
16 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages.CreateTransactionReply;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
25 public class DistributedDataStoreTest extends AbstractActorTest{
27 private DistributedDataStore distributedDataStore;
28 private MockActorContext mockActorContext;
29 private ActorRef doNothingActorRef;
32 public void setUp() throws Exception {
33 ShardStrategyFactory.setConfiguration(new MockConfiguration());
34 final Props props = Props.create(DoNothingActor.class);
36 doNothingActorRef = getSystem().actorOf(props);
38 mockActorContext = new MockActorContext(getSystem(), doNothingActorRef);
39 distributedDataStore = new DistributedDataStore(mockActorContext, "config");
40 distributedDataStore.onGlobalContextUpdated(
41 TestModel.createTestContext());
43 // Make CreateTransactionReply as the default response. Will need to be
44 // tuned if a specific test requires some other response
45 mockActorContext.setExecuteShardOperationResponse(
46 CreateTransactionReply.newBuilder()
47 .setTransactionActorPath(doNothingActorRef.path().toString())
48 .setTransactionId("txn-1 ")
53 public void tearDown() throws Exception {
58 public void testRegisterChangeListener() throws Exception {
59 mockActorContext.setExecuteShardOperationResponse(new RegisterChangeListenerReply(doNothingActorRef.path()).toSerializable());
60 ListenerRegistration registration =
61 distributedDataStore.registerChangeListener(TestModel.TEST_PATH, new AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>() {
63 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {
64 throw new UnsupportedOperationException("onDataChanged");
66 }, AsyncDataBroker.DataChangeScope.BASE);
68 Assert.assertNotNull(registration);
72 public void testCreateTransactionChain() throws Exception {
73 final DOMStoreTransactionChain transactionChain = distributedDataStore.createTransactionChain();
74 Assert.assertNotNull(transactionChain);
78 public void testNewReadOnlyTransaction() throws Exception {
79 final DOMStoreReadTransaction transaction = distributedDataStore.newReadOnlyTransaction();
80 Assert.assertNotNull(transaction);
84 public void testNewWriteOnlyTransaction() throws Exception {
85 final DOMStoreWriteTransaction transaction = distributedDataStore.newWriteOnlyTransaction();
86 Assert.assertNotNull(transaction);
90 public void testNewReadWriteTransaction() throws Exception {
91 final DOMStoreReadWriteTransaction transaction = distributedDataStore.newReadWriteTransaction();
92 Assert.assertNotNull(transaction);