Search in sources :

Example 6 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class DOMTransactionChainTest method testTransactionChainNoConflict.

@Test
public void testTransactionChainNoConflict() throws InterruptedException, ExecutionException, TimeoutException {
    BlockingTransactionChainListener listener = new BlockingTransactionChainListener();
    DOMTransactionChain txChain = domBroker.createTransactionChain(listener);
    assertNotNull(txChain);
    /**
     * We alocate new read-write transaction and write /test.
     */
    DOMDataReadWriteTransaction firstTx = allocateAndWrite(txChain);
    /**
     * First transaction is marked as ready, we are able to allocate chained
     * transactions.
     */
    ListenableFuture<Void> firstWriteTxFuture = firstTx.submit();
    /**
     * We alocate chained transaction - read transaction.
     */
    DOMDataReadTransaction secondReadTx = txChain.newReadOnlyTransaction();
    /**
     * We test if we are able to read data from tx, read should not fail
     * since we are using chained transaction.
     */
    assertTestContainerExists(secondReadTx);
    /**
     * We alocate next transaction, which is still based on first one, but
     * is read-write.
     */
    DOMDataReadWriteTransaction thirdDeleteTx = allocateAndDelete(txChain);
    /**
     * We commit first transaction.
     */
    assertCommitSuccessful(firstWriteTxFuture);
    /**
     * Allocates transaction from data store.
     */
    DOMDataReadTransaction storeReadTx = domBroker.newReadOnlyTransaction();
    /**
     * We verify transaction is commited to store, container should exists
     * in datastore.
     */
    assertTestContainerExists(storeReadTx);
    /**
     * third transaction is sealed and commited.
     */
    ListenableFuture<Void> thirdDeleteTxFuture = thirdDeleteTx.submit();
    assertCommitSuccessful(thirdDeleteTxFuture);
    /**
     * We close transaction chain.
     */
    txChain.close();
    listener.getSuccessFuture().get(1000, TimeUnit.MILLISECONDS);
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) DOMDataReadTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) Test(org.junit.Test)

Example 7 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class DOMTransactionChainTest method allocateAndWrite.

private static DOMDataReadWriteTransaction allocateAndWrite(final DOMTransactionChain txChain) throws InterruptedException, ExecutionException {
    DOMDataReadWriteTransaction tx = txChain.newReadWriteTransaction();
    assertTestContainerWrite(tx);
    return tx;
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)

Example 8 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class DOMBrokerPerformanceTest method measureSeparateWritesOneLevel.

private void measureSeparateWritesOneLevel(final int txNum, final int innerNum) throws Exception {
    final List<DOMDataReadWriteTransaction> transactions = measure("Txs:" + txNum + " Allocate", () -> {
        List<DOMDataReadWriteTransaction> builder = new ArrayList<>(txNum);
        for (int i = 0; i < txNum; i++) {
            DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
            builder.add(writeTx);
        }
        return builder;
    });
    assertEquals(txNum, transactions.size());
    measure("Txs:" + txNum + " Writes:1", (Callable<Void>) () -> {
        int index = 0;
        for (DOMDataReadWriteTransaction writeTx : transactions) {
            // Writes /test/outer-list/i in writeTx
            writeTx.put(OPERATIONAL, outerListPath(index), outerList(index));
            index++;
        }
        return null;
    });
    measure("Txs:" + txNum + " Writes:" + innerNum, (Callable<Void>) () -> {
        int index = 0;
        for (DOMDataReadWriteTransaction writeTx : transactions) {
            // Writes /test/outer-list/i in writeTx
            YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(index)).node(TestModel.INNER_LIST_QNAME).build();
            writeTx.put(OPERATIONAL, path, ImmutableNodes.mapNodeBuilder(TestModel.INNER_LIST_QNAME).build());
            for (int j = 0; j < innerNum; j++) {
                YangInstanceIdentifier innerPath = YangInstanceIdentifier.builder(path).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build();
                writeTx.put(OPERATIONAL, innerPath, ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)));
            }
            index++;
        }
        return null;
    });
    measure("Txs:" + txNum + " Submit, Finish", (Callable<Void>) () -> {
        List<ListenableFuture<?>> allFutures = measure(txNum + " Submits", () -> {
            List<ListenableFuture<?>> builder = new ArrayList<>(txNum);
            for (DOMDataReadWriteTransaction tx : transactions) {
                builder.add(tx.submit());
            }
            return builder;
        });
        Futures.allAsList(allFutures).get();
        return null;
    });
    final DOMDataReadTransaction readTx = measure("Txs:1 (ro), Allocate", (Callable<DOMDataReadTransaction>) () -> domBroker.newReadOnlyTransaction());
    measure("Txs:1 (ro) Reads:" + txNum + " (1-level)", (Callable<Void>) () -> {
        for (int i = 0; i < txNum; i++) {
            ListenableFuture<Optional<NormalizedNode<?, ?>>> potential = readTx.read(OPERATIONAL, outerListPath(i));
            assertTrue("outerList/" + i, potential.get().isPresent());
        }
        return null;
    });
    measure("Txs:1 (ro) Reads:" + txNum * innerNum + " (2-level)", (Callable<Void>) () -> {
        for (int i = 0; i < txNum; i++) {
            for (int j = 0; j < innerNum; j++) {
                YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(i)).node(TestModel.INNER_LIST_QNAME).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build();
                ListenableFuture<Optional<NormalizedNode<?, ?>>> potential = readTx.read(OPERATIONAL, path);
                assertTrue("outer-list/" + i + "/inner-list/" + j, potential.get().isPresent());
            }
        }
        return null;
    });
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) DOMDataReadTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) List(java.util.List) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 9 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class DOMBrokerTest method testTransactionCommit.

