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=6e060f027f2ca10999eb64e5b33d8fe61d5d927a;hp=9c7442bbbcf6332f0f7f2e46ebaa21841b706c26;hb=f41c5e6e6f6e10b36b1e4b1992877e38e718c8fb;hpb=823bd74f34ee1c651f1f90daeef386a35c68d431 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 9c7442bbbc..6e060f027f 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; @@ -53,7 +54,7 @@ import org.opendaylight.controller.cluster.datastore.persisted.CommitTransaction import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; -import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; +import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -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())); @@ -347,31 +352,27 @@ public class ShardDataTreeTest extends AbstractTest { } @Test - public void testPipelinedTransactionsWithUnmodifiedCandidate() throws Exception { - doReturn(false).when(mockShard).canSkipPayload(); + 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.merge(CarsModel.BASE_PATH, CarsModel.emptyContainer())); - - final FutureCallback commitCallback1 = immediate3PhaseCommit(cohort1); + snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode())); - verify(mockShard).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), eq(false)); + 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); - verify(mockShard, never()).persistPayload(eq(cohort2.getIdentifier()), any(CommitTransactionPayload.class), - anyBoolean()); - - // The payload instance doesn't matter - it just needs to be of type CommitTransactionPayload. - shardDataTree.applyReplicatedPayload(cohort1.getIdentifier(), - CommitTransactionPayload.create(nextTransactionId(), cohort1.getCandidate())); - - InOrder inOrder = inOrder(commitCallback1, commitCallback2); + 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(); @@ -382,8 +383,6 @@ public class ShardDataTreeTest extends AbstractTest { @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())); @@ -441,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()));