Search in sources :

Example 1 with DOMDataTreeReadTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testLazySubTransactionCreationForReadOnlyTransactions.

@Test
public void testLazySubTransactionCreationForReadOnlyTransactions() {
    DOMStore configDomStore = mock(DOMStore.class);
    DOMStore operationalDomStore = mock(DOMStore.class);
    DOMStoreReadTransaction storeTxn = mock(DOMStoreReadTransaction.class);
    doReturn(storeTxn).when(operationalDomStore).newReadOnlyTransaction();
    doReturn(storeTxn).when(configDomStore).newReadOnlyTransaction();
    try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION, configDomStore), futureExecutor)) {
        DOMDataTreeReadTransaction dataTxn = dataBroker.newReadOnlyTransaction();
        dataTxn.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
        dataTxn.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
        verify(configDomStore, never()).newReadOnlyTransaction();
        verify(operationalDomStore, times(1)).newReadOnlyTransaction();
        dataTxn.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
        verify(configDomStore, times(1)).newReadOnlyTransaction();
        verify(operationalDomStore, times(1)).newReadOnlyTransaction();
    }
}
Also used : DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) Test(org.junit.Test)

Example 2 with DOMDataTreeReadTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction in project controller by opendaylight.

the class ShardedDOMDataBrokerDelegatingTransactionChainTest method testTransactionChainFailed.

@Test
public void testTransactionChainFailed() {
    final DOMDataTreeWriteTransaction writeTxDelegate = mock(DOMDataTreeWriteTransaction.class);
    doReturn("DELEGATE-WRITE-TX-1").when(writeTxDelegate).getIdentifier();
    doReturn(writeTxDelegate).when(delegateTxChain).newWriteOnlyTransaction();
    doNothing().when(txChainlistener).onTransactionChainFailed(any(), any(), any());
    // verify writetx fail
    txChain.newWriteOnlyTransaction();
    txChain.onTransactionChainFailed(delegateTxChain, writeTxDelegate, new Throwable("Fail"));
    final ArgumentCaptor<AsyncTransaction> txCaptor = ArgumentCaptor.forClass(AsyncTransaction.class);
    final ArgumentCaptor<Throwable> throwableCaptor = ArgumentCaptor.forClass(Throwable.class);
    verify(txChainlistener).onTransactionChainFailed(eq(txChain), txCaptor.capture(), throwableCaptor.capture());
    assertEquals("DOM-CHAIN-1-0", txCaptor.getValue().getIdentifier());
    assertEquals("Fail", throwableCaptor.getValue().getMessage());
    // verify readtx fail
    final DOMDataTreeReadTransaction readTxDelegate = mock(DOMDataTreeReadTransaction.class);
    doReturn("DELEGATE-READ-TX-1").when(readTxDelegate).getIdentifier();
    doReturn(readTxDelegate).when(delegateTxChain).newReadOnlyTransaction();
    doNothing().when(txChainlistener).onTransactionChainFailed(any(), any(), any());
    txChain.newReadOnlyTransaction();
    txChain.onTransactionChainFailed(delegateTxChain, readTxDelegate, new Throwable("Fail"));
    verify(txChainlistener, times(2)).onTransactionChainFailed(eq(txChain), txCaptor.capture(), throwableCaptor.capture());
    assertEquals("DOM-CHAIN-1-1", txCaptor.getValue().getIdentifier());
    assertEquals("Fail", throwableCaptor.getValue().getMessage());
    // verify readwritetx fail, we must check both read and write failure
    // translates to returned readwritetx
    // we can reuse write and read tx delegates, just return different
    // identifiers to avoid conflicts in keys in tx dictionary
    doReturn("DELEGATE-WRITE-RWTX-1").when(writeTxDelegate).getIdentifier();
    doReturn("DELEGATE-READ-RWTX-1").when(readTxDelegate).getIdentifier();
    txChain.newReadWriteTransaction();
    txChain.onTransactionChainFailed(delegateTxChain, writeTxDelegate, new Throwable("Fail"));
    verify(txChainlistener, times(3)).onTransactionChainFailed(eq(txChain), txCaptor.capture(), throwableCaptor.capture());
    assertEquals("DOM-CHAIN-1-2", txCaptor.getValue().getIdentifier());
    assertEquals("Fail", throwableCaptor.getValue().getMessage());
    txChain.onTransactionChainFailed(delegateTxChain, readTxDelegate, new Throwable("Fail"));
    verify(txChainlistener, times(4)).onTransactionChainFailed(eq(txChain), txCaptor.capture(), throwableCaptor.capture());
    assertEquals("DOM-CHAIN-1-2", txCaptor.getValue().getIdentifier());
    assertEquals("Fail", throwableCaptor.getValue().getMessage());
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) AsyncTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) Test(org.junit.Test)

