Migrate from YangInstanceIdentifier.EMPTY
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / MockDataTreeChangeListener.java
index e1a881f7eef5d1f1154d039ab0dd88f126115a46..fecfc52fb6a57a036b009ef89502c8ed26c199a9 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.cluster.datastore.utils;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import com.google.common.util.concurrent.Uninterruptibles;
@@ -21,8 +22,8 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -33,6 +34,9 @@ public class MockDataTreeChangeListener implements DOMDataTreeChangeListener {
 
     private final List<DataTreeCandidate> changeList = new ArrayList<>();
 
+    private final CountDownLatch onInitialDataLatch = new CountDownLatch(1);
+    private final AtomicInteger onInitialDataEventCount = new AtomicInteger();
+
     private volatile CountDownLatch changeLatch;
     private int expChangeEventCount;
 
@@ -49,7 +53,7 @@ public class MockDataTreeChangeListener implements DOMDataTreeChangeListener {
     }
 
     @Override
-    public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> changes) {
+    public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
         if (changeLatch.getCount() > 0) {
             synchronized (changeList) {
                 changeList.addAll(changes);
@@ -58,6 +62,23 @@ public class MockDataTreeChangeListener implements DOMDataTreeChangeListener {
         }
     }
 
+    @Override
+    public void onInitialData() {
+        onInitialDataEventCount.incrementAndGet();
+        onInitialDataLatch.countDown();
+    }
+
+    public void verifyOnInitialDataEvent() {
+        assertTrue("onInitialData was not triggered",
+                Uninterruptibles.awaitUninterruptibly(onInitialDataLatch, 5, TimeUnit.SECONDS));
+        assertEquals("onInitialDataEventCount", 1, onInitialDataEventCount.get());
+    }
+
+    public void verifyNoOnInitialDataEvent() {
+        assertFalse("onInitialData was triggered unexpectedly",
+                Uninterruptibles.awaitUninterruptibly(onInitialDataLatch, 500, TimeUnit.MILLISECONDS));
+    }
+
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public void waitForChangeEvents(final YangInstanceIdentifier... expPaths) {
         boolean done = Uninterruptibles.awaitUninterruptibly(changeLatch, 5, TimeUnit.SECONDS);