use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode 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.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class DistributedEntityOwnershipIntegrationTest method verifyCandidates.
private static void verifyCandidates(final AbstractDataStore dataStore, final DOMEntity entity, final String... expCandidates) throws Exception {
AssertionError lastError = null;
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.MILLISECONDS) <= 10000) {
Optional<NormalizedNode<?, ?>> possible = dataStore.newReadOnlyTransaction().read(entityPath(entity.getType(), entity.getIdentifier()).node(Candidate.QNAME)).get(5, TimeUnit.SECONDS);
try {
assertEquals("Candidates not found for " + entity, true, possible.isPresent());
Collection<String> actual = new ArrayList<>();
for (MapEntryNode candidate : ((MapNode) possible.get()).getValue()) {
actual.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
}
assertEquals("Candidates for " + entity, Arrays.asList(expCandidates), actual);
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class RemoteProxyTransactionTest method testRead.
@Override
@Test
public void testRead() throws Exception {
final TransactionTester<RemoteProxyTransaction> tester = getTester();
final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = transaction.read(PATH_2);
final ReadTransactionRequest req = tester.expectTransactionRequest(ReadTransactionRequest.class);
final Optional<NormalizedNode<?, ?>> result = Optional.of(DATA_1);
tester.replySuccess(new ReadTransactionSuccess(TRANSACTION_ID, req.getSequence(), result));
assertFutureEquals(result, read);
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class IntegrationTestKit method testWriteTransaction.
void testWriteTransaction(final AbstractDataStore dataStore, final YangInstanceIdentifier nodePath, final NormalizedNode<?, ?> nodeToWrite) throws Exception {
// 1. Create a write-only Tx
DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
// 2. Write some data
writeTx.write(nodePath, nodeToWrite);
// 3. Ready the Tx for commit
DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
// 4. Commit the Tx
doCommit(cohort);
// 5. Verify the data in the store
DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
Optional<NormalizedNode<?, ?>> optional = readTx.read(nodePath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", nodeToWrite, optional.get());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapterTest method testTransactionChain.
@SuppressWarnings("rawtypes")
@Test
public void testTransactionChain() throws Exception {
TransactionChainListener mockListener = mock(TransactionChainListener.class);
doNothing().when(mockListener).onTransactionChainSuccessful(anyObject());
doNothing().when(mockListener).onTransactionChainFailed(anyObject(), anyObject(), anyObject());
DOMTransactionChain chain = adapter.createTransactionChain(mockListener);
// Test read-only tx
DOMDataReadOnlyTransaction readTx = chain.newReadOnlyTransaction();
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = readTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
Optional<NormalizedNode<?, ?>> readOptional = readFuture.get();
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("NormalizedNode", dataNode, readOptional.get());
// Test write-only tx
DOMDataWriteTransaction writeTx = chain.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
verify(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTx.submit();
submitFuture.get(5, TimeUnit.SECONDS);
InOrder inOrder = inOrder(mockCommitCohort);
inOrder.verify(mockCommitCohort).canCommit();
inOrder.verify(mockCommitCohort).preCommit();
inOrder.verify(mockCommitCohort).commit();
// Test read-write tx
DOMDataReadWriteTransaction readWriteTx = chain.newReadWriteTransaction();
readFuture = readWriteTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
readOptional = readFuture.get();
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("NormalizedNode", dataNode, readOptional.get());
chain.close();
verify(mockListener).onTransactionChainSuccessful(chain);
// Test failed chain
doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.TransactionCommitFailedException("mock", (Throwable) null))).when(mockCommitCohort).canCommit();
chain = adapter.createTransactionChain(mockListener);
writeTx = chain.newWriteOnlyTransaction();
try {
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (TransactionCommitFailedException e) {
// expected
}
ArgumentCaptor<AsyncTransaction> failedTx = ArgumentCaptor.forClass(AsyncTransaction.class);
verify(mockListener).onTransactionChainFailed(eq(chain), failedTx.capture(), any(TransactionCommitFailedException.class));
}
Aggregations