1 package org.opendaylight.controller.cluster.datastore;
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.junit.Assert.fail;
7 import static org.mockito.Matchers.any;
8 import static org.mockito.Matchers.anyString;
9 import static org.mockito.Matchers.argThat;
10 import static org.mockito.Matchers.eq;
11 import static org.mockito.Matchers.isA;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16 import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.READ_ONLY;
17 import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.READ_WRITE;
18 import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.WRITE_ONLY;
19 import akka.actor.ActorRef;
20 import akka.actor.ActorSelection;
21 import akka.actor.ActorSystem;
22 import akka.actor.Props;
23 import akka.dispatch.Futures;
24 import akka.testkit.JavaTestKit;
25 import com.google.common.base.Optional;
26 import com.google.common.collect.ImmutableMap;
27 import com.google.common.util.concurrent.CheckedFuture;
28 import com.google.common.util.concurrent.FutureCallback;
29 import com.google.common.util.concurrent.Uninterruptibles;
30 import com.typesafe.config.Config;
31 import com.typesafe.config.ConfigFactory;
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.concurrent.CountDownLatch;
36 import java.util.concurrent.TimeUnit;
37 import java.util.concurrent.atomic.AtomicReference;
38 import org.junit.AfterClass;
39 import org.junit.Assert;
40 import org.junit.Before;
41 import org.junit.BeforeClass;
42 import org.junit.Test;
43 import org.mockito.ArgumentCaptor;
44 import org.mockito.ArgumentMatcher;
45 import org.mockito.InOrder;
46 import org.mockito.Mock;
47 import org.mockito.Mockito;
48 import org.mockito.MockitoAnnotations;
49 import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder;
50 import org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType;
51 import org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException;
52 import org.opendaylight.controller.cluster.datastore.exceptions.TimeoutException;
53 import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
54 import org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply;
55 import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction;
56 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
57 import org.opendaylight.controller.cluster.datastore.messages.DataExists;
58 import org.opendaylight.controller.cluster.datastore.messages.DataExistsReply;
59 import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
60 import org.opendaylight.controller.cluster.datastore.messages.DeleteDataReply;
61 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
62 import org.opendaylight.controller.cluster.datastore.messages.MergeDataReply;
63 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
64 import org.opendaylight.controller.cluster.datastore.messages.ReadDataReply;
65 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
66 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply;
67 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
68 import org.opendaylight.controller.cluster.datastore.messages.WriteDataReply;
69 import org.opendaylight.controller.cluster.datastore.modification.AbstractModification;
70 import org.opendaylight.controller.cluster.datastore.modification.DeleteModification;
71 import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
72 import org.opendaylight.controller.cluster.datastore.modification.Modification;
73 import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
74 import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy;
75 import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory;
76 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
77 import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor;
78 import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration;
79 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
80 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
81 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
82 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
83 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages.CreateTransactionReply;
84 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
85 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
86 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
87 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
88 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
89 import scala.concurrent.Await;
90 import scala.concurrent.Future;
91 import scala.concurrent.Promise;
92 import scala.concurrent.duration.Duration;
94 @SuppressWarnings("resource")
95 public class TransactionProxyTest {
97 @SuppressWarnings("serial")
98 static class TestException extends RuntimeException {
101 static interface Invoker {
102 CheckedFuture<?, ReadFailedException> invoke(TransactionProxy proxy) throws Exception;
105 private static ActorSystem system;
107 private final Configuration configuration = new MockConfiguration();
110 private ActorContext mockActorContext;
112 private SchemaContext schemaContext;
115 private ClusterWrapper mockClusterWrapper;
117 private final String memberName = "mock-member";
119 private final Builder dataStoreContextBuilder = DatastoreContext.newBuilder().operationTimeoutInSeconds(2).
120 shardBatchedModificationCount(1);
123 public static void setUpClass() throws IOException {
125 Config config = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder().
126 put("akka.actor.default-dispatcher.type",
127 "akka.testkit.CallingThreadDispatcherConfigurator").build()).
128 withFallback(ConfigFactory.load());
129 system = ActorSystem.create("test", config);
133 public static void tearDownClass() throws IOException {
134 JavaTestKit.shutdownActorSystem(system);
140 MockitoAnnotations.initMocks(this);
142 schemaContext = TestModel.createTestContext();
144 doReturn(getSystem()).when(mockActorContext).getActorSystem();
145 doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(mockActorContext).getClientDispatcher();
146 doReturn(memberName).when(mockActorContext).getCurrentMemberName();
147 doReturn(schemaContext).when(mockActorContext).getSchemaContext();
148 doReturn(mockClusterWrapper).when(mockActorContext).getClusterWrapper();
149 doReturn(mockClusterWrapper).when(mockActorContext).getClusterWrapper();
150 doReturn(dataStoreContextBuilder.build()).when(mockActorContext).getDatastoreContext();
151 doReturn(10).when(mockActorContext).getTransactionOutstandingOperationLimit();
153 ShardStrategyFactory.setConfiguration(configuration);
156 private ActorSystem getSystem() {
160 private CreateTransaction eqCreateTransaction(final String memberName,
161 final TransactionType type) {
162 ArgumentMatcher<CreateTransaction> matcher = new ArgumentMatcher<CreateTransaction>() {
164 public boolean matches(Object argument) {
165 if(CreateTransaction.SERIALIZABLE_CLASS.equals(argument.getClass())) {
166 CreateTransaction obj = CreateTransaction.fromSerializable(argument);
167 return obj.getTransactionId().startsWith(memberName) &&
168 obj.getTransactionType() == type.ordinal();
175 return argThat(matcher);
178 private DataExists eqSerializedDataExists() {
179 ArgumentMatcher<DataExists> matcher = new ArgumentMatcher<DataExists>() {
181 public boolean matches(Object argument) {
182 return DataExists.SERIALIZABLE_CLASS.equals(argument.getClass()) &&
183 DataExists.fromSerializable(argument).getPath().equals(TestModel.TEST_PATH);
187 return argThat(matcher);
190 private DataExists eqDataExists() {
191 ArgumentMatcher<DataExists> matcher = new ArgumentMatcher<DataExists>() {
193 public boolean matches(Object argument) {
194 return (argument instanceof DataExists) &&
195 ((DataExists)argument).getPath().equals(TestModel.TEST_PATH);
199 return argThat(matcher);
202 private ReadData eqSerializedReadData() {
203 return eqSerializedReadData(TestModel.TEST_PATH);
206 private ReadData eqSerializedReadData(final YangInstanceIdentifier path) {
207 ArgumentMatcher<ReadData> matcher = new ArgumentMatcher<ReadData>() {
209 public boolean matches(Object argument) {
210 return ReadData.SERIALIZABLE_CLASS.equals(argument.getClass()) &&
211 ReadData.fromSerializable(argument).getPath().equals(path);
215 return argThat(matcher);
218 private ReadData eqReadData() {
219 ArgumentMatcher<ReadData> matcher = new ArgumentMatcher<ReadData>() {
221 public boolean matches(Object argument) {
222 return (argument instanceof ReadData) &&
223 ((ReadData)argument).getPath().equals(TestModel.TEST_PATH);
227 return argThat(matcher);
230 private WriteData eqLegacyWriteData(final NormalizedNode<?, ?> nodeToWrite) {
231 ArgumentMatcher<WriteData> matcher = new ArgumentMatcher<WriteData>() {
233 public boolean matches(Object argument) {
234 if(ShardTransactionMessages.WriteData.class.equals(argument.getClass())) {
235 WriteData obj = WriteData.fromSerializable(argument);
236 return obj.getPath().equals(TestModel.TEST_PATH) && obj.getData().equals(nodeToWrite);
243 return argThat(matcher);
246 private MergeData eqLegacyMergeData(final NormalizedNode<?, ?> nodeToWrite) {
247 ArgumentMatcher<MergeData> matcher = new ArgumentMatcher<MergeData>() {
249 public boolean matches(Object argument) {
250 if(ShardTransactionMessages.MergeData.class.equals(argument.getClass())) {
251 MergeData obj = MergeData.fromSerializable(argument);
252 return obj.getPath().equals(TestModel.TEST_PATH) && obj.getData().equals(nodeToWrite);
259 return argThat(matcher);
262 private DeleteData eqLegacyDeleteData(final YangInstanceIdentifier expPath) {
263 ArgumentMatcher<DeleteData> matcher = new ArgumentMatcher<DeleteData>() {
265 public boolean matches(Object argument) {
266 return ShardTransactionMessages.DeleteData.class.equals(argument.getClass()) &&
267 DeleteData.fromSerializable(argument).getPath().equals(expPath);
271 return argThat(matcher);
274 private Future<Object> readySerializedTxReply(String path) {
275 return Futures.successful((Object)new ReadyTransactionReply(path).toSerializable());
278 private Future<Object> readyTxReply(String path) {
279 return Futures.successful((Object)new ReadyTransactionReply(path));
282 private Future<Object> readSerializedDataReply(NormalizedNode<?, ?> data,
283 short transactionVersion) {
284 return Futures.successful(new ReadDataReply(data, transactionVersion).toSerializable());
287 private Future<Object> readSerializedDataReply(NormalizedNode<?, ?> data) {
288 return readSerializedDataReply(data, DataStoreVersions.CURRENT_VERSION);
291 private Future<ReadDataReply> readDataReply(NormalizedNode<?, ?> data) {
292 return Futures.successful(new ReadDataReply(data, DataStoreVersions.CURRENT_VERSION));
295 private Future<Object> dataExistsSerializedReply(boolean exists) {
296 return Futures.successful(new DataExistsReply(exists).toSerializable());
299 private Future<DataExistsReply> dataExistsReply(boolean exists) {
300 return Futures.successful(new DataExistsReply(exists));
303 private Future<BatchedModificationsReply> batchedModificationsReply(int count) {
304 return Futures.successful(new BatchedModificationsReply(count));
307 private Future<Object> incompleteFuture(){
308 return mock(Future.class);
311 private ActorSelection actorSelection(ActorRef actorRef) {
312 return getSystem().actorSelection(actorRef.path());
315 private void expectBatchedModifications(ActorRef actorRef, int count) {
316 doReturn(batchedModificationsReply(count)).when(mockActorContext).executeOperationAsync(
317 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
320 private void expectBatchedModifications(int count) {
321 doReturn(batchedModificationsReply(count)).when(mockActorContext).executeOperationAsync(
322 any(ActorSelection.class), isA(BatchedModifications.class));
325 private void expectIncompleteBatchedModifications() {
326 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
327 any(ActorSelection.class), isA(BatchedModifications.class));
330 private void expectReadyTransaction(ActorRef actorRef) {
331 doReturn(readySerializedTxReply(actorRef.path().toString())).when(mockActorContext).executeOperationAsync(
332 eq(actorSelection(actorRef)), isA(ReadyTransaction.SERIALIZABLE_CLASS));
335 private void expectFailedBatchedModifications(ActorRef actorRef) {
336 doReturn(Futures.failed(new TestException())).when(mockActorContext).executeOperationAsync(
337 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
340 private CreateTransactionReply createTransactionReply(ActorRef actorRef, int transactionVersion){
341 return CreateTransactionReply.newBuilder()
342 .setTransactionActorPath(actorRef.path().toString())
343 .setTransactionId("txn-1")
344 .setMessageVersion(transactionVersion)
348 private ActorRef setupActorContextWithoutInitialCreateTransaction(ActorSystem actorSystem) {
349 ActorRef actorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
350 doReturn(actorSystem.actorSelection(actorRef.path())).
351 when(mockActorContext).actorSelection(actorRef.path().toString());
353 doReturn(Futures.successful(actorSystem.actorSelection(actorRef.path()))).
354 when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
356 doReturn(false).when(mockActorContext).isPathLocal(actorRef.path().toString());
358 doReturn(10).when(mockActorContext).getTransactionOutstandingOperationLimit();
363 private ActorRef setupActorContextWithInitialCreateTransaction(ActorSystem actorSystem,
364 TransactionType type, int transactionVersion) {
365 ActorRef actorRef = setupActorContextWithoutInitialCreateTransaction(actorSystem);
367 doReturn(Futures.successful(createTransactionReply(actorRef, transactionVersion))).when(mockActorContext).
368 executeOperationAsync(eq(actorSystem.actorSelection(actorRef.path())),
369 eqCreateTransaction(memberName, type));
374 private ActorRef setupActorContextWithInitialCreateTransaction(ActorSystem actorSystem, TransactionType type) {
375 return setupActorContextWithInitialCreateTransaction(actorSystem, type, DataStoreVersions.CURRENT_VERSION);
379 private void propagateReadFailedExceptionCause(CheckedFuture<?, ReadFailedException> future)
383 future.checkedGet(5, TimeUnit.SECONDS);
384 fail("Expected ReadFailedException");
385 } catch(ReadFailedException e) {
391 public void testRead() throws Exception {
392 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
394 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_ONLY);
396 doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
397 eq(actorSelection(actorRef)), eqSerializedReadData());
399 Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(
400 TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
402 assertEquals("NormalizedNode isPresent", false, readOptional.isPresent());
404 NormalizedNode<?, ?> expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
406 doReturn(readSerializedDataReply(expectedNode)).when(mockActorContext).executeOperationAsync(
407 eq(actorSelection(actorRef)), eqSerializedReadData());
409 readOptional = transactionProxy.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
411 assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
413 assertEquals("Response NormalizedNode", expectedNode, readOptional.get());
416 @Test(expected = ReadFailedException.class)
417 public void testReadWithInvalidReplyMessageType() throws Exception {
418 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
420 doReturn(Futures.successful(new Object())).when(mockActorContext).
421 executeOperationAsync(eq(actorSelection(actorRef)), eqSerializedReadData());
423 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_ONLY);
425 transactionProxy.read(TestModel.TEST_PATH).checkedGet(5, TimeUnit.SECONDS);
428 @Test(expected = TestException.class)
429 public void testReadWithAsyncRemoteOperatonFailure() throws Throwable {
430 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
432 doReturn(Futures.failed(new TestException())).when(mockActorContext).
433 executeOperationAsync(eq(actorSelection(actorRef)), eqSerializedReadData());
435 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_ONLY);
437 propagateReadFailedExceptionCause(transactionProxy.read(TestModel.TEST_PATH));
440 private void testExceptionOnInitialCreateTransaction(Exception exToThrow, Invoker invoker)
442 ActorRef actorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
444 if (exToThrow instanceof PrimaryNotFoundException) {
445 doReturn(Futures.failed(exToThrow)).when(mockActorContext).findPrimaryShardAsync(anyString());
447 doReturn(Futures.successful(getSystem().actorSelection(actorRef.path()))).
448 when(mockActorContext).findPrimaryShardAsync(anyString());
451 doReturn(Futures.failed(exToThrow)).when(mockActorContext).executeOperationAsync(
452 any(ActorSelection.class), any());
454 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_ONLY);
456 propagateReadFailedExceptionCause(invoker.invoke(transactionProxy));
459 private void testReadWithExceptionOnInitialCreateTransaction(Exception exToThrow) throws Throwable {
460 testExceptionOnInitialCreateTransaction(exToThrow, new Invoker() {
462 public CheckedFuture<?, ReadFailedException> invoke(TransactionProxy proxy) throws Exception {
463 return proxy.read(TestModel.TEST_PATH);
468 @Test(expected = PrimaryNotFoundException.class)
469 public void testReadWhenAPrimaryNotFoundExceptionIsThrown() throws Throwable {
470 testReadWithExceptionOnInitialCreateTransaction(new PrimaryNotFoundException("test"));
473 @Test(expected = TimeoutException.class)
474 public void testReadWhenATimeoutExceptionIsThrown() throws Throwable {
475 testReadWithExceptionOnInitialCreateTransaction(new TimeoutException("test",
476 new Exception("reason")));
479 @Test(expected = TestException.class)
480 public void testReadWhenAnyOtherExceptionIsThrown() throws Throwable {
481 testReadWithExceptionOnInitialCreateTransaction(new TestException());
484 @Test(expected = TestException.class)
485 public void testReadWithPriorRecordingOperationFailure() throws Throwable {
486 doReturn(dataStoreContextBuilder.shardBatchedModificationCount(2).build()).
487 when(mockActorContext).getDatastoreContext();
489 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
491 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
493 expectFailedBatchedModifications(actorRef);
495 doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
496 eq(actorSelection(actorRef)), eqSerializedReadData());
498 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
500 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
502 transactionProxy.delete(TestModel.TEST_PATH);
505 propagateReadFailedExceptionCause(transactionProxy.read(TestModel.TEST_PATH));
507 verify(mockActorContext, times(0)).executeOperationAsync(
508 eq(actorSelection(actorRef)), eqSerializedReadData());
513 public void testReadWithPriorRecordingOperationSuccessful() throws Throwable {
514 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
516 NormalizedNode<?, ?> expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
518 expectBatchedModifications(actorRef, 1);
520 doReturn(readSerializedDataReply(expectedNode)).when(mockActorContext).executeOperationAsync(
521 eq(actorSelection(actorRef)), eqSerializedReadData());
523 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
525 transactionProxy.write(TestModel.TEST_PATH, expectedNode);
527 Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(
528 TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
530 assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
531 assertEquals("Response NormalizedNode", expectedNode, readOptional.get());
533 InOrder inOrder = Mockito.inOrder(mockActorContext);
534 inOrder.verify(mockActorContext).executeOperationAsync(
535 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
537 inOrder.verify(mockActorContext).executeOperationAsync(
538 eq(actorSelection(actorRef)), eqSerializedReadData());
541 @Test(expected=IllegalStateException.class)
542 public void testReadPreConditionCheck() {
543 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
544 transactionProxy.read(TestModel.TEST_PATH);
547 @Test(expected=IllegalArgumentException.class)
548 public void testInvalidCreateTransactionReply() throws Throwable {
549 ActorRef actorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
551 doReturn(getSystem().actorSelection(actorRef.path())).when(mockActorContext).
552 actorSelection(actorRef.path().toString());
554 doReturn(Futures.successful(getSystem().actorSelection(actorRef.path()))).
555 when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
557 doReturn(Futures.successful(new Object())).when(mockActorContext).executeOperationAsync(
558 eq(getSystem().actorSelection(actorRef.path())), eqCreateTransaction(memberName, READ_ONLY));
560 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_ONLY);
562 propagateReadFailedExceptionCause(transactionProxy.read(TestModel.TEST_PATH));
566 public void testExists() throws Exception {
567 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
569 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_ONLY);
571 doReturn(dataExistsSerializedReply(false)).when(mockActorContext).executeOperationAsync(
572 eq(actorSelection(actorRef)), eqSerializedDataExists());
574 Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
576 assertEquals("Exists response", false, exists);
578 doReturn(dataExistsSerializedReply(true)).when(mockActorContext).executeOperationAsync(
579 eq(actorSelection(actorRef)), eqSerializedDataExists());
581 exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
583 assertEquals("Exists response", true, exists);
586 @Test(expected = PrimaryNotFoundException.class)
587 public void testExistsWhenAPrimaryNotFoundExceptionIsThrown() throws Throwable {
588 testExceptionOnInitialCreateTransaction(new PrimaryNotFoundException("test"), new Invoker() {
590 public CheckedFuture<?, ReadFailedException> invoke(TransactionProxy proxy) throws Exception {
591 return proxy.exists(TestModel.TEST_PATH);
596 @Test(expected = ReadFailedException.class)
597 public void testExistsWithInvalidReplyMessageType() throws Exception {
598 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
600 doReturn(Futures.successful(new Object())).when(mockActorContext).
601 executeOperationAsync(eq(actorSelection(actorRef)), eqSerializedDataExists());
603 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext,
606 transactionProxy.exists(TestModel.TEST_PATH).checkedGet(5, TimeUnit.SECONDS);
609 @Test(expected = TestException.class)
610 public void testExistsWithAsyncRemoteOperatonFailure() throws Throwable {
611 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
613 doReturn(Futures.failed(new TestException())).when(mockActorContext).
614 executeOperationAsync(eq(actorSelection(actorRef)), eqSerializedDataExists());
616 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_ONLY);
618 propagateReadFailedExceptionCause(transactionProxy.exists(TestModel.TEST_PATH));
621 @Test(expected = TestException.class)
622 public void testExistsWithPriorRecordingOperationFailure() throws Throwable {
623 doReturn(dataStoreContextBuilder.shardBatchedModificationCount(2).build()).
624 when(mockActorContext).getDatastoreContext();
626 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
628 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
630 expectFailedBatchedModifications(actorRef);
632 doReturn(dataExistsSerializedReply(false)).when(mockActorContext).executeOperationAsync(
633 eq(actorSelection(actorRef)), eqSerializedDataExists());
635 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext,
638 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
640 transactionProxy.delete(TestModel.TEST_PATH);
643 propagateReadFailedExceptionCause(transactionProxy.exists(TestModel.TEST_PATH));
645 verify(mockActorContext, times(0)).executeOperationAsync(
646 eq(actorSelection(actorRef)), eqSerializedDataExists());
651 public void testExistsWithPriorRecordingOperationSuccessful() throws Throwable {
652 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
654 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
656 expectBatchedModifications(actorRef, 1);
658 doReturn(dataExistsSerializedReply(true)).when(mockActorContext).executeOperationAsync(
659 eq(actorSelection(actorRef)), eqSerializedDataExists());
661 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
663 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
665 Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
667 assertEquals("Exists response", true, exists);
669 InOrder inOrder = Mockito.inOrder(mockActorContext);
670 inOrder.verify(mockActorContext).executeOperationAsync(
671 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
673 inOrder.verify(mockActorContext).executeOperationAsync(
674 eq(actorSelection(actorRef)), eqSerializedDataExists());
677 @Test(expected=IllegalStateException.class)
678 public void testExistsPreConditionCheck() {
679 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
680 transactionProxy.exists(TestModel.TEST_PATH);
683 private void verifyRecordingOperationFutures(List<Future<Object>> futures,
684 Class<?>... expResultTypes) throws Exception {
685 assertEquals("getRecordingOperationFutures size", expResultTypes.length, futures.size());
688 for( Future<Object> future: futures) {
689 assertNotNull("Recording operation Future is null", future);
691 Class<?> expResultType = expResultTypes[i++];
692 if(Throwable.class.isAssignableFrom(expResultType)) {
694 Await.result(future, Duration.create(5, TimeUnit.SECONDS));
695 fail("Expected exception from recording operation Future");
696 } catch(Exception e) {
700 assertEquals(String.format("Recording operation %d Future result type", i +1 ), expResultType,
701 Await.result(future, Duration.create(5, TimeUnit.SECONDS)).getClass());
707 public void testWrite() throws Exception {
708 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
710 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
712 expectBatchedModifications(actorRef, 1);
713 expectReadyTransaction(actorRef);
715 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
717 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
719 // This sends the batched modification.
720 transactionProxy.ready();
722 verifyOneBatchedModification(actorRef, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
724 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
725 BatchedModificationsReply.class);
729 public void testWriteAfterAsyncRead() throws Throwable {
730 ActorRef actorRef = setupActorContextWithoutInitialCreateTransaction(getSystem());
732 Promise<Object> createTxPromise = akka.dispatch.Futures.promise();
733 doReturn(createTxPromise).when(mockActorContext).executeOperationAsync(
734 eq(getSystem().actorSelection(actorRef.path())),
735 eqCreateTransaction(memberName, READ_WRITE));
737 doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
738 eq(actorSelection(actorRef)), eqSerializedReadData());
740 expectBatchedModifications(actorRef, 1);
741 expectReadyTransaction(actorRef);
743 final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
745 final TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
747 final CountDownLatch readComplete = new CountDownLatch(1);
748 final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
749 com.google.common.util.concurrent.Futures.addCallback(transactionProxy.read(TestModel.TEST_PATH),
750 new FutureCallback<Optional<NormalizedNode<?, ?>>>() {
752 public void onSuccess(Optional<NormalizedNode<?, ?>> result) {
754 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
755 } catch (Exception e) {
758 readComplete.countDown();
763 public void onFailure(Throwable t) {
765 readComplete.countDown();
769 createTxPromise.success(createTransactionReply(actorRef, DataStoreVersions.CURRENT_VERSION));
771 Uninterruptibles.awaitUninterruptibly(readComplete, 5, TimeUnit.SECONDS);
773 if(caughtEx.get() != null) {
774 throw caughtEx.get();
777 // This sends the batched modification.
778 transactionProxy.ready();
780 verifyOneBatchedModification(actorRef, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
782 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
783 BatchedModificationsReply.class);
786 @Test(expected=IllegalStateException.class)
787 public void testWritePreConditionCheck() {
788 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_ONLY);
789 transactionProxy.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
792 @Test(expected=IllegalStateException.class)
793 public void testWriteAfterReadyPreConditionCheck() {
794 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
796 transactionProxy.ready();
798 transactionProxy.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
802 public void testMerge() throws Exception {
803 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
805 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
807 expectBatchedModifications(actorRef, 1);
808 expectReadyTransaction(actorRef);
810 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
812 transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
814 // This sends the batched modification.
815 transactionProxy.ready();
817 verifyOneBatchedModification(actorRef, new MergeModification(TestModel.TEST_PATH, nodeToWrite));
819 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
820 BatchedModificationsReply.class);
824 public void testDelete() throws Exception {
825 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
827 expectBatchedModifications(actorRef, 1);
828 expectReadyTransaction(actorRef);
830 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
832 transactionProxy.delete(TestModel.TEST_PATH);
834 // This sends the batched modification.
835 transactionProxy.ready();
837 verifyOneBatchedModification(actorRef, new DeleteModification(TestModel.TEST_PATH));
839 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
840 BatchedModificationsReply.class);
843 private void verifyCohortFutures(ThreePhaseCommitCohortProxy proxy,
844 Object... expReplies) throws Exception {
845 assertEquals("getReadyOperationFutures size", expReplies.length,
846 proxy.getCohortFutures().size());
849 for( Future<ActorSelection> future: proxy.getCohortFutures()) {
850 assertNotNull("Ready operation Future is null", future);
852 Object expReply = expReplies[i++];
853 if(expReply instanceof ActorSelection) {
854 ActorSelection actual = Await.result(future, Duration.create(5, TimeUnit.SECONDS));
855 assertEquals("Cohort actor path", expReply, actual);
857 // Expecting exception.
859 Await.result(future, Duration.create(5, TimeUnit.SECONDS));
860 fail("Expected exception from ready operation Future");
861 } catch(Exception e) {
869 public void testReady() throws Exception {
870 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
872 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
874 doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
875 eq(actorSelection(actorRef)), eqSerializedReadData());
877 expectBatchedModifications(actorRef, 1);
878 expectReadyTransaction(actorRef);
880 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
882 transactionProxy.read(TestModel.TEST_PATH);
884 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
886 DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
888 assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
890 ThreePhaseCommitCohortProxy proxy = (ThreePhaseCommitCohortProxy) ready;
892 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
893 BatchedModificationsReply.class);
895 verifyCohortFutures(proxy, getSystem().actorSelection(actorRef.path()));
897 verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)),
898 isA(BatchedModifications.class));
901 private ActorRef testCompatibilityWithHeliumVersion(short version) throws Exception {
902 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(),
903 READ_WRITE, version);
905 NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
907 doReturn(readSerializedDataReply(testNode, version)).when(mockActorContext).executeOperationAsync(
908 eq(actorSelection(actorRef)), eqSerializedReadData());
910 doReturn(Futures.successful(new WriteDataReply().toSerializable(version))).when(mockActorContext).
911 executeOperationAsync(eq(actorSelection(actorRef)), eqLegacyWriteData(testNode));
913 doReturn(Futures.successful(new MergeDataReply().toSerializable(version))).when(mockActorContext).
914 executeOperationAsync(eq(actorSelection(actorRef)), eqLegacyMergeData(testNode));
916 doReturn(Futures.successful(new DeleteDataReply().toSerializable(version))).when(mockActorContext).
917 executeOperationAsync(eq(actorSelection(actorRef)), eqLegacyDeleteData(TestModel.TEST_PATH));
919 expectReadyTransaction(actorRef);
921 doReturn(actorRef.path().toString()).when(mockActorContext).resolvePath(eq(actorRef.path().toString()),
922 eq(actorRef.path().toString()));
924 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
926 Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(TestModel.TEST_PATH).
927 get(5, TimeUnit.SECONDS);
929 assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
930 assertEquals("Response NormalizedNode", testNode, readOptional.get());
932 transactionProxy.write(TestModel.TEST_PATH, testNode);
934 transactionProxy.merge(TestModel.TEST_PATH, testNode);
936 transactionProxy.delete(TestModel.TEST_PATH);
938 DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
940 assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
942 ThreePhaseCommitCohortProxy proxy = (ThreePhaseCommitCohortProxy) ready;
944 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
945 ShardTransactionMessages.WriteDataReply.class, ShardTransactionMessages.MergeDataReply.class,
946 ShardTransactionMessages.DeleteDataReply.class);
948 verifyCohortFutures(proxy, getSystem().actorSelection(actorRef.path()));
954 public void testCompatibilityWithBaseHeliumVersion() throws Exception {
955 ActorRef actorRef = testCompatibilityWithHeliumVersion(DataStoreVersions.BASE_HELIUM_VERSION);
957 verify(mockActorContext).resolvePath(eq(actorRef.path().toString()),
958 eq(actorRef.path().toString()));
962 public void testCompatibilityWithHeliumR1Version() throws Exception {
963 ActorRef actorRef = testCompatibilityWithHeliumVersion(DataStoreVersions.HELIUM_1_VERSION);
965 verify(mockActorContext, Mockito.never()).resolvePath(eq(actorRef.path().toString()),
966 eq(actorRef.path().toString()));
970 public void testReadyWithRecordingOperationFailure() throws Exception {
971 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
973 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
975 expectFailedBatchedModifications(actorRef);
977 expectReadyTransaction(actorRef);
979 doReturn(false).when(mockActorContext).isPathLocal(actorRef.path().toString());
981 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
983 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
985 DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
987 assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
989 ThreePhaseCommitCohortProxy proxy = (ThreePhaseCommitCohortProxy) ready;
991 verifyCohortFutures(proxy, TestException.class);
993 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(), TestException.class);
997 public void testReadyWithReplyFailure() throws Exception {
998 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
1000 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1002 expectBatchedModifications(actorRef, 1);
1004 doReturn(Futures.failed(new TestException())).when(mockActorContext).
1005 executeOperationAsync(eq(actorSelection(actorRef)),
1006 isA(ReadyTransaction.SERIALIZABLE_CLASS));
1008 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
1010 transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
1012 DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
1014 assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
1016 ThreePhaseCommitCohortProxy proxy = (ThreePhaseCommitCohortProxy) ready;
1018 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
1019 BatchedModificationsReply.class);
1021 verifyCohortFutures(proxy, TestException.class);
1025 public void testReadyWithInitialCreateTransactionFailure() throws Exception {
1027 doReturn(Futures.failed(new PrimaryNotFoundException("mock"))).when(
1028 mockActorContext).findPrimaryShardAsync(anyString());
1030 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
1032 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1034 transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
1036 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1038 transactionProxy.delete(TestModel.TEST_PATH);
1040 DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
1042 assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
1044 ThreePhaseCommitCohortProxy proxy = (ThreePhaseCommitCohortProxy) ready;
1046 verifyCohortFutures(proxy, PrimaryNotFoundException.class);
1050 public void testReadyWithInvalidReplyMessageType() throws Exception {
1051 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
1053 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1055 expectBatchedModifications(actorRef, 1);
1057 doReturn(Futures.successful(new Object())).when(mockActorContext).
1058 executeOperationAsync(eq(actorSelection(actorRef)),
1059 isA(ReadyTransaction.SERIALIZABLE_CLASS));
1061 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
1063 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1065 DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
1067 assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
1069 ThreePhaseCommitCohortProxy proxy = (ThreePhaseCommitCohortProxy) ready;
1071 verifyCohortFutures(proxy, IllegalArgumentException.class);
1075 public void testGetIdentifier() {
1076 setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
1077 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext,
1078 TransactionProxy.TransactionType.READ_ONLY);
1080 Object id = transactionProxy.getIdentifier();
1081 assertNotNull("getIdentifier returned null", id);
1082 assertTrue("Invalid identifier: " + id, id.toString().startsWith(memberName));
1086 public void testClose() throws Exception{
1087 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
1089 doReturn(readSerializedDataReply(null)).when(mockActorContext).executeOperationAsync(
1090 eq(actorSelection(actorRef)), eqSerializedReadData());
1092 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
1094 transactionProxy.read(TestModel.TEST_PATH);
1096 transactionProxy.close();
1098 verify(mockActorContext).sendOperationAsync(
1099 eq(actorSelection(actorRef)), isA(CloseTransaction.SERIALIZABLE_CLASS));
1104 * Method to test a local Tx actor. The Tx paths are matched to decide if the
1105 * Tx actor is local or not. This is done by mocking the Tx actor path
1106 * and the caller paths and ensuring that the paths have the remote-address format
1108 * Note: Since the default akka provider for test is not a RemoteActorRefProvider,
1109 * the paths returned for the actors for all the tests are not qualified remote paths.
1110 * Hence are treated as non-local/remote actors. In short, all tests except
1111 * few below run for remote actors
1116 public void testLocalTxActorRead() throws Exception {
1117 ActorSystem actorSystem = getSystem();
1118 ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
1120 doReturn(actorSystem.actorSelection(shardActorRef.path())).
1121 when(mockActorContext).actorSelection(shardActorRef.path().toString());
1123 doReturn(Futures.successful(actorSystem.actorSelection(shardActorRef.path()))).
1124 when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
1126 String actorPath = "akka.tcp://system@127.0.0.1:2550/user/tx-actor";
1127 CreateTransactionReply createTransactionReply = CreateTransactionReply.newBuilder()
1128 .setTransactionId("txn-1").setTransactionActorPath(actorPath).build();
1130 doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).
1131 executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())),
1132 eqCreateTransaction(memberName, READ_ONLY));
1134 doReturn(true).when(mockActorContext).isPathLocal(actorPath);
1136 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext,READ_ONLY);
1138 // negative test case with null as the reply
1139 doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(
1140 any(ActorSelection.class), eqReadData());
1142 Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(
1143 TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
1145 assertEquals("NormalizedNode isPresent", false, readOptional.isPresent());
1147 // test case with node as read data reply
1148 NormalizedNode<?, ?> expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1150 doReturn(readDataReply(expectedNode)).when(mockActorContext).executeOperationAsync(
1151 any(ActorSelection.class), eqReadData());
1153 readOptional = transactionProxy.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
1155 assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
1157 assertEquals("Response NormalizedNode", expectedNode, readOptional.get());
1159 // test for local data exists
1160 doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync(
1161 any(ActorSelection.class), eqDataExists());
1163 boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
1165 assertEquals("Exists response", true, exists);
1169 public void testLocalTxActorReady() throws Exception {
1170 ActorSystem actorSystem = getSystem();
1171 ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
1173 doReturn(actorSystem.actorSelection(shardActorRef.path())).
1174 when(mockActorContext).actorSelection(shardActorRef.path().toString());
1176 doReturn(Futures.successful(actorSystem.actorSelection(shardActorRef.path()))).
1177 when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
1179 String actorPath = "akka.tcp://system@127.0.0.1:2550/user/tx-actor";
1180 CreateTransactionReply createTransactionReply = CreateTransactionReply.newBuilder().
1181 setTransactionId("txn-1").setTransactionActorPath(actorPath).
1182 setMessageVersion(DataStoreVersions.CURRENT_VERSION).build();
1184 doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).
1185 executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())),
1186 eqCreateTransaction(memberName, WRITE_ONLY));
1188 doReturn(true).when(mockActorContext).isPathLocal(actorPath);
1190 doReturn(batchedModificationsReply(1)).when(mockActorContext).executeOperationAsync(
1191 any(ActorSelection.class), isA(BatchedModifications.class));
1193 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, WRITE_ONLY);
1195 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1196 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1198 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
1199 BatchedModificationsReply.class);
1202 doReturn(readyTxReply(shardActorRef.path().toString())).when(mockActorContext).executeOperationAsync(
1203 any(ActorSelection.class), isA(ReadyTransaction.class));
1205 DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
1207 assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
1209 ThreePhaseCommitCohortProxy proxy = (ThreePhaseCommitCohortProxy) ready;
1211 verifyCohortFutures(proxy, getSystem().actorSelection(shardActorRef.path()));
1214 private static interface TransactionProxyOperation {
1215 void run(TransactionProxy transactionProxy);
1218 private void throttleOperation(TransactionProxyOperation operation) {
1219 throttleOperation(operation, 1, true);
1222 private void throttleOperation(TransactionProxyOperation operation, int outstandingOpsLimit, boolean shardFound){
1223 ActorSystem actorSystem = getSystem();
1224 ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
1226 doReturn(outstandingOpsLimit).when(mockActorContext).getTransactionOutstandingOperationLimit();
1228 doReturn(actorSystem.actorSelection(shardActorRef.path())).
1229 when(mockActorContext).actorSelection(shardActorRef.path().toString());
1232 doReturn(Futures.successful(actorSystem.actorSelection(shardActorRef.path()))).
1233 when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
1235 doReturn(Futures.failed(new Exception("not found")))
1236 .when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
1239 String actorPath = "akka.tcp://system@127.0.0.1:2550/user/tx-actor";
1240 CreateTransactionReply createTransactionReply = CreateTransactionReply.newBuilder().
1241 setTransactionId("txn-1").setTransactionActorPath(actorPath).
1242 setMessageVersion(DataStoreVersions.CURRENT_VERSION).build();
1244 doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).
1245 executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())),
1246 eqCreateTransaction(memberName, READ_WRITE));
1248 doReturn(true).when(mockActorContext).isPathLocal(actorPath);
1250 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
1252 long start = System.nanoTime();
1254 operation.run(transactionProxy);
1256 long end = System.nanoTime();
1258 long expected = TimeUnit.SECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds());
1259 Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s",
1260 expected, (end-start)), (end - start) > expected);
1264 private void completeOperation(TransactionProxyOperation operation){
1265 completeOperation(operation, true);
1268 private void completeOperation(TransactionProxyOperation operation, boolean shardFound){
1269 ActorSystem actorSystem = getSystem();
1270 ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
1272 doReturn(1).when(mockActorContext).getTransactionOutstandingOperationLimit();
1274 doReturn(actorSystem.actorSelection(shardActorRef.path())).
1275 when(mockActorContext).actorSelection(shardActorRef.path().toString());
1278 doReturn(Futures.successful(actorSystem.actorSelection(shardActorRef.path()))).
1279 when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
1281 doReturn(Futures.failed(new Exception("not found")))
1282 .when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
1285 String actorPath = "akka.tcp://system@127.0.0.1:2550/user/tx-actor";
1286 CreateTransactionReply createTransactionReply = CreateTransactionReply.newBuilder().
1287 setTransactionId("txn-1").setTransactionActorPath(actorPath).
1288 setMessageVersion(DataStoreVersions.CURRENT_VERSION).build();
1290 doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).
1291 executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())),
1292 eqCreateTransaction(memberName, READ_WRITE));
1294 doReturn(true).when(mockActorContext).isPathLocal(actorPath);
1296 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
1298 long start = System.nanoTime();
1300 operation.run(transactionProxy);
1302 long end = System.nanoTime();
1304 long expected = TimeUnit.SECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds());
1305 Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s",
1306 expected, (end-start)), (end - start) <= expected);
1309 public void testWriteThrottling(boolean shardFound){
1311 throttleOperation(new TransactionProxyOperation() {
1313 public void run(TransactionProxy transactionProxy) {
1314 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1316 expectBatchedModifications(2);
1318 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1320 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1326 public void testWriteThrottlingWhenShardFound(){
1327 throttleOperation(new TransactionProxyOperation() {
1329 public void run(TransactionProxy transactionProxy) {
1330 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1332 expectIncompleteBatchedModifications();
1334 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1336 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1342 public void testWriteThrottlingWhenShardNotFound(){
1343 // Confirm that there is no throttling when the Shard is not found
1344 completeOperation(new TransactionProxyOperation() {
1346 public void run(TransactionProxy transactionProxy) {
1347 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1349 expectBatchedModifications(2);
1351 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1353 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1361 public void testWriteCompletion(){
1362 completeOperation(new TransactionProxyOperation() {
1364 public void run(TransactionProxy transactionProxy) {
1365 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1367 expectBatchedModifications(2);
1369 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1371 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1377 public void testMergeThrottlingWhenShardFound(){
1379 throttleOperation(new TransactionProxyOperation() {
1381 public void run(TransactionProxy transactionProxy) {
1382 NormalizedNode<?, ?> nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1384 expectIncompleteBatchedModifications();
1386 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1388 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1394 public void testMergeThrottlingWhenShardNotFound(){
1396 completeOperation(new TransactionProxyOperation() {
1398 public void run(TransactionProxy transactionProxy) {
1399 NormalizedNode<?, ?> nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1401 expectBatchedModifications(2);
1403 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1405 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1411 public void testMergeCompletion(){
1412 completeOperation(new TransactionProxyOperation() {
1414 public void run(TransactionProxy transactionProxy) {
1415 NormalizedNode<?, ?> nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1417 expectBatchedModifications(2);
1419 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1421 transactionProxy.merge(TestModel.TEST_PATH, nodeToMerge);
1428 public void testDeleteThrottlingWhenShardFound(){
1430 throttleOperation(new TransactionProxyOperation() {
1432 public void run(TransactionProxy transactionProxy) {
1433 expectIncompleteBatchedModifications();
1435 transactionProxy.delete(TestModel.TEST_PATH);
1437 transactionProxy.delete(TestModel.TEST_PATH);
1444 public void testDeleteThrottlingWhenShardNotFound(){
1446 completeOperation(new TransactionProxyOperation() {
1448 public void run(TransactionProxy transactionProxy) {
1449 expectBatchedModifications(2);
1451 transactionProxy.delete(TestModel.TEST_PATH);
1453 transactionProxy.delete(TestModel.TEST_PATH);
1459 public void testDeleteCompletion(){
1460 completeOperation(new TransactionProxyOperation() {
1462 public void run(TransactionProxy transactionProxy) {
1463 expectBatchedModifications(2);
1465 transactionProxy.delete(TestModel.TEST_PATH);
1467 transactionProxy.delete(TestModel.TEST_PATH);
1474 public void testReadThrottlingWhenShardFound(){
1476 throttleOperation(new TransactionProxyOperation() {
1478 public void run(TransactionProxy transactionProxy) {
1479 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1480 any(ActorSelection.class), eqReadData());
1482 transactionProxy.read(TestModel.TEST_PATH);
1484 transactionProxy.read(TestModel.TEST_PATH);
1490 public void testReadThrottlingWhenShardNotFound(){
1492 completeOperation(new TransactionProxyOperation() {
1494 public void run(TransactionProxy transactionProxy) {
1495 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1496 any(ActorSelection.class), eqReadData());
1498 transactionProxy.read(TestModel.TEST_PATH);
1500 transactionProxy.read(TestModel.TEST_PATH);
1507 public void testReadCompletion(){
1508 completeOperation(new TransactionProxyOperation() {
1510 public void run(TransactionProxy transactionProxy) {
1511 NormalizedNode<?, ?> nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1513 doReturn(readDataReply(nodeToRead)).when(mockActorContext).executeOperationAsync(
1514 any(ActorSelection.class), eqReadData());
1516 transactionProxy.read(TestModel.TEST_PATH);
1518 transactionProxy.read(TestModel.TEST_PATH);
1525 public void testExistsThrottlingWhenShardFound(){
1527 throttleOperation(new TransactionProxyOperation() {
1529 public void run(TransactionProxy transactionProxy) {
1530 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1531 any(ActorSelection.class), eqDataExists());
1533 transactionProxy.exists(TestModel.TEST_PATH);
1535 transactionProxy.exists(TestModel.TEST_PATH);
1541 public void testExistsThrottlingWhenShardNotFound(){
1543 completeOperation(new TransactionProxyOperation() {
1545 public void run(TransactionProxy transactionProxy) {
1546 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1547 any(ActorSelection.class), eqDataExists());
1549 transactionProxy.exists(TestModel.TEST_PATH);
1551 transactionProxy.exists(TestModel.TEST_PATH);
1558 public void testExistsCompletion(){
1559 completeOperation(new TransactionProxyOperation() {
1561 public void run(TransactionProxy transactionProxy) {
1562 doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync(
1563 any(ActorSelection.class), eqDataExists());
1565 transactionProxy.exists(TestModel.TEST_PATH);
1567 transactionProxy.exists(TestModel.TEST_PATH);
1574 public void testReadyThrottling(){
1576 throttleOperation(new TransactionProxyOperation() {
1578 public void run(TransactionProxy transactionProxy) {
1579 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1581 expectBatchedModifications(1);
1583 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1584 any(ActorSelection.class), any(ReadyTransaction.class));
1586 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1588 transactionProxy.ready();
1594 public void testReadyThrottlingWithTwoTransactionContexts(){
1596 throttleOperation(new TransactionProxyOperation() {
1598 public void run(TransactionProxy transactionProxy) {
1599 NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1600 NormalizedNode<?, ?> carsNode = ImmutableNodes.containerNode(CarsModel.BASE_QNAME);
1602 expectBatchedModifications(2);
1604 doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
1605 any(ActorSelection.class), any(ReadyTransaction.class));
1607 transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
1609 transactionProxy.write(TestModel.TEST_PATH, carsNode);
1611 transactionProxy.ready();
1617 public void testModificationOperationBatching() throws Throwable {
1618 int shardBatchedModificationCount = 3;
1619 doReturn(dataStoreContextBuilder.shardBatchedModificationCount(shardBatchedModificationCount).build()).
1620 when(mockActorContext).getDatastoreContext();
1622 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
1624 expectBatchedModifications(actorRef, shardBatchedModificationCount);
1626 expectReadyTransaction(actorRef);
1628 YangInstanceIdentifier writePath1 = TestModel.TEST_PATH;
1629 NormalizedNode<?, ?> writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1631 YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH;
1632 NormalizedNode<?, ?> writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
1634 YangInstanceIdentifier writePath3 = TestModel.INNER_LIST_PATH;
1635 NormalizedNode<?, ?> writeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
1637 YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH;
1638 NormalizedNode<?, ?> mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1640 YangInstanceIdentifier mergePath2 = TestModel.OUTER_LIST_PATH;
1641 NormalizedNode<?, ?> mergeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
1643 YangInstanceIdentifier mergePath3 = TestModel.INNER_LIST_PATH;
1644 NormalizedNode<?, ?> mergeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
1646 YangInstanceIdentifier deletePath1 = TestModel.TEST_PATH;
1647 YangInstanceIdentifier deletePath2 = TestModel.OUTER_LIST_PATH;
1649 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
1651 transactionProxy.write(writePath1, writeNode1);
1652 transactionProxy.write(writePath2, writeNode2);
1653 transactionProxy.delete(deletePath1);
1654 transactionProxy.merge(mergePath1, mergeNode1);
1655 transactionProxy.merge(mergePath2, mergeNode2);
1656 transactionProxy.write(writePath3, writeNode3);
1657 transactionProxy.merge(mergePath3, mergeNode3);
1658 transactionProxy.delete(deletePath2);
1660 // This sends the last batch.
1661 transactionProxy.ready();
1663 List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
1664 assertEquals("Captured BatchedModifications count", 3, batchedModifications.size());
1666 verifyBatchedModifications(batchedModifications.get(0), new WriteModification(writePath1, writeNode1),
1667 new WriteModification(writePath2, writeNode2), new DeleteModification(deletePath1));
1669 verifyBatchedModifications(batchedModifications.get(1), new MergeModification(mergePath1, mergeNode1),
1670 new MergeModification(mergePath2, mergeNode2), new WriteModification(writePath3, writeNode3));
1672 verifyBatchedModifications(batchedModifications.get(2), new MergeModification(mergePath3, mergeNode3),
1673 new DeleteModification(deletePath2));
1675 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
1676 BatchedModificationsReply.class, BatchedModificationsReply.class, BatchedModificationsReply.class);
1680 public void testModificationOperationBatchingWithInterleavedReads() throws Throwable {
1681 int shardBatchedModificationCount = 10;
1682 doReturn(dataStoreContextBuilder.shardBatchedModificationCount(shardBatchedModificationCount).build()).
1683 when(mockActorContext).getDatastoreContext();
1685 ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
1687 expectBatchedModifications(actorRef, shardBatchedModificationCount);
1689 YangInstanceIdentifier writePath1 = TestModel.TEST_PATH;
1690 NormalizedNode<?, ?> writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1692 YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH;
1693 NormalizedNode<?, ?> writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
1695 YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH;
1696 NormalizedNode<?, ?> mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
1698 YangInstanceIdentifier mergePath2 = TestModel.INNER_LIST_PATH;
1699 NormalizedNode<?, ?> mergeNode2 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
1701 YangInstanceIdentifier deletePath = TestModel.OUTER_LIST_PATH;
1703 doReturn(readSerializedDataReply(writeNode2)).when(mockActorContext).executeOperationAsync(
1704 eq(actorSelection(actorRef)), eqSerializedReadData(writePath2));
1706 doReturn(readSerializedDataReply(mergeNode2)).when(mockActorContext).executeOperationAsync(
1707 eq(actorSelection(actorRef)), eqSerializedReadData(mergePath2));
1709 doReturn(dataExistsSerializedReply(true)).when(mockActorContext).executeOperationAsync(
1710 eq(actorSelection(actorRef)), eqSerializedDataExists());
1712 TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
1714 transactionProxy.write(writePath1, writeNode1);
1715 transactionProxy.write(writePath2, writeNode2);
1717 Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(writePath2).
1718 get(5, TimeUnit.SECONDS);
1720 assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
1721 assertEquals("Response NormalizedNode", writeNode2, readOptional.get());
1723 transactionProxy.merge(mergePath1, mergeNode1);
1724 transactionProxy.merge(mergePath2, mergeNode2);
1726 readOptional = transactionProxy.read(mergePath2).get(5, TimeUnit.SECONDS);
1728 transactionProxy.delete(deletePath);
1730 Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
1731 assertEquals("Exists response", true, exists);
1733 assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
1734 assertEquals("Response NormalizedNode", mergeNode2, readOptional.get());
1736 List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
1737 assertEquals("Captured BatchedModifications count", 3, batchedModifications.size());
1739 verifyBatchedModifications(batchedModifications.get(0), new WriteModification(writePath1, writeNode1),
1740 new WriteModification(writePath2, writeNode2));
1742 verifyBatchedModifications(batchedModifications.get(1), new MergeModification(mergePath1, mergeNode1),
1743 new MergeModification(mergePath2, mergeNode2));
1745 verifyBatchedModifications(batchedModifications.get(2), new DeleteModification(deletePath));
1747 InOrder inOrder = Mockito.inOrder(mockActorContext);
1748 inOrder.verify(mockActorContext).executeOperationAsync(
1749 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
1751 inOrder.verify(mockActorContext).executeOperationAsync(
1752 eq(actorSelection(actorRef)), eqSerializedReadData(writePath2));
1754 inOrder.verify(mockActorContext).executeOperationAsync(
1755 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
1757 inOrder.verify(mockActorContext).executeOperationAsync(
1758 eq(actorSelection(actorRef)), eqSerializedReadData(mergePath2));
1760 inOrder.verify(mockActorContext).executeOperationAsync(
1761 eq(actorSelection(actorRef)), isA(BatchedModifications.class));
1763 inOrder.verify(mockActorContext).executeOperationAsync(
1764 eq(actorSelection(actorRef)), eqSerializedDataExists());
1766 verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(),
1767 BatchedModificationsReply.class, BatchedModificationsReply.class, BatchedModificationsReply.class);
1770 private List<BatchedModifications> captureBatchedModifications(ActorRef actorRef) {
1771 ArgumentCaptor<BatchedModifications> batchedModificationsCaptor =
1772 ArgumentCaptor.forClass(BatchedModifications.class);
1773 verify(mockActorContext, Mockito.atLeastOnce()).executeOperationAsync(
1774 eq(actorSelection(actorRef)), batchedModificationsCaptor.capture());
1776 List<BatchedModifications> batchedModifications = filterCaptured(
1777 batchedModificationsCaptor, BatchedModifications.class);
1778 return batchedModifications;
1781 private <T> List<T> filterCaptured(ArgumentCaptor<T> captor, Class<T> type) {
1782 List<T> captured = new ArrayList<>();
1783 for(T c: captor.getAllValues()) {
1784 if(type.isInstance(c)) {
1792 private void verifyOneBatchedModification(ActorRef actorRef, Modification expected) {
1793 List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
1794 assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
1796 verifyBatchedModifications(batchedModifications.get(0), expected);
1799 private void verifyBatchedModifications(Object message, Modification... expected) {
1800 assertEquals("Message type", BatchedModifications.class, message.getClass());
1801 BatchedModifications batchedModifications = (BatchedModifications)message;
1802 assertEquals("BatchedModifications size", expected.length, batchedModifications.getModifications().size());
1803 for(int i = 0; i < batchedModifications.getModifications().size(); i++) {
1804 Modification actual = batchedModifications.getModifications().get(i);
1805 assertEquals("Modification type", expected[i].getClass(), actual.getClass());
1806 assertEquals("getPath", ((AbstractModification)expected[i]).getPath(),
1807 ((AbstractModification)actual).getPath());
1808 if(actual instanceof WriteModification) {
1809 assertEquals("getData", ((WriteModification)expected[i]).getData(),
1810 ((WriteModification)actual).getData());