@Test(timeout = 10000)
public void testTransactionCommit() throws InterruptedException, ExecutionException {
    DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
    assertNotNull(writeTx);
    /**
     * Writes /test in writeTx
     */
    writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    /**
     * Reads /test from writeTx Read should return container.
     */
    ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(OPERATIONAL, TestModel.TEST_PATH);
    assertTrue(writeTxContainer.get().isPresent());
    writeTx.submit().get();
    Optional<NormalizedNode<?, ?>> afterCommitRead = domBroker.newReadOnlyTransaction().read(OPERATIONAL, TestModel.TEST_PATH).get();
    assertTrue(afterCommitRead.isPresent());
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) Optional(com.google.common.base.Optional) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 10 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class CrossBrokerMountPointTest method testMountPoint.

@Test
public void testMountPoint() throws ReadFailedException, TimeoutException {
    final Integer attrIntValue = 500;
    domMountPointService.createMountPoint(TLL_INSTANCE_ID_BI).addService(DOMDataBroker.class, new DOMDataBroker() {

        @Override
        public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
            throw new UnsupportedOperationException();
        }

        @Override
        public DOMDataWriteTransaction newWriteOnlyTransaction() {
            throw new UnsupportedOperationException();
        }

        @Override
        public DOMDataReadWriteTransaction newReadWriteTransaction() {
            return new DOMDataReadWriteTransaction() {

                @Override
                public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
                    if (store == LogicalDatastoreType.OPERATIONAL && path.getLastPathArgument().equals(GROUP_STATISTICS_ID_BI.getLastPathArgument())) {
                        final ContainerNode data = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(AUG_CONT)).withChild(ImmutableNodes.leafNode(QName.create(AUG_CONT, "attr-int"), attrIntValue)).build();
                        return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?, ?>>of(data));
                    }
                    return Futures.immediateFailedCheckedFuture(new ReadFailedException(TLL_NAME, new Exception()));
                }

                @Override
                public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public Object getIdentifier() {
                    return this;
                }

                @Override
                public boolean cancel() {
                    return false;
                }

                @Override
                public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public CheckedFuture<Void, TransactionCommitFailedException> submit() {
                    throw new UnsupportedOperationException();
                }
            };
        }

        @Override
        public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
            throw new UnsupportedOperationException();
        }

        @Override
        public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
            return Collections.emptyMap();
        }
    }).register();
    final Optional<MountPoint> bindingMountPoint = bindingMountPointService.getMountPoint(TLL_INSTANCE_ID_BA);
    assertTrue(bindingMountPoint.isPresent());
    final Optional<DataBroker> dataBroker = bindingMountPoint.get().getService(DataBroker.class);
    assertTrue(dataBroker.isPresent());
    final Optional<Cont> data = dataBroker.get().newReadWriteTransaction().read(LogicalDatastoreType.OPERATIONAL, AUG_CONT_ID_BA).checkedGet(5, TimeUnit.SECONDS);
    assertTrue(data.isPresent());
    assertEquals(attrIntValue, data.get().getAttrInt());
}
Also used : DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) 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) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TimeoutException(java.util.concurrent.TimeoutException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) MountPoint(org.opendaylight.controller.md.sal.binding.api.MountPoint) Cont(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.top.top.level.list.list1.list1._1.Cont) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DOMDataChangeListener(org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Test(org.junit.Test)

Aggregations

DOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)24 Test (org.junit.Test)8 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)6 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 Measurement (org.openjdk.jmh.annotations.Measurement)6 Warmup (org.openjdk.jmh.annotations.Warmup)6 Optional (com.google.common.base.Optional)5 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)4 DOMTransactionChain (org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain)4 TransactionChainListener (org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener)3 DOMDataReadOnlyTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction)3 DOMDataReadTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction)3 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)3 ForwardingDOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataReadWriteTransaction)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 InOrder (org.mockito.InOrder)2 AsyncTransaction (org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction)2 DOMDataBroker (org.opendaylight.controller.md.sal.dom.api.DOMDataBroker)2