Search in sources :

Example 76 with NormalizedNode

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));
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) InOrder(org.mockito.InOrder) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 77 with NormalizedNode

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;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 78 with NormalizedNode

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);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Optional(com.google.common.base.Optional) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess) Test(org.junit.Test)

Example 79 with NormalizedNode

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());
}
Also used : DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)

Example 80 with NormalizedNode

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));
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) InOrder(org.mockito.InOrder) Optional(com.google.common.base.Optional) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) TransactionChainListener(org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener) AsyncTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Aggregations

NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)94 Test (org.junit.Test)55 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)39 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)18 Optional (com.google.common.base.Optional)15 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9 ActorRef (akka.actor.ActorRef)8 InOrder (org.mockito.InOrder)8 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)8 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)8 ExecutionException (java.util.concurrent.ExecutionException)7 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)7 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)7 Map (java.util.Map)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6