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%2FShardDataTreeTest.java;h=5a096acbb1206075e438a87042bf54877545182a;hb=5fd8e6506248cc34da72281a1662612f6c2b2f9a;hp=9ae74bb47c1b8dd17a2f3f8b8f7a51d9ecbd68b7;hpb=4f1f2ae598588f6aa5aac59b2206d97ad402a193;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java index 9ae74bb47c..5a096acbb1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java @@ -11,14 +11,15 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.immediateCanCommit; import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.immediateCommit; import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.immediatePreCommit; + import com.google.common.base.Optional; import com.google.common.base.Ticker; import com.google.common.collect.Maps; @@ -76,17 +77,19 @@ public class ShardDataTreeTest extends AbstractTest { } - private void modify(final ShardDataTree shardDataTree, final boolean merge, final boolean expectedCarsPresent, final boolean expectedPeoplePresent) throws ExecutionException, InterruptedException { + private void modify(final ShardDataTree shardDataTree, final boolean merge, final boolean expectedCarsPresent, + final boolean expectedPeoplePresent) throws ExecutionException, InterruptedException { assertEquals(fullSchema, shardDataTree.getSchemaContext()); - final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId()); + final ReadWriteShardDataTreeTransaction transaction = + shardDataTree.newReadWriteTransaction(nextTransactionId()); final DataTreeModification snapshot = transaction.getSnapshot(); assertNotNull(snapshot); - if(merge){ + if (merge) { snapshot.merge(CarsModel.BASE_PATH, CarsModel.create()); snapshot.merge(PeopleModel.BASE_PATH, PeopleModel.create()); } else { @@ -100,7 +103,8 @@ public class ShardDataTreeTest extends AbstractTest { immediatePreCommit(cohort); immediateCommit(cohort); - final ReadOnlyShardDataTreeTransaction readOnlyShardDataTreeTransaction = shardDataTree.newReadOnlyTransaction(nextTransactionId()); + final ReadOnlyShardDataTreeTransaction readOnlyShardDataTreeTransaction = + shardDataTree.newReadOnlyTransaction(nextTransactionId()); final DataTreeSnapshot snapshot1 = readOnlyShardDataTreeTransaction.getSnapshot(); @@ -187,17 +191,18 @@ public class ShardDataTreeTest extends AbstractTest { assertEquals("getModificationType", expType, dtc.getRootNode().getModificationType()); }); - if(!expChanges.isEmpty()) { + if (!expChanges.isEmpty()) { fail("Missing change notifications: " + expChanges); } } @SuppressWarnings({ "rawtypes", "unchecked" }) - private static void verifyOnDataTreeChanged(DOMDataTreeChangeListener listener, Consumer callback) { + private static void verifyOnDataTreeChanged(DOMDataTreeChangeListener listener, + Consumer callback) { ArgumentCaptor changes = ArgumentCaptor.forClass(Collection.class); verify(listener, atLeastOnce()).onDataTreeChanged(changes.capture()); - for(Collection list: changes.getAllValues()) { - for(Object dtc: list) { + for (Collection list : changes.getAllValues()) { + for (Object dtc : list) { callback.accept((DataTreeCandidate)dtc); } } @@ -206,7 +211,8 @@ public class ShardDataTreeTest extends AbstractTest { } private static NormalizedNode getCars(final ShardDataTree shardDataTree) { - final ReadOnlyShardDataTreeTransaction readOnlyShardDataTreeTransaction = shardDataTree.newReadOnlyTransaction(nextTransactionId()); + final ReadOnlyShardDataTreeTransaction readOnlyShardDataTreeTransaction = + shardDataTree.newReadOnlyTransaction(nextTransactionId()); final DataTreeSnapshot snapshot1 = readOnlyShardDataTreeTransaction.getSnapshot(); final Optional> optional = snapshot1.readNode(CarsModel.BASE_PATH); @@ -216,30 +222,34 @@ public class ShardDataTreeTest extends AbstractTest { return optional.get(); } - private static DataTreeCandidateTip addCar(final ShardDataTree shardDataTree) throws ExecutionException, InterruptedException { + private static DataTreeCandidateTip addCar(final ShardDataTree shardDataTree) + throws ExecutionException, InterruptedException { return addCar(shardDataTree, "altima"); } - private static DataTreeCandidateTip addCar(final ShardDataTree shardDataTree, String name) throws ExecutionException, InterruptedException { + private static DataTreeCandidateTip addCar(final ShardDataTree shardDataTree, String name) + throws ExecutionException, InterruptedException { return doTransaction(shardDataTree, snapshot -> { - snapshot.merge(CarsModel.BASE_PATH, CarsModel.emptyContainer()); - snapshot.merge(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()); - snapshot.write(CarsModel.newCarPath(name), CarsModel.newCarEntry(name, new BigInteger("100"))); - }); + snapshot.merge(CarsModel.BASE_PATH, CarsModel.emptyContainer()); + snapshot.merge(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()); + snapshot.write(CarsModel.newCarPath(name), CarsModel.newCarEntry(name, new BigInteger("100"))); + }); } - private static DataTreeCandidateTip removeCar(final ShardDataTree shardDataTree) throws ExecutionException, InterruptedException { + private static DataTreeCandidateTip removeCar(final ShardDataTree shardDataTree) + throws ExecutionException, InterruptedException { return doTransaction(shardDataTree, snapshot -> snapshot.delete(CarsModel.newCarPath("altima"))); } @FunctionalInterface - private static interface DataTreeOperation { + private interface DataTreeOperation { void execute(DataTreeModification snapshot); } - private static DataTreeCandidateTip doTransaction(final ShardDataTree shardDataTree, final DataTreeOperation operation) - throws ExecutionException, InterruptedException { - final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId()); + private static DataTreeCandidateTip doTransaction(final ShardDataTree shardDataTree, + final DataTreeOperation operation) throws ExecutionException, InterruptedException { + final ReadWriteShardDataTreeTransaction transaction = + shardDataTree.newReadWriteTransaction(nextTransactionId()); final DataTreeModification snapshot = transaction.getSnapshot(); operation.execute(snapshot); final ShardDataTreeCohort cohort = shardDataTree.finishTransaction(transaction); @@ -252,11 +262,12 @@ public class ShardDataTreeTest extends AbstractTest { return candidate; } - private static DataTreeCandidateTip applyCandidates(final ShardDataTree shardDataTree, final List candidates) - throws ExecutionException, InterruptedException { - final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId()); + private static DataTreeCandidateTip applyCandidates(final ShardDataTree shardDataTree, + final List candidates) throws ExecutionException, InterruptedException { + final ReadWriteShardDataTreeTransaction transaction = + shardDataTree.newReadWriteTransaction(nextTransactionId()); final DataTreeModification snapshot = transaction.getSnapshot(); - for(final DataTreeCandidateTip candidateTip : candidates){ + for (final DataTreeCandidateTip candidateTip : candidates) { DataTreeCandidates.applyToModification(snapshot, candidateTip); } final ShardDataTreeCohort cohort = shardDataTree.finishTransaction(transaction); @@ -268,5 +279,4 @@ public class ShardDataTreeTest extends AbstractTest { return candidate; } - }