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();
}
}
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());
}
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();
}
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();
}
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;
}
Aggregations