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