private void deleteAndListenAugment(final InstanceIdentifier<?> path) {
final var augment = writeInitialState();
try (var collector = createCollector(LogicalDatastoreType.OPERATIONAL, WILDCARDED_AUGMENT_PATH)) {
+ collector.verifyModifications(added(FOO_AUGMENT_PATH, augment));
+
final var tx = getDataBroker().newWriteOnlyTransaction();
tx.delete(LogicalDatastoreType.OPERATIONAL, path);
assertCommit(tx.commit());
- collector.assertModifications(
- added(FOO_AUGMENT_PATH, augment),
- deleted(FOO_AUGMENT_PATH, augment));
+ collector.verifyModifications(deleted(FOO_AUGMENT_PATH, augment));
}
}
@Test
public void writeTopWithListItemAugmentedListenTopSubtree() {
try (var collector = createCollector(LogicalDatastoreType.CONFIGURATION, TOP_PATH)) {
+ collector.verifyModifications();
+
writeTopWithListItem(LogicalDatastoreType.CONFIGURATION);
- collector.assertModifications(added(TOP_PATH, topWithListItem()));
+ collector.verifyModifications(added(TOP_PATH, topWithListItem()));
}
}
@Test
public void writeTopWithListItemAugmentedListenAugmentSubtreeWildcarded() {
try (var collector = createCollector(LogicalDatastoreType.CONFIGURATION, AUGMENT_WILDCARD)) {
+ collector.verifyModifications();
+
writeTopWithListItem(LogicalDatastoreType.CONFIGURATION);
- collector.assertModifications(
+ collector.verifyModifications(
added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)));
}
}
final var top = writeTopWithListItem(LogicalDatastoreType.CONFIGURATION);
try (var collector = createCollector(LogicalDatastoreType.CONFIGURATION, TOP_PATH)) {
+ collector.verifyModifications(added(TOP_PATH, top));
+
deleteItem(LogicalDatastoreType.CONFIGURATION, path(TOP_FOO_KEY, USES_ONE_KEY));
- collector.assertModifications(
- added(TOP_PATH, top),
+ collector.verifyModifications(
subtreeModified(TOP_PATH, top, top(topLevelList(TOP_FOO_KEY, complexUsesAugment(USES_TWO_KEY)))));
}
}
writeTopWithListItem(LogicalDatastoreType.CONFIGURATION);
try (var collector = createCollector(LogicalDatastoreType.CONFIGURATION, AUGMENT_WILDCARD)) {
+ collector.verifyModifications(
+ added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)));
+
deleteItem(LogicalDatastoreType.CONFIGURATION, path(TOP_FOO_KEY, USES_ONE_KEY));
- collector.assertModifications(
- added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)),
+ collector.verifyModifications(
subtreeModified(path(TOP_FOO_KEY, TreeComplexUsesAugment.class),
complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY), complexUsesAugment(USES_TWO_KEY)));
}
public void leafOnlyAugmentationCreatedTest() {
final var leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf");
try (var collector = createCollector(CONFIGURATION, SIMPLE_AUGMENT)) {
+ collector.verifyModifications();
+
final var writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(CONFIGURATION, TOP, top());
writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment);
assertCommit(writeTx.commit());
- collector.assertModifications(added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
+ collector.verifyModifications(
+ added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
}
}
final var leafOnlyUsesAugmentAfter = leafOnlyUsesAugment("test leaf changed");
try (var collector = createCollector(CONFIGURATION, SIMPLE_AUGMENT)) {
+ collector.verifyModifications(
+ added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore));
+
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentAfter);
assertCommit(writeTx.commit());
- collector.assertModifications(
- added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore),
+ collector.verifyModifications(
replaced(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore,
leafOnlyUsesAugmentAfter));
}
assertCommit(writeTx.commit());
try (var collector = createCollector(CONFIGURATION, SIMPLE_AUGMENT)) {
+ collector.verifyModifications(
+ added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
+
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.delete(CONFIGURATION, SIMPLE_AUGMENT);
assertCommit(writeTx.commit());
- collector.assertModifications(
- added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment),
+ collector.verifyModifications(
deleted(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
}
}
writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment);
assertCommit(writeTx.commit());
- collector.assertModifications(added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment));
+ collector.verifyModifications(
+ added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment));
}
}
assertCommit(writeTx.commit());
try (var collector = createCollector(CONFIGURATION, COMPLEX_AUGMENT)) {
+ collector.verifyModifications(
+ added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore));
+
final var complexUsesAugmentAfter = complexUsesAugment(LIST_VIA_USES_KEY_MOD);
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentAfter);
assertCommit(writeTx.commit());
- collector.assertModifications(
- added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore),
+ collector.verifyModifications(
// While we are overwriting the augment, at the transaction ends up replacing one child with another,
// so the Augmentation ends up not being overwritten, but modified
subtreeModified(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore,
final var root = new RootBuilder().setFooroot(List.of(fooRoot)).build();
try (var collector = createCollector(LogicalDatastoreType.CONFIGURATION, ROOT_PATH)) {
+ collector.verifyModifications();
+
final var readWriteTransaction = getDataBroker().newReadWriteTransaction();
readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, root);
assertCommit(readWriteTransaction.commit());
- collector.assertModifications(added(ROOT_PATH, root));
+ collector.verifyModifications(added(ROOT_PATH, root));
}
}
}
final var root = new RootBuilder().setListInRoot(BindingMap.of(listInRoots)).build();
try (var collector = createCollector(LogicalDatastoreType.CONFIGURATION, ROOT_PATH)) {
+ collector.verifyModifications();
+
final var readWriteTransaction = getDataBroker().newReadWriteTransaction();
readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, root);
assertCommit(readWriteTransaction.commit());
- collector.assertModifications(match(ModificationType.WRITE, ROOT_PATH, Objects::isNull,
+ collector.verifyModifications(match(ModificationType.WRITE, ROOT_PATH, Objects::isNull,
(DataMatcher<Root>) dataAfter -> checkData(root, dataAfter)));
}
}
writeTx.put(CONFIGURATION, TOP, top);
assertCommit(writeTx.commit());
- barListener.assertModifications(added(TOP_BAR, topBar));
+ barListener.verifyModifications(added(TOP_BAR, topBar));
}
- fooListener.assertModifications(added(TOP_FOO, topFoo), deleted(TOP_FOO, topFoo));
+ fooListener.verifyModifications(added(TOP_FOO, topFoo), deleted(TOP_FOO, topFoo));
}
- allListener.assertModifications(
+ allListener.verifyModifications(
added(TOP_FOO, topFoo),
added(TOP_BAR, topBar),
deleted(TOP_FOO, topFoo));
}
- topListener.assertModifications(
+ topListener.verifyModifications(
added(TOP, top(topLevelList(TOP_FOO_KEY))),
replaced(TOP, top(topFoo), top));
}
writeTx.merge(CONFIGURATION, TOP, top(topLevelList(TOP_BAR_KEY)));
assertCommit(writeTx.commit());
- barListener.assertModifications(added(TOP_BAR, topBar));
+ barListener.verifyModifications(added(TOP_BAR, topBar));
}
- fooListener.assertModifications(added(TOP_FOO, topFoo));
+ fooListener.verifyModifications(added(TOP_FOO, topFoo));
}
- allListener.assertModifications(added(TOP_FOO, topFoo), added(TOP_BAR, topBar));
+ allListener.verifyModifications(added(TOP_FOO, topFoo), added(TOP_BAR, topBar));
}
- topListener.assertModifications(
+ topListener.verifyModifications(
added(TOP, top(topLevelList(TOP_FOO_KEY))), topSubtreeModified(topFoo, topBar));
}
}
writeTx.put(CONFIGURATION, TOP_BAR, topLevelList(TOP_BAR_KEY));
assertCommit(writeTx.commit());
- barListener.assertModifications(added(TOP_BAR, topBar));
+ barListener.verifyModifications(added(TOP_BAR, topBar));
}
- fooListener.assertModifications(added(TOP_FOO, topFoo));
+ fooListener.verifyModifications(added(TOP_FOO, topFoo));
}
- allListener.assertModifications(added(TOP_FOO, topFoo), added(TOP_BAR, topBar));
+ allListener.verifyModifications(added(TOP_FOO, topFoo), added(TOP_BAR, topBar));
}
- topListener.assertModifications(
+ topListener.verifyModifications(
added(TOP, top(topLevelList(TOP_FOO_KEY))), topSubtreeModified(topFoo, topBar));
}
}
writeTx.merge(CONFIGURATION, TOP_BAR, topLevelList(TOP_BAR_KEY));
assertCommit(writeTx.commit());
- barListener.assertModifications(added(TOP_BAR, topBar));
+ barListener.verifyModifications(added(TOP_BAR, topBar));
}
- fooListener.assertModifications(added(TOP_FOO, topFoo));
+ fooListener.verifyModifications(added(TOP_FOO, topFoo));
}
- allListener.assertModifications(added(TOP_FOO, topFoo), added(TOP_BAR, topBar));
+ allListener.verifyModifications(added(TOP_FOO, topFoo), added(TOP_BAR, topBar));
}
- topListener.assertModifications(
+ topListener.verifyModifications(
added(TOP, top(topLevelList(TOP_FOO_KEY))), topSubtreeModified(topFoo, topBar));
}
}
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
-import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNull;
}
@SafeVarargs
- public final void assertModifications(final Matcher<T>... inOrder) {
+ public final void verifyModifications(final Matcher<T>... inOrder) {
final var matchers = new ArrayDeque<>(Arrays.asList(inOrder));
- final var changes = new ArrayDeque<>(listener.awaitChanges(matchers.size()));
+ final var changes = listener.awaitChanges(matchers.size());
while (!changes.isEmpty()) {
final var mod = changes.pop();
- final var matcher = matchers.peek();
- if (matcher == null || !matcher.apply(mod)) {
+ final var matcher = matchers.pop();
+ if (!matcher.apply(mod)) {
final var rootNode = mod.getRootNode();
fail("Received unexpected notification: type: %s, path: %s, before: %s, after: %s".formatted(
rootNode.getModificationType(), mod.getRootPath().getRootIdentifier(), rootNode.getDataBefore(),
rootNode.getDataAfter()));
return;
}
-
- matchers.pop();
}
- if (!matchers.isEmpty()) {
- fail("Unsatisfied matchers " + matchers);
+ final var count = listener.changeCount();
+ if (count != 0) {
+ throw new AssertionError("Expected no more changes, %s remain".formatted(count));
}
}
synced = true;
}
- private void awaitSync() {
+ void awaitSync() {
final var sw = Stopwatch.createStarted();
do {
throw new AssertionError("Failed to achieve initial sync");
}
- private List<DataTreeModification<T>> awaitChanges(final int expectedCount) {
+ Deque<DataTreeModification<T>> awaitChanges(final int expectedCount) {
+ final var ret = new ArrayDeque<DataTreeModification<T>>(expectedCount);
final var sw = Stopwatch.createStarted();
+ int remaining = expectedCount;
do {
synchronized (this) {
- if (accumulatedChanges.size() >= expectedCount) {
- return List.copyOf(accumulatedChanges);
+ while (remaining != 0) {
+ final var change = accumulatedChanges.poll();
+ if (change == null) {
+ break;
+ }
+
+ remaining--;
+ ret.add(change);
}
}
+ if (remaining == 0) {
+ return ret;
+ }
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
} while (sw.elapsed(TimeUnit.SECONDS) < 5);
- synchronized (this) {
- throw new AssertionError("Expected %s changes, received only %s".formatted(expectedCount,
- accumulatedChanges.size()));
- }
+ throw new AssertionError("Expected %s changes, received only %s".formatted(expectedCount, ret.size()));
+ }
+
+ synchronized int changeCount() {
+ return accumulatedChanges.size();
}
}