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;
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;
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;
}
@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);
}
}
+ @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);