use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.
the class TransactionProxyTest method testReadyWithWriteOnlyAndLastBatchEmpty.
@Test
public void testReadyWithWriteOnlyAndLastBatchEmpty() throws Exception {
dataStoreContextBuilder.shardBatchedModificationCount(1).writeOnlyTransactionOptimizationsEnabled(true);
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
expectBatchedModificationsReady(actorRef, true);
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
assertTrue(ready instanceof SingleCommitCohortProxy);
verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
assertEquals("Captured BatchedModifications count", 2, batchedModifications.size());
verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
verifyBatchedModifications(batchedModifications.get(1), true, true);
}
use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.
the class TransactionProxyTest method testWrite.
@Test
public void testWrite() throws Exception {
dataStoreContextBuilder.shardBatchedModificationCount(1);
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
expectBatchedModifications(actorRef, 1);
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
verifyOneBatchedModification(actorRef, new WriteModification(TestModel.TEST_PATH, nodeToWrite), false);
}
use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.
the class TransactionProxyTest method testReadyWithWriteOnlyAndLastBatchPending.
@Test
public void testReadyWithWriteOnlyAndLastBatchPending() throws Exception {
dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
expectBatchedModificationsReady(actorRef, true);
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
assertTrue(ready instanceof SingleCommitCohortProxy);
verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
verifyBatchedModifications(batchedModifications.get(0), true, true, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
}
use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.
the class TransactionProxyTest method testModificationOperationBatchingWithInterleavedReads.
@Test
public void testModificationOperationBatchingWithInterleavedReads() throws Exception {
int shardBatchedModificationCount = 10;
dataStoreContextBuilder.shardBatchedModificationCount(shardBatchedModificationCount);
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
expectBatchedModifications(actorRef, shardBatchedModificationCount);
final YangInstanceIdentifier writePath1 = TestModel.TEST_PATH;
final NormalizedNode<?, ?> writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH;
NormalizedNode<?, ?> writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
final YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH;
final NormalizedNode<?, ?> mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
YangInstanceIdentifier mergePath2 = TestModel.INNER_LIST_PATH;
NormalizedNode<?, ?> mergeNode2 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
final YangInstanceIdentifier deletePath = TestModel.OUTER_LIST_PATH;
doReturn(readDataReply(writeNode2)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(writePath2), any(Timeout.class));
doReturn(readDataReply(mergeNode2)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(mergePath2), any(Timeout.class));
doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class));
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
transactionProxy.write(writePath1, writeNode1);
transactionProxy.write(writePath2, writeNode2);
Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(writePath2).get(5, TimeUnit.SECONDS);
assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
assertEquals("Response NormalizedNode", writeNode2, readOptional.get());
transactionProxy.merge(mergePath1, mergeNode1);
transactionProxy.merge(mergePath2, mergeNode2);
readOptional = transactionProxy.read(mergePath2).get(5, TimeUnit.SECONDS);
transactionProxy.delete(deletePath);
Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
assertEquals("Exists response", true, exists);
assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
assertEquals("Response NormalizedNode", mergeNode2, readOptional.get());
List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
assertEquals("Captured BatchedModifications count", 3, batchedModifications.size());
verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(writePath1, writeNode1), new WriteModification(writePath2, writeNode2));
verifyBatchedModifications(batchedModifications.get(1), false, new MergeModification(mergePath1, mergeNode1), new MergeModification(mergePath2, mergeNode2));
verifyBatchedModifications(batchedModifications.get(2), false, new DeleteModification(deletePath));
InOrder inOrder = Mockito.inOrder(mockActorContext);
inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), isA(BatchedModifications.class), any(Timeout.class));
inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(writePath2), any(Timeout.class));
inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), isA(BatchedModifications.class), any(Timeout.class));
inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(mergePath2), any(Timeout.class));
inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), isA(BatchedModifications.class), any(Timeout.class));
inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class));
}
use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.
the class TransactionProxyTest method testReadWrite.
@Test
public void testReadWrite() throws Exception {
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
expectBatchedModifications(actorRef, 1);
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
transactionProxy.read(TestModel.TEST_PATH);
transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
transactionProxy.read(TestModel.TEST_PATH);
transactionProxy.read(TestModel.TEST_PATH);
List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
}
Aggregations