Keep DataChange registrations and notifications local
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / DistributedDataStoreTest.java
index 23a1ed49315ec827baa95c41b51dfe4d23159d4e..03191f70f1ab5979d8bcc6189b2ddece6616c867 100644 (file)
@@ -54,8 +54,8 @@ 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<YangInstanceIdentifier, NormalizedNode<?, ?>>() {
             @Override
@@ -64,9 +64,31 @@ public class DistributedDataStoreTest extends AbstractActorTest{
             }
         }, 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()).toSerializable());
+
+        ListenerRegistration registration =
+            distributedDataStore.registerChangeListener(TestModel.TEST_PATH, new AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>() {
+                @Override
+                public void onDataChanged(AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> 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();