X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDistributedDataStoreTest.java;h=d1beab904984262cd1f83de56a039c5970dc0742;hb=8e42b08cb626a60919c145b2a46d94114c3905d6;hp=1c9e337f75c3b6df8fc3f7f8f7d135af4d6cba40;hpb=9340a64d067473032111bd8c3341ea6855cd9e4a;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreTest.java index 1c9e337f75..d1beab9049 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreTest.java @@ -3,10 +3,11 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; import akka.actor.Props; import junit.framework.Assert; - import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListenerReply; +import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory; import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor; import org.opendaylight.controller.cluster.datastore.utils.MockActorContext; +import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; @@ -17,7 +18,7 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransactio import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain; import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; public class DistributedDataStoreTest extends AbstractActorTest{ @@ -28,6 +29,7 @@ public class DistributedDataStoreTest extends AbstractActorTest{ @org.junit.Before public void setUp() throws Exception { + ShardStrategyFactory.setConfiguration(new MockConfiguration()); final Props props = Props.create(DoNothingActor.class); doNothingActorRef = getSystem().actorOf(props); @@ -52,19 +54,41 @@ public class DistributedDataStoreTest extends AbstractActorTest{ } @org.junit.Test - public void testRegisterChangeListener() throws Exception { - mockActorContext.setExecuteShardOperationResponse(new RegisterChangeListenerReply(doNothingActorRef.path()).toSerializable()); + public void testRegisterChangeListenerWhenShardIsNotLocal() throws Exception { + ListenerRegistration registration = - distributedDataStore.registerChangeListener(TestModel.TEST_PATH, new AsyncDataChangeListener>() { + distributedDataStore.registerChangeListener(TestModel.TEST_PATH, new AsyncDataChangeListener>() { @Override - public void onDataChanged(AsyncDataChangeEvent> change) { + public void onDataChanged(AsyncDataChangeEvent> change) { throw new UnsupportedOperationException("onDataChanged"); } }, AsyncDataBroker.DataChangeScope.BASE); + // Since we do not expect the shard to be local registration will return a NoOpRegistration + Assert.assertTrue(registration instanceof NoOpDataChangeListenerRegistration); + Assert.assertNotNull(registration); } + @org.junit.Test + public void testRegisterChangeListenerWhenShardIsLocal() throws Exception { + + mockActorContext.setExecuteLocalShardOperationResponse(new RegisterChangeListenerReply(doNothingActorRef.path())); + + ListenerRegistration registration = + distributedDataStore.registerChangeListener(TestModel.TEST_PATH, new AsyncDataChangeListener>() { + @Override + public void onDataChanged(AsyncDataChangeEvent> change) { + throw new UnsupportedOperationException("onDataChanged"); + } + }, AsyncDataBroker.DataChangeScope.BASE); + + Assert.assertTrue(registration instanceof DataChangeListenerRegistrationProxy); + + Assert.assertNotNull(registration); + } + + @org.junit.Test public void testCreateTransactionChain() throws Exception { final DOMStoreTransactionChain transactionChain = distributedDataStore.createTransactionChain();