X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardDataTreeTest.java;h=aa38e30fe84f587bd20f8fcbd26e38b8a4f9fa1c;hp=6f0b32b4506ebce3f3886fe227cfc5afbdf231a9;hb=20a32e6459fd1e27e7669bf1ebc7742b96787b94;hpb=29aa3b83db308b1a511857db8d918e0f2e629407 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 6f0b32b450..aa38e30fe8 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 @@ -29,9 +29,9 @@ import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.immediate3PhaseCommit; 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.immediatePayloadReplication; 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; import com.google.common.primitives.UnsignedLong; @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; import org.junit.Before; @@ -73,7 +74,6 @@ public class ShardDataTreeTest extends AbstractTest { @Before public void setUp() { - doReturn(true).when(mockShard).canSkipPayload(); doReturn(Ticker.systemTicker()).when(mockShard).ticker(); doReturn(Mockito.mock(ShardStats.class)).when(mockShard).getShardMBean(); @@ -94,6 +94,7 @@ public class ShardDataTreeTest extends AbstractTest { private void modify(final boolean merge, final boolean expectedCarsPresent, final boolean expectedPeoplePresent) throws ExecutionException, InterruptedException { + immediatePayloadReplication(shardDataTree, mockShard); assertEquals(fullSchema, shardDataTree.getSchemaContext()); @@ -134,6 +135,8 @@ public class ShardDataTreeTest extends AbstractTest { @Test public void bug4359AddRemoveCarOnce() throws ExecutionException, InterruptedException { + immediatePayloadReplication(shardDataTree, mockShard); + final List candidates = new ArrayList<>(); candidates.add(addCar(shardDataTree)); candidates.add(removeCar(shardDataTree)); @@ -149,6 +152,8 @@ public class ShardDataTreeTest extends AbstractTest { @Test public void bug4359AddRemoveCarTwice() throws ExecutionException, InterruptedException { + immediatePayloadReplication(shardDataTree, mockShard); + final List candidates = new ArrayList<>(); candidates.add(addCar(shardDataTree)); candidates.add(removeCar(shardDataTree)); @@ -166,8 +171,11 @@ public class ShardDataTreeTest extends AbstractTest { @Test public void testListenerNotifiedOnApplySnapshot() throws Exception { + immediatePayloadReplication(shardDataTree, mockShard); + DOMDataTreeChangeListener listener = mock(DOMDataTreeChangeListener.class); - shardDataTree.registerTreeChangeListener(CarsModel.CAR_LIST_PATH.node(CarsModel.CAR_QNAME), listener); + shardDataTree.registerTreeChangeListener(CarsModel.CAR_LIST_PATH.node(CarsModel.CAR_QNAME), listener, + com.google.common.base.Optional.absent(), noop -> { }); addCar(shardDataTree, "optima"); @@ -184,6 +192,7 @@ public class ShardDataTreeTest extends AbstractTest { }); ShardDataTree newDataTree = new ShardDataTree(mockShard, fullSchema, TreeType.OPERATIONAL); + immediatePayloadReplication(newDataTree, mockShard); addCar(newDataTree, "optima"); addCar(newDataTree, "murano"); @@ -206,8 +215,6 @@ public class ShardDataTreeTest extends AbstractTest { @Test public void testPipelinedTransactionsWithCoordinatedCommits() throws Exception { - doReturn(false).when(mockShard).canSkipPayload(); - final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer())); @@ -303,8 +310,6 @@ public class ShardDataTreeTest extends AbstractTest { @Test public void testPipelinedTransactionsWithImmediateCommits() throws Exception { - doReturn(false).when(mockShard).canSkipPayload(); - final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer())); @@ -346,11 +351,38 @@ public class ShardDataTreeTest extends AbstractTest { assertEquals("Car node", carNode, optional.get()); } + @Test + public void testPipelinedTransactionsWithImmediateReplication() throws Exception { + immediatePayloadReplication(shardDataTree, mockShard); + + final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> + snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer())); + + final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> + snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode())); + + YangInstanceIdentifier carPath = CarsModel.newCarPath("optima"); + MapEntryNode carNode = CarsModel.newCarEntry("optima", new BigInteger("100")); + final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode)); + + final FutureCallback commitCallback1 = immediate3PhaseCommit(cohort1); + final FutureCallback commitCallback2 = immediate3PhaseCommit(cohort2); + final FutureCallback commitCallback3 = immediate3PhaseCommit(cohort3); + + InOrder inOrder = inOrder(commitCallback1, commitCallback2, commitCallback3); + inOrder.verify(commitCallback1).onSuccess(any(UnsignedLong.class)); + inOrder.verify(commitCallback2).onSuccess(any(UnsignedLong.class)); + inOrder.verify(commitCallback3).onSuccess(any(UnsignedLong.class)); + + final DataTreeSnapshot snapshot = + shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot(); + Optional> optional = snapshot.readNode(CarsModel.BASE_PATH); + assertEquals("Car node present", true, optional.isPresent()); + } + @SuppressWarnings("unchecked") @Test public void testAbortWithPendingCommits() throws Exception { - doReturn(false).when(mockShard).canSkipPayload(); - final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer())); @@ -408,6 +440,8 @@ public class ShardDataTreeTest extends AbstractTest { @SuppressWarnings("unchecked") @Test public void testAbortWithFailedRebase() throws Exception { + immediatePayloadReplication(shardDataTree, mockShard); + final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));