Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / ShardDataTreeTest.java
index 6f0b32b4506ebce3f3886fe227cfc5afbdf231a9..aa38e30fe84f587bd20f8fcbd26e38b8a4f9fa1c 100644 (file)
@@ -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<DataTreeCandidate> 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<DataTreeCandidate> 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<UnsignedLong> commitCallback1 = immediate3PhaseCommit(cohort1);
+        final FutureCallback<UnsignedLong> commitCallback2 = immediate3PhaseCommit(cohort2);
+        final FutureCallback<UnsignedLong> 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<NormalizedNode<?, ?>> 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()));