+ TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
+
+ transactionProxy.merge(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+
+ DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
+
+ assertTrue(ready instanceof DebugThreePhaseCommitCohort);
+
+ verifyCohortFutures((DebugThreePhaseCommitCohort)ready, new CommitTransactionReply().toSerializable());
+ }
+
+ @Test
+ public void testReadyWithLocalTransaction() throws Exception {
+ ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
+
+ doReturn(getSystem().actorSelection(shardActorRef.path())).when(mockActorContext)
+ .actorSelection(shardActorRef.path().toString());
+
+ doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef, createDataTree()))).when(mockActorContext)
+ .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
+
+ TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
+
+ expectReadyLocalTransaction(shardActorRef, true);
+
+ NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
+
+ DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
+ assertTrue(ready instanceof SingleCommitCohortProxy);
+ verifyCohortFutures((SingleCommitCohortProxy)ready, new CommitTransactionReply().toSerializable());
+ }
+
+ @Test
+ public void testReadyWithLocalTransactionWithFailure() throws Exception {
+ ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
+
+ doReturn(getSystem().actorSelection(shardActorRef.path())).when(mockActorContext)
+ .actorSelection(shardActorRef.path().toString());
+
+ DataTree mockDataTree = createDataTree();
+ DataTreeModification mockModification = mockDataTree.takeSnapshot().newModification();
+ doThrow(new RuntimeException("mock")).when(mockModification).ready();
+
+ doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef, mockDataTree))).when(mockActorContext)
+ .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
+
+ TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
+
+ expectReadyLocalTransaction(shardActorRef, true);
+
+ NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
+
+ DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
+ assertTrue(ready instanceof SingleCommitCohortProxy);
+ verifyCohortFutures((SingleCommitCohortProxy)ready, RuntimeException.class);