Class DataBrokerFailuresImpl
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- org.opendaylight.mdsal.binding.spi.ForwardingDataBroker
-
- org.opendaylight.mdsal.binding.testutils.DataBrokerFailuresImpl
-
- All Implemented Interfaces:
BindingService
,DataBroker
,DataTreeChangeService
,TransactionFactory
,DataBrokerFailures
public class DataBrokerFailuresImpl extends ForwardingDataBroker implements DataBrokerFailures
DataBroker with methods to simulate failures, useful for tests.- Author:
- Michael Vorburger.ch
-
-
Constructor Summary
Constructors Constructor Description DataBrokerFailuresImpl(DataBroker delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DataBroker
delegate()
void
failButCommitAnyway()
To simulate scenarios where even though the transaction throws a TransactionCommitFailedException (caused by akka.pattern.AskTimeoutException) it eventually succeeds.void
failCommits(int howManyTimes, TransactionCommitFailedException exception)
Fails N future Transaction commits.void
failCommits(TransactionCommitFailedException exception)
Fails all future Transaction commits.void
failReads(int howManyTimes, ReadFailedException exception)
Fails N future reads.void
failReads(ReadFailedException exception)
Fails all future reads.<T extends DataObject>
FluentFuture<Optional<T>>handleRead(BiFunction<LogicalDatastoreType,InstanceIdentifier<T>,FluentFuture<Optional<T>>> readMethod, LogicalDatastoreType store, InstanceIdentifier<T> path)
ReadWriteTransaction
newReadWriteTransaction()
Allocates new read-write transaction which provides a mutable view of the data tree.WriteTransaction
newWriteOnlyTransaction()
Allocates new write-only transaction based on latest state of data tree.void
unfailCommits()
void
unfailReads()
-
Methods inherited from class org.opendaylight.mdsal.binding.spi.ForwardingDataBroker
createMergingTransactionChain, createTransactionChain, newReadOnlyTransaction, registerDataTreeChangeListener
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
-
-
-
Constructor Detail
-
DataBrokerFailuresImpl
public DataBrokerFailuresImpl(DataBroker delegate)
-
-
Method Detail
-
delegate
protected DataBroker delegate()
- Specified by:
delegate
in classForwardingDataBroker
-
failReads
public void failReads(ReadFailedException exception)
Description copied from interface:DataBrokerFailures
Fails all future reads.- Specified by:
failReads
in interfaceDataBrokerFailures
- Parameters:
exception
- aReadFailedException
to throw from aReadOperations.read(LogicalDatastoreType, InstanceIdentifier)
call.
-
failReads
public void failReads(int howManyTimes, ReadFailedException exception)
Description copied from interface:DataBrokerFailures
Fails N future reads.- Specified by:
failReads
in interfaceDataBrokerFailures
- Parameters:
howManyTimes
- how many times to throw the passed exception, until it resets.exception
- aReadFailedException
to throw from aReadOperations.read(LogicalDatastoreType, InstanceIdentifier)
call.
-
failCommits
public void failCommits(TransactionCommitFailedException exception)
Description copied from interface:DataBrokerFailures
Fails all future Transaction commits.- Specified by:
failCommits
in interfaceDataBrokerFailures
- Parameters:
exception
- an Exception to throw from aWriteTransaction.commit()
method.
-
failCommits
public void failCommits(int howManyTimes, TransactionCommitFailedException exception)
Description copied from interface:DataBrokerFailures
Fails N future Transaction commits.- Specified by:
failCommits
in interfaceDataBrokerFailures
- Parameters:
howManyTimes
- how many times to throw the passed exception, until it resetsexception
- an Exception to throw from aWriteTransaction.commit()
method.
-
unfailReads
public void unfailReads()
Description copied from interface:DataBrokerFailures
Resets any earlierDataBrokerFailures.failReads(ReadFailedException)
orDataBrokerFailures.failReads(int, ReadFailedException)
.- Specified by:
unfailReads
in interfaceDataBrokerFailures
-
unfailCommits
public void unfailCommits()
Description copied from interface:DataBrokerFailures
Resets any earlierDataBrokerFailures.failCommits(TransactionCommitFailedException)
orDataBrokerFailures.failCommits(int, TransactionCommitFailedException)
.- Specified by:
unfailCommits
in interfaceDataBrokerFailures
-
failButCommitAnyway
public void failButCommitAnyway()
Description copied from interface:DataBrokerFailures
To simulate scenarios where even though the transaction throws a TransactionCommitFailedException (caused by akka.pattern.AskTimeoutException) it eventually succeeds. These timeouts are typically seen in scaled cluster environments under load. The new tell-based protocol, which will soon be enabled by default (c/61002), adds internal retries for transactions, making the application not to handle such scenarios.- Specified by:
failButCommitAnyway
in interfaceDataBrokerFailures
-
handleRead
public <T extends DataObject> FluentFuture<Optional<T>> handleRead(BiFunction<LogicalDatastoreType,InstanceIdentifier<T>,FluentFuture<Optional<T>>> readMethod, LogicalDatastoreType store, InstanceIdentifier<T> path)
-
newReadWriteTransaction
public ReadWriteTransaction newReadWriteTransaction()
Description copied from interface:TransactionFactory
Allocates new read-write transaction which provides a mutable view of the data tree.Preconditions for mutation of data tree are captured from the snapshot of data tree state, when the transaction is allocated. If data was changed during transaction in an incompatible way then the commit of this transaction will fail. See
WriteTransaction.commit()
for more details about conflicting and non-conflicting changes and failure scenarios.- Specified by:
newReadWriteTransaction
in interfaceTransactionFactory
- Overrides:
newReadWriteTransaction
in classForwardingDataBroker
- Returns:
- new read-write transaction
-
newWriteOnlyTransaction
public WriteTransaction newWriteOnlyTransaction()
Description copied from interface:TransactionFactory
Allocates new write-only transaction based on latest state of data tree.Preconditions for mutation of data tree are captured from the snapshot of data tree state, when the transaction is allocated. If data was changed during transaction in an incompatible way then the commit of this transaction will fail. See
WriteTransaction.commit()
for more details about conflicting and not-conflicting changes and failure scenarios.Since this transaction does not provide a view of the data it SHOULD BE used only by callers who are exclusive writers (exporters of data) to the subtree they modify. This prevents optimistic lock failures as described in
WriteTransaction.commit()
.Exclusivity of writers to particular subtree SHOULD BE enforced by external locking mechanism.
- Specified by:
newWriteOnlyTransaction
in interfaceTransactionFactory
- Overrides:
newWriteOnlyTransaction
in classForwardingDataBroker
- Returns:
- new write-only transaction
-
-