Example 3 with DOMDataTreeReadTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction in project controller by opendaylight.

the class ShardedDOMDataBrokerDelegatingTransactionChainTest method testNewReadOnlyTransaction.

@Test
public void testNewReadOnlyTransaction() {
    DOMDataTreeReadTransaction delegateReadTx = mock(DOMDataTreeReadTransaction.class);
    doReturn("TEST-READ-TX-DELEGATE").when(delegateReadTx).getIdentifier();
    doReturn(delegateReadTx).when(delegateTxChain).newReadOnlyTransaction();
    txChain.newReadOnlyTransaction();
    verify(delegateTxChain).newReadOnlyTransaction();
}
Also used : DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) Test(org.junit.Test)

Example 4 with DOMDataTreeReadTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction in project controller by opendaylight.

the class ShardedDOMDataBrokerDelegatingTransactionChainTest method testNewReadWriteTransaction.

@Test
public void testNewReadWriteTransaction() {
    DOMDataTreeReadTransaction delegateReadTx = mock(DOMDataTreeReadTransaction.class);
    doReturn("TEST-READ-TX-DELEGATE").when(delegateReadTx).getIdentifier();
    doReturn(delegateReadTx).when(delegateTxChain).newReadOnlyTransaction();
    DOMDataTreeWriteTransaction delegateWriteTx = mock(DOMDataTreeWriteTransaction.class);
    doReturn(delegateWriteTx).when(delegateTxChain).newWriteOnlyTransaction();
    doReturn("TEST-WRITE-TX-DELEGATE").when(delegateWriteTx).getIdentifier();
    txChain.newReadWriteTransaction();
    verify(delegateTxChain).newReadOnlyTransaction();
    verify(delegateTxChain).newWriteOnlyTransaction();
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) Test(org.junit.Test)

Example 5 with DOMDataTreeReadTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction in project controller by opendaylight.

the class ShardedDOMDataBrokerDelegatingTransactionChain method newReadWriteTransaction.

@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
    final Object readWriteTxId = newTransactionIdentifier();
    final DOMDataTreeReadTransaction readTxDelegate = txChainDelegate.newReadOnlyTransaction();
    final DOMDataReadOnlyTransaction readTx = new ShardedDOMDataBrokerDelegatingReadTransaction(readWriteTxId, readTxDelegate);
    final DOMDataTreeWriteTransaction writeTxDelegate = txChainDelegate.newWriteOnlyTransaction();
    final DOMDataWriteTransaction writeTx = new ShardedDOMDataBrokerDelegatingWriteTransaction(readWriteTxId, writeTxDelegate);
    final DOMDataReadWriteTransaction readWriteTx = new ShardedDOMDataBrokerDelegatingReadWriteTransaction(readWriteTxId, schemaContext, readTx, writeTx);
    transactionMap.put(readTxDelegate.getIdentifier(), readWriteTx);
    transactionMap.put(writeTxDelegate.getIdentifier(), readWriteTx);
    return readWriteTx;
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Aggregations

DOMDataTreeReadTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction)6 Test (org.junit.Test)4 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)3 DOMDataReadOnlyTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction)2 AsyncTransaction (org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction)1 DOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)1 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)1 DOMStore (org.opendaylight.mdsal.dom.spi.store.DOMStore)1 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)1