Bug 3376: Add debug context for CDS transactions
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / TransactionProxyTest.java
1 package org.opendaylight.controller.cluster.datastore;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6 import static org.mockito.Matchers.any;
7 import static org.mockito.Matchers.anyString;
8 import static org.mockito.Matchers.eq;
9 import static org.mockito.Matchers.isA;
10 import static org.mockito.Mockito.doReturn;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.never;
13 import static org.mockito.Mockito.verify;
14 import static org.opendaylight.controller.cluster.datastore.TransactionType.READ_ONLY;
15 import static org.opendaylight.controller.cluster.datastore.TransactionType.READ_WRITE;
16 import static org.opendaylight.controller.cluster.datastore.TransactionType.WRITE_ONLY;
17 import akka.actor.ActorRef;
18 import akka.actor.ActorSelection;
19 import akka.actor.ActorSystem;
20 import akka.actor.Props;
21 import akka.dispatch.Futures;
22 import com.google.common.base.Optional;
23 import com.google.common.collect.Sets;
24 import com.google.common.util.concurrent.CheckedFuture;
25 import com.google.common.util.concurrent.FutureCallback;
26 import com.google.common.util.concurrent.Uninterruptibles;
27 import java.util.Collection;
28 import java.util.List;
29 import java.util.concurrent.CountDownLatch;
30 import java.util.concurrent.ExecutionException;
31 import java.util.concurrent.TimeUnit;
32 import java.util.concurrent.atomic.AtomicReference;
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.mockito.InOrder;
36 import org.mockito.Mockito;
37 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
38 import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException;
39 import org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException;
40 import org.opendaylight.controller.cluster.datastore.exceptions.TimeoutException;
41 import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
42 import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction;
43 import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply;
44 import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
45 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
46 import org.opendaylight.controller.cluster.datastore.modification.DeleteModification;
47 import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
48 import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
49 import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy;
50 import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor;
51 import org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest;
52 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
53 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
54 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
55 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
56 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages.CreateTransactionReply;
57 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
58 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
59 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
60 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
61 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
62 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
63 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
64 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
65 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
66 import scala.concurrent.Promise;
67
68 @SuppressWarnings("resource")
69 public class TransactionProxyTest extends AbstractTransactionProxyTest {
70
71     @SuppressWarnings("serial")
72     static class TestException extends RuntimeException {
73     }
74
75     static interface Invoker {
76         CheckedFuture<?, ReadFailedException> invoke(TransactionProxy proxy) throws Exception;
77     }
78
79     @Test
80     public void testRead() throws Exception {
81         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
82
83         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
84
85         doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
86                 eq(actorSelection(actorRef)), eqSerializedReadData());
87
88         Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(
89                 TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
90
91         assertEquals("NormalizedNode isPresent", false, readOptional.isPresent());
92
93         NormalizedNode<?, ?> expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
94
95         doReturn(readSerializedDataReply(expectedNode)).when(mockActorContext).executeOperationAsync(
96                 eq(actorSelection(actorRef)), eqSerializedReadData());
97
98         readOptional = transactionProxy.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
99
100         assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
101
102         assertEquals("Response NormalizedNode", expectedNode, readOptional.get());
103     }
104
105     @Test(expected = ReadFailedException.class)
106     public void testReadWithInvalidReplyMessageType() throws Exception {
107         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
108
109         doReturn(Futures.successful(new Object())).when(mockActorContext).
110                 executeOperationAsync(eq(actorSelection(actorRef)), eqSerializedReadData());
111
112         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
113
114         transactionProxy.read(TestModel.TEST_PATH).checkedGet(5, TimeUnit.SECONDS);
115     }
116
117     @Test(expected = TestException.class)
118     public void testReadWithAsyncRemoteOperatonFailure() throws Throwable {
119         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
120
121         doReturn(Futures.failed(new TestException())).when(mockActorContext).
122                 executeOperationAsync(eq(actorSelection(actorRef)), eqSerializedReadData());
123
124         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
125
126         propagateReadFailedExceptionCause(transactionProxy.read(TestModel.TEST_PATH));
127     }
128
129     private void testExceptionOnInitialCreateTransaction(Exception exToThrow, Invoker invoker)
130             throws Throwable {
131         ActorRef actorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
132
133         if (exToThrow instanceof PrimaryNotFoundException) {
134             doReturn(Futures.failed(exToThrow)).when(mockActorContext).findPrimaryShardAsync(anyString());
135         } else {
136             doReturn(primaryShardInfoReply(getSystem(), actorRef)).
137                     when(mockActorContext).findPrimaryShardAsync(anyString());
138         }
139
140         doReturn(Futures.failed(exToThrow)).when(mockActorContext).executeOperationAsync(
141                 any(ActorSelection.class), any());
142
143         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
144
145         propagateReadFailedExceptionCause(invoker.invoke(transactionProxy));
146     }
147
148     private void testReadWithExceptionOnInitialCreateTransaction(Exception exToThrow) throws Throwable {
149         testExceptionOnInitialCreateTransaction(exToThrow, new Invoker() {
150             @Override
151             public CheckedFuture<?, ReadFailedException> invoke(TransactionProxy proxy) throws Exception {
152                 return proxy.read(TestModel.TEST_PATH);
153             }
154         });
155     }
156
157     @Test(expected = PrimaryNotFoundException.class)
158     public void testReadWhenAPrimaryNotFoundExceptionIsThrown() throws Throwable {
159         testReadWithExceptionOnInitialCreateTransaction(new PrimaryNotFoundException("test"));
160     }
161
162     @Test(expected = TimeoutException.class)
163     public void testReadWhenATimeoutExceptionIsThrown() throws Throwable {
164         testReadWithExceptionOnInitialCreateTransaction(new TimeoutException("test",
165                 new Exception("reason")));
166     }
167
168     @Test(expected = TestException.class)
169     public void testReadWhenAnyOtherExceptionIsThrown() throws Throwable {
170         testReadWithExceptionOnInitialCreateTransaction(new TestException());
171     }
172
173     @Test
174     public void testReadWithPriorRecordingOperationSuccessful() throws Throwable {
175         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
176
177         NormalizedNode<?, ?> expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
178
179         expectBatchedModifications(actorRef, 1);
180
181         doReturn(readSerializedDataReply(expectedNode)).when(mockActorContext).executeOperationAsync(
182                 eq(actorSelection(actorRef)), eqSerializedReadData());
183
184         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
185
186         transactionProxy.write(TestModel.TEST_PATH, expectedNode);
187
188         Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(
189                 TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
190
191         assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
192         assertEquals("Response NormalizedNode", expectedNode, readOptional.get());
193
194         InOrder inOrder = Mockito.inOrder(mockActorContext);
195         inOrder.verify(mockActorContext).executeOperationAsync(
196                 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
197
198         inOrder.verify(mockActorContext).executeOperationAsync(
199                 eq(actorSelection(actorRef)), eqSerializedReadData());
200     }
201
202     @Test(expected=IllegalStateException.class)
203     public void testReadPreConditionCheck() {
204         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
205         transactionProxy.read(TestModel.TEST_PATH);
206     }
207
208     @Test(expected=IllegalArgumentException.class)
209     public void testInvalidCreateTransactionReply() throws Throwable {
210         ActorRef actorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
211
212         doReturn(getSystem().actorSelection(actorRef.path())).when(mockActorContext).
213             actorSelection(actorRef.path().toString());
214
215         doReturn(primaryShardInfoReply(getSystem(), actorRef)).
216             when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
217
218         doReturn(Futures.successful(new Object())).when(mockActorContext).executeOperationAsync(
219             eq(getSystem().actorSelection(actorRef.path())), eqCreateTransaction(memberName, READ_ONLY));
220
221         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
222
223         propagateReadFailedExceptionCause(transactionProxy.read(TestModel.TEST_PATH));
224     }
225
226     @Test
227     public void testExists() throws Exception {
228         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
229
230         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
231
232         doReturn(dataExistsSerializedReply(false)).when(mockActorContext).executeOperationAsync(
233                 eq(actorSelection(actorRef)), eqSerializedDataExists());
234
235         Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
236
237         assertEquals("Exists response", false, exists);
238
239         doReturn(dataExistsSerializedReply(true)).when(mockActorContext).executeOperationAsync(
240                 eq(actorSelection(actorRef)), eqSerializedDataExists());
241
242         exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
243
244         assertEquals("Exists response", true, exists);
245     }
246
247     @Test(expected = PrimaryNotFoundException.class)
248     public void testExistsWhenAPrimaryNotFoundExceptionIsThrown() throws Throwable {
249         testExceptionOnInitialCreateTransaction(new PrimaryNotFoundException("test"), new Invoker() {
250             @Override
251             public CheckedFuture<?, ReadFailedException> invoke(TransactionProxy proxy) throws Exception {
252                 return proxy.exists(TestModel.TEST_PATH);
253             }
254         });
255     }
256
257     @Test(expected = ReadFailedException.class)
258     public void testExistsWithInvalidReplyMessageType() throws Exception {
259         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
260
261         doReturn(Futures.successful(new Object())).when(mockActorContext).
262                 executeOperationAsync(eq(actorSelection(actorRef)), eqSerializedDataExists());
263
264         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
265
266         transactionProxy.exists(TestModel.TEST_PATH).checkedGet(5, TimeUnit.SECONDS);
267     }
268
269     @Test(expected = TestException.class)
270     public void testExistsWithAsyncRemoteOperatonFailure() throws Throwable {
271         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
272
273         doReturn(Futures.failed(new TestException())).when(mockActorContext).
274                 executeOperationAsync(eq(actorSelection(actorRef)), eqSerializedDataExists());
275
276         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
277
278         propagateReadFailedExceptionCause(transactionProxy.exists(TestModel.TEST_PATH));
279     }
280
281     @Test
282     public void testExistsWithPriorRecordingOperationSuccessful() throws Throwable {
283         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
284
285         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
286
287         expectBatchedModifications(actorRef, 1);
288
289         doReturn(dataExistsSerializedReply(true)).when(mockActorContext).executeOperationAsync(
290                 eq(actorSelection(actorRef)), eqSerializedDataExists());
291
292         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
293
294         transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
295
296         Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
297
298         assertEquals("Exists response", true, exists);
299
300         InOrder inOrder = Mockito.inOrder(mockActorContext);
301         inOrder.verify(mockActorContext).executeOperationAsync(
302                 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
303
304         inOrder.verify(mockActorContext).executeOperationAsync(
305                 eq(actorSelection(actorRef)), eqSerializedDataExists());
306     }
307
308     @Test(expected=IllegalStateException.class)
309     public void testExistsPreConditionCheck() {
310         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
311         transactionProxy.exists(TestModel.TEST_PATH);
312     }
313
314     @Test
315     public void testWrite() throws Exception {
316         dataStoreContextBuilder.shardBatchedModificationCount(1);
317         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
318
319         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
320
321         expectBatchedModifications(actorRef, 1);
322
323         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
324
325         transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
326
327         verifyOneBatchedModification(actorRef, new WriteModification(TestModel.TEST_PATH, nodeToWrite), false);
328     }
329
330     @Test
331     public void testWriteAfterAsyncRead() throws Throwable {
332         ActorRef actorRef = setupActorContextWithoutInitialCreateTransaction(getSystem(), DefaultShardStrategy.DEFAULT_SHARD);
333
334         Promise<Object> createTxPromise = akka.dispatch.Futures.promise();
335         doReturn(createTxPromise).when(mockActorContext).executeOperationAsync(
336                 eq(getSystem().actorSelection(actorRef.path())),
337                 eqCreateTransaction(memberName, READ_WRITE));
338
339         doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
340                 eq(actorSelection(actorRef)), eqSerializedReadData());
341
342         expectBatchedModificationsReady(actorRef);
343
344         final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
345
346         final TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
347
348         final CountDownLatch readComplete = new CountDownLatch(1);
349         final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
350         com.google.common.util.concurrent.Futures.addCallback(transactionProxy.read(TestModel.TEST_PATH),
351                 new  FutureCallback<Optional<NormalizedNode<?, ?>>>() {
352                     @Override
353                     public void onSuccess(Optional<NormalizedNode<?, ?>> result) {
354                         try {
355                             transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
356                         } catch (Exception e) {
357                             caughtEx.set(e);
358                         } finally {
359                             readComplete.countDown();
360                         }
361                     }
362
363                     @Override
364                     public void onFailure(Throwable t) {
365                         caughtEx.set(t);
366                         readComplete.countDown();
367                     }
368                 });
369
370         createTxPromise.success(createTransactionReply(actorRef, DataStoreVersions.CURRENT_VERSION));
371
372         Uninterruptibles.awaitUninterruptibly(readComplete, 5, TimeUnit.SECONDS);
373
374         if(caughtEx.get() != null) {
375             throw caughtEx.get();
376         }
377
378         // This sends the batched modification.
379         transactionProxy.ready();
380
381         verifyOneBatchedModification(actorRef, new WriteModification(TestModel.TEST_PATH, nodeToWrite), true);
382     }
383
384     @Test(expected=IllegalStateException.class)
385     public void testWritePreConditionCheck() {
386         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
387         transactionProxy.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
388     }
389
390     @Test(expected=IllegalStateException.class)
391     public void testWriteAfterReadyPreConditionCheck() {
392         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
393
394         transactionProxy.ready();
395
396         transactionProxy.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
397     }
398
399     @Test
400     public void testMerge() throws Exception {
401         dataStoreContextBuilder.shardBatchedModificationCount(1);
402         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
403
404         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
405
406         expectBatchedModifications(actorRef, 1);
407
408         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
409
410         transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
411
412         verifyOneBatchedModification(actorRef, new MergeModification(TestModel.TEST_PATH, nodeToWrite), false);
413     }
414
415     @Test
416     public void testDelete() throws Exception {
417         dataStoreContextBuilder.shardBatchedModificationCount(1);
418         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
419
420         expectBatchedModifications(actorRef, 1);
421
422         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
423
424         transactionProxy.delete(TestModel.TEST_PATH);
425
426         verifyOneBatchedModification(actorRef, new DeleteModification(TestModel.TEST_PATH), false);
427     }
428
429     @Test
430     public void testReadWrite() throws Exception {
431         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
432
433         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
434
435         doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
436                 eq(actorSelection(actorRef)), eqSerializedReadData());
437
438         expectBatchedModifications(actorRef, 1);
439
440         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
441
442         transactionProxy.read(TestModel.TEST_PATH);
443
444         transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
445
446         transactionProxy.read(TestModel.TEST_PATH);
447
448         transactionProxy.read(TestModel.TEST_PATH);
449
450         List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
451         assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
452
453         verifyBatchedModifications(batchedModifications.get(0), false,
454                 new WriteModification(TestModel.TEST_PATH, nodeToWrite));
455     }
456
457     @Test
458     public void testReadyWithReadWrite() throws Exception {
459         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
460
461         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
462
463         doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
464                 eq(actorSelection(actorRef)), eqSerializedReadData());
465
466         expectBatchedModificationsReady(actorRef, true);
467
468         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
469
470         transactionProxy.read(TestModel.TEST_PATH);
471
472         transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
473
474         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
475
476         assertTrue(ready instanceof SingleCommitCohortProxy);
477
478         verifyCohortFutures((SingleCommitCohortProxy)ready, new CommitTransactionReply().toSerializable());
479
480         List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
481         assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
482
483         verifyBatchedModifications(batchedModifications.get(0), true, true,
484                 new WriteModification(TestModel.TEST_PATH, nodeToWrite));
485
486         assertEquals("getTotalMessageCount", 1, batchedModifications.get(0).getTotalMessagesSent());
487     }
488
489     @Test
490     public void testReadyWithNoModifications() throws Exception {
491         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
492
493         doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
494                 eq(actorSelection(actorRef)), eqSerializedReadData());
495
496         expectBatchedModificationsReady(actorRef, true);
497
498         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
499
500         transactionProxy.read(TestModel.TEST_PATH);
501
502         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
503
504         assertTrue(ready instanceof SingleCommitCohortProxy);
505
506         verifyCohortFutures((SingleCommitCohortProxy)ready, new CommitTransactionReply().toSerializable());
507
508         List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
509         assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
510
511         verifyBatchedModifications(batchedModifications.get(0), true, true);
512     }
513
514     @Test
515     public void testReadyWithMultipleShardWrites() throws Exception {
516         ActorRef actorRef1 = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
517
518         ActorRef actorRef2 = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY, "junk");
519
520         expectBatchedModificationsReady(actorRef1);
521         expectBatchedModificationsReady(actorRef2);
522
523         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
524
525         transactionProxy.write(TestModel.JUNK_PATH, ImmutableNodes.containerNode(TestModel.JUNK_QNAME));
526         transactionProxy.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
527
528         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
529
530         assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
531
532         verifyCohortFutures((ThreePhaseCommitCohortProxy)ready, actorSelection(actorRef1),
533                 actorSelection(actorRef2));
534     }
535
536     @Test
537     public void testReadyWithWriteOnlyAndLastBatchPending() throws Exception {
538         dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
539
540         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
541
542         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
543
544         expectBatchedModificationsReady(actorRef, true);
545
546         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
547
548         transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
549
550         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
551
552         assertTrue(ready instanceof SingleCommitCohortProxy);
553
554         verifyCohortFutures((SingleCommitCohortProxy)ready, new CommitTransactionReply().toSerializable());
555
556         List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
557         assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
558
559         verifyBatchedModifications(batchedModifications.get(0), true, true,
560                 new WriteModification(TestModel.TEST_PATH, nodeToWrite));
561
562         verify(mockActorContext, never()).executeOperationAsync(eq(actorSelection(actorRef)),
563                 isA(ReadyTransaction.SERIALIZABLE_CLASS));
564     }
565
566     @Test
567     public void testReadyWithWriteOnlyAndLastBatchEmpty() throws Exception {
568         dataStoreContextBuilder.shardBatchedModificationCount(1).writeOnlyTransactionOptimizationsEnabled(true);
569         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
570
571         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
572
573         expectBatchedModificationsReady(actorRef, true);
574
575         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
576
577         transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
578
579         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
580
581         assertTrue(ready instanceof SingleCommitCohortProxy);
582
583         verifyCohortFutures((SingleCommitCohortProxy)ready, new CommitTransactionReply().toSerializable());
584
585         List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
586         assertEquals("Captured BatchedModifications count", 2, batchedModifications.size());
587
588         verifyBatchedModifications(batchedModifications.get(0), false,
589                 new WriteModification(TestModel.TEST_PATH, nodeToWrite));
590
591         verifyBatchedModifications(batchedModifications.get(1), true, true);
592
593         verify(mockActorContext, never()).executeOperationAsync(eq(actorSelection(actorRef)),
594                 isA(ReadyTransaction.SERIALIZABLE_CLASS));
595     }
596
597     @Test
598     public void testReadyWithReplyFailure() throws Exception {
599         dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
600
601         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
602
603         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
604
605         expectFailedBatchedModifications(actorRef);
606
607         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
608
609         transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
610
611         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
612
613         assertTrue(ready instanceof SingleCommitCohortProxy);
614
615         verifyCohortFutures((SingleCommitCohortProxy)ready, TestException.class);
616     }
617
618     @Test
619     public void testReadyWithDebugContextEnabled() throws Exception {
620         dataStoreContextBuilder.transactionDebugContextEnabled(true);
621
622         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
623
624         expectBatchedModificationsReady(actorRef, true);
625
626         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
627
628         transactionProxy.merge(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
629
630         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
631
632         assertTrue(ready instanceof DebugThreePhaseCommitCohort);
633
634         verifyCohortFutures((DebugThreePhaseCommitCohort)ready, new CommitTransactionReply().toSerializable());
635     }
636
637     private void testWriteOnlyTxWithFindPrimaryShardFailure(Exception toThrow) throws Exception {
638         doReturn(Futures.failed(toThrow)).when(mockActorContext).findPrimaryShardAsync(anyString());
639
640         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
641
642         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
643
644         transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
645
646         transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
647
648         transactionProxy.delete(TestModel.TEST_PATH);
649
650         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
651
652         assertTrue(ready instanceof SingleCommitCohortProxy);
653
654         verifyCohortFutures((SingleCommitCohortProxy)ready, toThrow.getClass());
655     }
656
657     @Test
658     public void testWriteOnlyTxWithPrimaryNotFoundException() throws Exception {
659         testWriteOnlyTxWithFindPrimaryShardFailure(new PrimaryNotFoundException("mock"));
660     }
661
662     @Test
663     public void testWriteOnlyTxWithNotInitializedException() throws Exception {
664         testWriteOnlyTxWithFindPrimaryShardFailure(new NotInitializedException("mock"));
665     }
666
667     @Test
668     public void testWriteOnlyTxWithNoShardLeaderException() throws Exception {
669         testWriteOnlyTxWithFindPrimaryShardFailure(new NoShardLeaderException("mock"));
670     }
671
672     @Test
673     public void testReadyWithInvalidReplyMessageType() throws Exception {
674         dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
675         ActorRef actorRef1 = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
676
677         ActorRef actorRef2 = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY, "junk");
678
679         doReturn(Futures.successful(new Object())).when(mockActorContext).
680                 executeOperationAsync(eq(actorSelection(actorRef1)), isA(BatchedModifications.class));
681
682         expectBatchedModificationsReady(actorRef2);
683
684         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
685
686         transactionProxy.write(TestModel.JUNK_PATH, ImmutableNodes.containerNode(TestModel.JUNK_QNAME));
687         transactionProxy.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
688
689         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
690
691         assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
692
693         verifyCohortFutures((ThreePhaseCommitCohortProxy)ready, actorSelection(actorRef2),
694                 IllegalArgumentException.class);
695     }
696
697     @Test
698     public void testGetIdentifier() {
699         setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
700         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
701
702         Object id = transactionProxy.getIdentifier();
703         assertNotNull("getIdentifier returned null", id);
704         assertTrue("Invalid identifier: " + id, id.toString().startsWith(memberName));
705     }
706
707     @Test
708     public void testClose() throws Exception{
709         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
710
711         doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
712                 eq(actorSelection(actorRef)), eqSerializedReadData());
713
714         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
715
716         transactionProxy.read(TestModel.TEST_PATH);
717
718         transactionProxy.close();
719
720         verify(mockActorContext).sendOperationAsync(
721                 eq(actorSelection(actorRef)), isA(CloseTransaction.SERIALIZABLE_CLASS));
722     }
723
724
725     /**
726      * Method to test a local Tx actor. The Tx paths are matched to decide if the
727      * Tx actor is local or not. This is done by mocking the Tx actor path
728      * and the caller paths and ensuring that the paths have the remote-address format
729      *
730      * Note: Since the default akka provider for test is not a RemoteActorRefProvider,
731      * the paths returned for the actors for all the tests are not qualified remote paths.
732      * Hence are treated as non-local/remote actors. In short, all tests except
733      * few below run for remote actors
734      *
735      * @throws Exception
736      */
737     @Test
738     public void testLocalTxActorRead() throws Exception {
739         setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
740         doReturn(true).when(mockActorContext).isPathLocal(anyString());
741
742         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
743
744         // negative test case with null as the reply
745         doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(
746             any(ActorSelection.class), eqReadData());
747
748         Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(
749             TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
750
751         assertEquals("NormalizedNode isPresent", false, readOptional.isPresent());
752
753         // test case with node as read data reply
754         NormalizedNode<?, ?> expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
755
756         doReturn(readDataReply(expectedNode)).when(mockActorContext).executeOperationAsync(
757             any(ActorSelection.class), eqReadData());
758
759         readOptional = transactionProxy.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
760
761         assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
762
763         assertEquals("Response NormalizedNode", expectedNode, readOptional.get());
764
765         // test for local data exists
766         doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync(
767             any(ActorSelection.class), eqDataExists());
768
769         boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
770
771         assertEquals("Exists response", true, exists);
772     }
773
774     @Test
775     public void testLocalTxActorReady() throws Exception {
776         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
777         doReturn(true).when(mockActorContext).isPathLocal(anyString());
778
779         expectBatchedModificationsReady(actorRef, true);
780
781         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
782
783         NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
784         transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
785
786         DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
787
788         assertTrue(ready instanceof SingleCommitCohortProxy);
789
790         verifyCohortFutures((SingleCommitCohortProxy)ready, new CommitTransactionReply().toSerializable());
791     }
792
793     private static interface TransactionProxyOperation {
794         void run(TransactionProxy transactionProxy);
795     }
796
797     private void throttleOperation(TransactionProxyOperation operation) {
798         throttleOperation(operation, 1, true);
799     }
800
801     private PrimaryShardInfo newPrimaryShardInfo(ActorRef actorRef){
802         return new PrimaryShardInfo(getSystem().actorSelection(actorRef.path()), Optional.<DataTree>absent());
803     }
804
805     private PrimaryShardInfo newPrimaryShardInfo(ActorRef actorRef, Optional<DataTree> dataTreeOptional){
806         return new PrimaryShardInfo(getSystem().actorSelection(actorRef.path()), dataTreeOptional);
807     }
808
809
810     private void throttleOperation(TransactionProxyOperation operation, int outstandingOpsLimit, boolean shardFound){
811         ActorSystem actorSystem = getSystem();
812         ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
813
814         doReturn(outstandingOpsLimit).when(mockActorContext).getTransactionOutstandingOperationLimit();
815
816         doReturn(actorSystem.actorSelection(shardActorRef.path())).
817                 when(mockActorContext).actorSelection(shardActorRef.path().toString());
818
819         if(shardFound) {
820             doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).
821                     when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
822         } else {
823             doReturn(Futures.failed(new Exception("not found")))
824                     .when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
825         }
826
827         String actorPath = "akka.tcp://system@127.0.0.1:2550/user/tx-actor";
828         CreateTransactionReply createTransactionReply = CreateTransactionReply.newBuilder().
829                 setTransactionId("txn-1").setTransactionActorPath(actorPath).
830                 setMessageVersion(DataStoreVersions.CURRENT_VERSION).build();
831
832         doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).
833                 executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())),
834                         eqCreateTransaction(memberName, READ_WRITE));
835
836         doReturn(true).when(mockActorContext).isPathLocal(actorPath);
837
838         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
839
840         long start = System.nanoTime();
841
842         operation.run(transactionProxy);
843
844         long end = System.nanoTime();
845
846         long expected = TimeUnit.SECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds());
847         Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s",
848                 expected, (end-start)), (end - start) > expected);
849
850     }
851
852     private void completeOperation(TransactionProxyOperation operation){
853         completeOperation(operation, true);
854     }
855
856     private void completeOperation(TransactionProxyOperation operation, boolean shardFound){
857         ActorSystem actorSystem = getSystem();
858         ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
859
860         doReturn(1).when(mockActorContext).getTransactionOutstandingOperationLimit();
861
862         doReturn(actorSystem.actorSelection(shardActorRef.path())).
863                 when(mockActorContext).actorSelection(shardActorRef.path().toString());
864
865         if(shardFound) {
866             doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).
867                     when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
868         } else {
869             doReturn(Futures.failed(new PrimaryNotFoundException("test")))
870                     .when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
871         }
872
873         ActorRef txActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
874         String actorPath = txActorRef.path().toString();
875         CreateTransactionReply createTransactionReply = CreateTransactionReply.newBuilder().
876                 setTransactionId("txn-1").setTransactionActorPath(actorPath).
877                 setMessageVersion(DataStoreVersions.CURRENT_VERSION).build();
878
879         doReturn(actorSystem.actorSelection(actorPath)).when(mockActorContext).actorSelection(actorPath);
880
881         doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).
882                 executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())),
883                         eqCreateTransaction(memberName, READ_WRITE));
884
885         doReturn(true).when(mockActorContext).isPathLocal(anyString());
886
887         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
888
889         long start = System.nanoTime();
890
891         operation.run(transactionProxy);
892
893         long end = System.nanoTime();
894
895         long expected = TimeUnit.SECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds());
896         Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s",
897                 expected, (end-start)), (end - start) <= expected);
898     }
899
900     private void completeOperationLocal(TransactionProxyOperation operation, Optional<DataTree> dataTreeOptional){
901         ActorSystem actorSystem = getSystem();
902         ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
903
904         doReturn(1).when(mockActorContext).getTransactionOutstandingOperationLimit();
905
906         doReturn(actorSystem.actorSelection(shardActorRef.path())).
907                 when(mockActorContext).actorSelection(shardActorRef.path().toString());
908
909         doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef, dataTreeOptional))).
910                 when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
911
912         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
913
914         long start = System.nanoTime();
915
916         operation.run(transactionProxy);
917
918         long end = System.nanoTime();
919
920         long expected = TimeUnit.SECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds());
921         Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s",
922                 expected, (end-start)), (end - start) <= expected);
923     }
924
925     private Optional<DataTree> createDataTree(){
926         DataTree dataTree = mock(DataTree.class);
927         Optional<DataTree> dataTreeOptional = Optional.of(dataTree);
928         DataTreeSnapshot dataTreeSnapshot = mock(DataTreeSnapshot.class);
929         DataTreeModification dataTreeModification = mock(DataTreeModification.class);
930
931         doReturn(dataTreeSnapshot).when(dataTree).takeSnapshot();
932         doReturn(dataTreeModification).when(dataTreeSnapshot).newModification();
933
934         return dataTreeOptional;
935     }
936
937     private Optional<DataTree> createDataTree(NormalizedNode readResponse){
938         DataTree dataTree = mock(DataTree.class);
939         Optional<DataTree> dataTreeOptional = Optional.of(dataTree);
940         DataTreeSnapshot dataTreeSnapshot = mock(DataTreeSnapshot.class);
941         DataTreeModification dataTreeModification = mock(DataTreeModification.class);
942
943         doReturn(dataTreeSnapshot).when(dataTree).takeSnapshot();
944         doReturn(dataTreeModification).when(dataTreeSnapshot).newModification();
945         doReturn(Optional.of(readResponse)).when(dataTreeModification).readNode(any(YangInstanceIdentifier.class));
946
947         return dataTreeOptional;
948     }
949
950
951     @Test
952     public void testWriteCompletionForLocalShard(){
953         dataStoreContextBuilder.shardBatchedModificationCount(1);
954         completeOperationLocal(new TransactionProxyOperation() {
955             @Override
956             public void run(TransactionProxy transactionProxy) {
957                 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
958
959                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
960
961                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
962
963             }
964         }, createDataTree());
965     }
966
967     @Test
968     public void testWriteThrottlingWhenShardFound(){
969         dataStoreContextBuilder.shardBatchedModificationCount(1);
970         throttleOperation(new TransactionProxyOperation() {
971             @Override
972             public void run(TransactionProxy transactionProxy) {
973                 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
974
975                 expectIncompleteBatchedModifications();
976
977                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
978
979                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
980             }
981         });
982     }
983
984     @Test
985     public void testWriteThrottlingWhenShardNotFound(){
986         // Confirm that there is no throttling when the Shard is not found
987         dataStoreContextBuilder.shardBatchedModificationCount(1);
988         completeOperation(new TransactionProxyOperation() {
989             @Override
990             public void run(TransactionProxy transactionProxy) {
991                 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
992
993                 expectBatchedModifications(2);
994
995                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
996
997                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
998             }
999         }, false);
1000
1001     }
1002
1003
1004     @Test
1005     public void testWriteCompletion(){
1006         dataStoreContextBuilder.shardBatchedModificationCount(1);
1007         completeOperation(new TransactionProxyOperation() {
1008             @Override
1009             public void run(TransactionProxy transactionProxy) {
1010                 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1011
1012                 expectBatchedModifications(2);
1013
1014                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1015
1016                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1017             }
1018         });
1019     }
1020
1021     @Test
1022     public void testMergeThrottlingWhenShardFound(){
1023         dataStoreContextBuilder.shardBatchedModificationCount(1);
1024         throttleOperation(new TransactionProxyOperation() {
1025             @Override
1026             public void run(TransactionProxy transactionProxy) {
1027                 NormalizedNode<?, ?> nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1028
1029                 expectIncompleteBatchedModifications();
1030
1031                 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1032
1033                 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1034             }
1035         });
1036     }
1037
1038     @Test
1039     public void testMergeThrottlingWhenShardNotFound(){
1040         dataStoreContextBuilder.shardBatchedModificationCount(1);
1041         completeOperation(new TransactionProxyOperation() {
1042             @Override
1043             public void run(TransactionProxy transactionProxy) {
1044                 NormalizedNode<?, ?> nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1045
1046                 expectBatchedModifications(2);
1047
1048                 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1049
1050                 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1051             }
1052         }, false);
1053     }
1054
1055     @Test
1056     public void testMergeCompletion(){
1057         dataStoreContextBuilder.shardBatchedModificationCount(1);
1058         completeOperation(new TransactionProxyOperation() {
1059             @Override
1060             public void run(TransactionProxy transactionProxy) {
1061                 NormalizedNode<?, ?> nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1062
1063                 expectBatchedModifications(2);
1064
1065                 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1066
1067                 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1068             }
1069         });
1070
1071     }
1072
1073     @Test
1074     public void testMergeCompletionForLocalShard(){
1075         dataStoreContextBuilder.shardBatchedModificationCount(1);
1076         completeOperationLocal(new TransactionProxyOperation() {
1077             @Override
1078             public void run(TransactionProxy transactionProxy) {
1079                 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1080
1081                 transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
1082
1083                 transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
1084
1085             }
1086         }, createDataTree());
1087     }
1088
1089
1090     @Test
1091     public void testDeleteThrottlingWhenShardFound(){
1092
1093         throttleOperation(new TransactionProxyOperation() {
1094             @Override
1095             public void run(TransactionProxy transactionProxy) {
1096                 expectIncompleteBatchedModifications();
1097
1098                 transactionProxy.delete(TestModel.TEST_PATH);
1099
1100                 transactionProxy.delete(TestModel.TEST_PATH);
1101             }
1102         });
1103     }
1104
1105
1106     @Test
1107     public void testDeleteThrottlingWhenShardNotFound(){
1108
1109         completeOperation(new TransactionProxyOperation() {
1110             @Override
1111             public void run(TransactionProxy transactionProxy) {
1112                 expectBatchedModifications(2);
1113
1114                 transactionProxy.delete(TestModel.TEST_PATH);
1115
1116                 transactionProxy.delete(TestModel.TEST_PATH);
1117             }
1118         }, false);
1119     }
1120
1121     @Test
1122     public void testDeleteCompletionForLocalShard(){
1123         dataStoreContextBuilder.shardBatchedModificationCount(1);
1124         completeOperationLocal(new TransactionProxyOperation() {
1125             @Override
1126             public void run(TransactionProxy transactionProxy) {
1127
1128                 transactionProxy.delete(TestModel.TEST_PATH);
1129
1130                 transactionProxy.delete(TestModel.TEST_PATH);
1131             }
1132         }, createDataTree());
1133
1134     }
1135
1136     @Test
1137     public void testDeleteCompletion(){
1138         dataStoreContextBuilder.shardBatchedModificationCount(1);
1139         completeOperation(new TransactionProxyOperation() {
1140             @Override
1141             public void run(TransactionProxy transactionProxy) {
1142                 expectBatchedModifications(2);
1143
1144                 transactionProxy.delete(TestModel.TEST_PATH);
1145
1146                 transactionProxy.delete(TestModel.TEST_PATH);
1147             }
1148         });
1149
1150     }
1151
1152     @Test
1153     public void testReadThrottlingWhenShardFound(){
1154
1155         throttleOperation(new TransactionProxyOperation() {
1156             @Override
1157             public void run(TransactionProxy transactionProxy) {
1158                 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1159                         any(ActorSelection.class), eqReadData());
1160
1161                 transactionProxy.read(TestModel.TEST_PATH);
1162
1163                 transactionProxy.read(TestModel.TEST_PATH);
1164             }
1165         });
1166     }
1167
1168     @Test
1169     public void testReadThrottlingWhenShardNotFound(){
1170
1171         completeOperation(new TransactionProxyOperation() {
1172             @Override
1173             public void run(TransactionProxy transactionProxy) {
1174                 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1175                         any(ActorSelection.class), eqReadData());
1176
1177                 transactionProxy.read(TestModel.TEST_PATH);
1178
1179                 transactionProxy.read(TestModel.TEST_PATH);
1180             }
1181         }, false);
1182     }
1183
1184
1185     @Test
1186     public void testReadCompletion(){
1187         completeOperation(new TransactionProxyOperation() {
1188             @Override
1189             public void run(TransactionProxy transactionProxy) {
1190                 NormalizedNode<?, ?> nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1191
1192                 doReturn(readDataReply(nodeToRead)).when(mockActorContext).executeOperationAsync(
1193                         any(ActorSelection.class), eqReadData());
1194
1195                 transactionProxy.read(TestModel.TEST_PATH);
1196
1197                 transactionProxy.read(TestModel.TEST_PATH);
1198             }
1199         });
1200
1201     }
1202
1203     @Test
1204     public void testReadCompletionForLocalShard(){
1205         final NormalizedNode nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1206         completeOperationLocal(new TransactionProxyOperation() {
1207             @Override
1208             public void run(TransactionProxy transactionProxy) {
1209                 transactionProxy.read(TestModel.TEST_PATH);
1210
1211                 transactionProxy.read(TestModel.TEST_PATH);
1212             }
1213         }, createDataTree(nodeToRead));
1214
1215     }
1216
1217     @Test
1218     public void testReadCompletionForLocalShardWhenExceptionOccurs(){
1219         completeOperationLocal(new TransactionProxyOperation() {
1220             @Override
1221             public void run(TransactionProxy transactionProxy) {
1222                 transactionProxy.read(TestModel.TEST_PATH);
1223
1224                 transactionProxy.read(TestModel.TEST_PATH);
1225             }
1226         }, createDataTree());
1227
1228     }
1229
1230     @Test
1231     public void testExistsThrottlingWhenShardFound(){
1232
1233         throttleOperation(new TransactionProxyOperation() {
1234             @Override
1235             public void run(TransactionProxy transactionProxy) {
1236                 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1237                         any(ActorSelection.class), eqDataExists());
1238
1239                 transactionProxy.exists(TestModel.TEST_PATH);
1240
1241                 transactionProxy.exists(TestModel.TEST_PATH);
1242             }
1243         });
1244     }
1245
1246     @Test
1247     public void testExistsThrottlingWhenShardNotFound(){
1248
1249         completeOperation(new TransactionProxyOperation() {
1250             @Override
1251             public void run(TransactionProxy transactionProxy) {
1252                 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1253                         any(ActorSelection.class), eqDataExists());
1254
1255                 transactionProxy.exists(TestModel.TEST_PATH);
1256
1257                 transactionProxy.exists(TestModel.TEST_PATH);
1258             }
1259         }, false);
1260     }
1261
1262
1263     @Test
1264     public void testExistsCompletion(){
1265         completeOperation(new TransactionProxyOperation() {
1266             @Override
1267             public void run(TransactionProxy transactionProxy) {
1268                 doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync(
1269                         any(ActorSelection.class), eqDataExists());
1270
1271                 transactionProxy.exists(TestModel.TEST_PATH);
1272
1273                 transactionProxy.exists(TestModel.TEST_PATH);
1274             }
1275         });
1276
1277     }
1278
1279     @Test
1280     public void testExistsCompletionForLocalShard(){
1281         final NormalizedNode nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1282         completeOperationLocal(new TransactionProxyOperation() {
1283             @Override
1284             public void run(TransactionProxy transactionProxy) {
1285                 transactionProxy.exists(TestModel.TEST_PATH);
1286
1287                 transactionProxy.exists(TestModel.TEST_PATH);
1288             }
1289         }, createDataTree(nodeToRead));
1290
1291     }
1292
1293     @Test
1294     public void testExistsCompletionForLocalShardWhenExceptionOccurs(){
1295         completeOperationLocal(new TransactionProxyOperation() {
1296             @Override
1297             public void run(TransactionProxy transactionProxy) {
1298                 transactionProxy.exists(TestModel.TEST_PATH);
1299
1300                 transactionProxy.exists(TestModel.TEST_PATH);
1301             }
1302         }, createDataTree());
1303
1304     }
1305     @Test
1306     public void testReadyThrottling(){
1307
1308         throttleOperation(new TransactionProxyOperation() {
1309             @Override
1310             public void run(TransactionProxy transactionProxy) {
1311                 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1312
1313                 expectBatchedModifications(1);
1314
1315                 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1316                         any(ActorSelection.class), any(ReadyTransaction.class));
1317
1318                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1319
1320                 transactionProxy.ready();
1321             }
1322         });
1323     }
1324
1325     @Test
1326     public void testReadyThrottlingWithTwoTransactionContexts(){
1327
1328         throttleOperation(new TransactionProxyOperation() {
1329             @Override
1330             public void run(TransactionProxy transactionProxy) {
1331                 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1332                 NormalizedNode<?, ?> carsNode = ImmutableNodes.containerNode(CarsModel.BASE_QNAME);
1333
1334                 expectBatchedModifications(2);
1335
1336                 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1337                         any(ActorSelection.class), any(ReadyTransaction.class));
1338
1339                 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1340
1341                 transactionProxy.write(TestModel.TEST_PATH, carsNode);
1342
1343                 transactionProxy.ready();
1344             }
1345         }, 2, true);
1346     }
1347
1348     private void testModificationOperationBatching(TransactionType type) throws Exception {
1349         int shardBatchedModificationCount = 3;
1350         dataStoreContextBuilder.shardBatchedModificationCount(shardBatchedModificationCount);
1351
1352         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), type);
1353
1354         expectBatchedModifications(actorRef, shardBatchedModificationCount);
1355
1356         YangInstanceIdentifier writePath1 = TestModel.TEST_PATH;
1357         NormalizedNode<?, ?> writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1358
1359         YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH;
1360         NormalizedNode<?, ?> writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
1361
1362         YangInstanceIdentifier writePath3 = TestModel.INNER_LIST_PATH;
1363         NormalizedNode<?, ?> writeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
1364
1365         YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH;
1366         NormalizedNode<?, ?> mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1367
1368         YangInstanceIdentifier mergePath2 = TestModel.OUTER_LIST_PATH;
1369         NormalizedNode<?, ?> mergeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
1370
1371         YangInstanceIdentifier mergePath3 = TestModel.INNER_LIST_PATH;
1372         NormalizedNode<?, ?> mergeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
1373
1374         YangInstanceIdentifier deletePath1 = TestModel.TEST_PATH;
1375         YangInstanceIdentifier deletePath2 = TestModel.OUTER_LIST_PATH;
1376
1377         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, type);
1378
1379         transactionProxy.write(writePath1, writeNode1);
1380         transactionProxy.write(writePath2, writeNode2);
1381         transactionProxy.delete(deletePath1);
1382         transactionProxy.merge(mergePath1, mergeNode1);
1383         transactionProxy.merge(mergePath2, mergeNode2);
1384         transactionProxy.write(writePath3, writeNode3);
1385         transactionProxy.merge(mergePath3, mergeNode3);
1386         transactionProxy.delete(deletePath2);
1387
1388         // This sends the last batch.
1389         transactionProxy.ready();
1390
1391         List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
1392         assertEquals("Captured BatchedModifications count", 3, batchedModifications.size());
1393
1394         verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(writePath1, writeNode1),
1395                 new WriteModification(writePath2, writeNode2), new DeleteModification(deletePath1));
1396
1397         verifyBatchedModifications(batchedModifications.get(1), false, new MergeModification(mergePath1, mergeNode1),
1398                 new MergeModification(mergePath2, mergeNode2), new WriteModification(writePath3, writeNode3));
1399
1400         verifyBatchedModifications(batchedModifications.get(2), true, true,
1401                 new MergeModification(mergePath3, mergeNode3), new DeleteModification(deletePath2));
1402
1403         assertEquals("getTotalMessageCount", 3, batchedModifications.get(2).getTotalMessagesSent());
1404     }
1405
1406     @Test
1407     public void testReadWriteModificationOperationBatching() throws Throwable {
1408         testModificationOperationBatching(READ_WRITE);
1409     }
1410
1411     @Test
1412     public void testWriteOnlyModificationOperationBatching() throws Throwable {
1413         testModificationOperationBatching(WRITE_ONLY);
1414     }
1415
1416     @Test
1417     public void testOptimizedWriteOnlyModificationOperationBatching() throws Throwable {
1418         dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
1419         testModificationOperationBatching(WRITE_ONLY);
1420     }
1421
1422     @Test
1423     public void testModificationOperationBatchingWithInterleavedReads() throws Throwable {
1424
1425         int shardBatchedModificationCount = 10;
1426         dataStoreContextBuilder.shardBatchedModificationCount(shardBatchedModificationCount);
1427
1428         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
1429
1430         expectBatchedModifications(actorRef, shardBatchedModificationCount);
1431
1432         YangInstanceIdentifier writePath1 = TestModel.TEST_PATH;
1433         NormalizedNode<?, ?> writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1434
1435         YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH;
1436         NormalizedNode<?, ?> writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
1437
1438         YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH;
1439         NormalizedNode<?, ?> mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1440
1441         YangInstanceIdentifier mergePath2 = TestModel.INNER_LIST_PATH;
1442         NormalizedNode<?, ?> mergeNode2 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
1443
1444         YangInstanceIdentifier deletePath = TestModel.OUTER_LIST_PATH;
1445
1446         doReturn(readSerializedDataReply(writeNode2)).when(mockActorContext).executeOperationAsync(
1447                 eq(actorSelection(actorRef)), eqSerializedReadData(writePath2));
1448
1449         doReturn(readSerializedDataReply(mergeNode2)).when(mockActorContext).executeOperationAsync(
1450                 eq(actorSelection(actorRef)), eqSerializedReadData(mergePath2));
1451
1452         doReturn(dataExistsSerializedReply(true)).when(mockActorContext).executeOperationAsync(
1453                 eq(actorSelection(actorRef)), eqSerializedDataExists());
1454
1455         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
1456
1457         transactionProxy.write(writePath1, writeNode1);
1458         transactionProxy.write(writePath2, writeNode2);
1459
1460         Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(writePath2).
1461                 get(5, TimeUnit.SECONDS);
1462
1463         assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
1464         assertEquals("Response NormalizedNode", writeNode2, readOptional.get());
1465
1466         transactionProxy.merge(mergePath1, mergeNode1);
1467         transactionProxy.merge(mergePath2, mergeNode2);
1468
1469         readOptional = transactionProxy.read(mergePath2).get(5, TimeUnit.SECONDS);
1470
1471         transactionProxy.delete(deletePath);
1472
1473         Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
1474         assertEquals("Exists response", true, exists);
1475
1476         assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
1477         assertEquals("Response NormalizedNode", mergeNode2, readOptional.get());
1478
1479         List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
1480         assertEquals("Captured BatchedModifications count", 3, batchedModifications.size());
1481
1482         verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(writePath1, writeNode1),
1483                 new WriteModification(writePath2, writeNode2));
1484
1485         verifyBatchedModifications(batchedModifications.get(1), false, new MergeModification(mergePath1, mergeNode1),
1486                 new MergeModification(mergePath2, mergeNode2));
1487
1488         verifyBatchedModifications(batchedModifications.get(2), false, new DeleteModification(deletePath));
1489
1490         InOrder inOrder = Mockito.inOrder(mockActorContext);
1491         inOrder.verify(mockActorContext).executeOperationAsync(
1492                 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
1493
1494         inOrder.verify(mockActorContext).executeOperationAsync(
1495                 eq(actorSelection(actorRef)), eqSerializedReadData(writePath2));
1496
1497         inOrder.verify(mockActorContext).executeOperationAsync(
1498                 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
1499
1500         inOrder.verify(mockActorContext).executeOperationAsync(
1501                 eq(actorSelection(actorRef)), eqSerializedReadData(mergePath2));
1502
1503         inOrder.verify(mockActorContext).executeOperationAsync(
1504                 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
1505
1506         inOrder.verify(mockActorContext).executeOperationAsync(
1507                 eq(actorSelection(actorRef)), eqSerializedDataExists());
1508     }
1509
1510     @Test
1511     public void testReadRoot() throws ReadFailedException, InterruptedException, ExecutionException, java.util.concurrent.TimeoutException {
1512
1513         SchemaContext schemaContext = SchemaContextHelper.full();
1514         Configuration configuration = mock(Configuration.class);
1515         doReturn(configuration).when(mockActorContext).getConfiguration();
1516         doReturn(schemaContext).when(mockActorContext).getSchemaContext();
1517         doReturn(Sets.newHashSet("test", "cars")).when(configuration).getAllShardNames();
1518
1519         NormalizedNode<?, ?> expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1520         NormalizedNode<?, ?> expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
1521
1522         setUpReadData("test", NormalizedNodeAggregatorTest.getRootNode(expectedNode1, schemaContext));
1523         setUpReadData("cars", NormalizedNodeAggregatorTest.getRootNode(expectedNode2, schemaContext));
1524
1525         doReturn(memberName).when(mockActorContext).getCurrentMemberName();
1526
1527         doReturn(10).when(mockActorContext).getTransactionOutstandingOperationLimit();
1528
1529         doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(mockActorContext).getClientDispatcher();
1530
1531         TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
1532
1533         Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(
1534                 YangInstanceIdentifier.builder().build()).get(5, TimeUnit.SECONDS);
1535
1536         assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
1537
1538         NormalizedNode<?, ?> normalizedNode = readOptional.get();
1539
1540         assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection);
1541
1542         Collection<NormalizedNode<?,?>> collection = (Collection<NormalizedNode<?,?>>) normalizedNode.getValue();
1543
1544         for(NormalizedNode<?,?> node : collection){
1545             assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode);
1546         }
1547
1548         assertTrue("Child with QName = " + TestModel.TEST_QNAME + " not found",
1549                 NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME) != null);
1550
1551         assertEquals(expectedNode1, NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME));
1552
1553         assertTrue("Child with QName = " + CarsModel.BASE_QNAME + " not found",
1554                 NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME) != null);
1555
1556         assertEquals(expectedNode2, NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME));
1557     }
1558
1559
1560     private void setUpReadData(String shardName, NormalizedNode<?, ?> expectedNode) {
1561         ActorSystem actorSystem = getSystem();
1562         ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
1563
1564         doReturn(getSystem().actorSelection(shardActorRef.path())).
1565                 when(mockActorContext).actorSelection(shardActorRef.path().toString());
1566
1567         doReturn(primaryShardInfoReply(getSystem(), shardActorRef)).
1568                 when(mockActorContext).findPrimaryShardAsync(eq(shardName));
1569
1570         doReturn(true).when(mockActorContext).isPathLocal(shardActorRef.path().toString());
1571
1572         ActorRef txActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
1573
1574         doReturn(actorSystem.actorSelection(txActorRef.path())).
1575                 when(mockActorContext).actorSelection(txActorRef.path().toString());
1576
1577         doReturn(Futures.successful(createTransactionReply(txActorRef, DataStoreVersions.CURRENT_VERSION))).when(mockActorContext).
1578                 executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())),
1579                         eqCreateTransaction(memberName, TransactionType.READ_ONLY));
1580
1581         doReturn(readSerializedDataReply(expectedNode)).when(mockActorContext).executeOperationAsync(
1582                 eq(actorSelection(txActorRef)), eqSerializedReadData(YangInstanceIdentifier.builder().build()));
1583     }
1584 }