Class DataBrokerFailuresImpl

  • All Implemented Interfaces:
    DataBrokerFailures, org.opendaylight.mdsal.binding.api.BindingService, org.opendaylight.mdsal.binding.api.DataBroker, org.opendaylight.mdsal.binding.api.DataTreeChangeService, org.opendaylight.mdsal.binding.api.TransactionFactory

    public class DataBrokerFailuresImpl
    extends org.opendaylight.mdsal.binding.spi.ForwardingDataBroker
    implements DataBrokerFailures
    DataBroker with methods to simulate failures, useful for tests.

    If you use this from a Guice-based component test, consider just binding it via the DataBrokerFailuresModule.

    Author:
    Michael Vorburger.ch
    • Constructor Summary

      Constructors 
      Constructor Description
      DataBrokerFailuresImpl​(org.opendaylight.mdsal.binding.api.DataBroker delegate)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.opendaylight.mdsal.binding.api.DataBroker delegate()  
      void failButSubmitsAnyways()
      To simulate scenarios where even though the transaction throws a TransactionCommitFailedException (caused by akka.pattern.AskTimeoutException) it eventually succeeds.
      void failReads​(int howManyTimes, org.opendaylight.mdsal.common.api.ReadFailedException exception)
      Fails N future reads.
      void failReads​(org.opendaylight.mdsal.common.api.ReadFailedException exception)
      Fails all future reads.
      void failSubmits​(int howManyTimes, org.opendaylight.mdsal.common.api.TransactionCommitFailedException exception)
      Fails N future Transaction submits.
      void failSubmits​(org.opendaylight.mdsal.common.api.TransactionCommitFailedException exception)
      Fails all future Transaction submits.
      <T extends org.opendaylight.yangtools.yang.binding.DataObject>
      com.google.common.util.concurrent.FluentFuture<java.util.Optional<T>>
      handleRead​(java.util.function.BiFunction<org.opendaylight.mdsal.common.api.LogicalDatastoreType,​org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T>,​com.google.common.util.concurrent.FluentFuture<java.util.Optional<T>>> readMethod, org.opendaylight.mdsal.common.api.LogicalDatastoreType store, org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> path)  
      org.opendaylight.mdsal.binding.api.ReadWriteTransaction newReadWriteTransaction()  
      org.opendaylight.mdsal.binding.api.WriteTransaction newWriteOnlyTransaction()  
      void unfailReads()
      void unfailSubmits()
      • Methods inherited from class org.opendaylight.mdsal.binding.spi.ForwardingDataBroker

        createMergingTransactionChain, createTransactionChain, newReadOnlyTransaction, registerDataTreeChangeListener
      • Methods inherited from class com.google.common.collect.ForwardingObject

        toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DataBrokerFailuresImpl

        public DataBrokerFailuresImpl​(org.opendaylight.mdsal.binding.api.DataBroker delegate)
    • Method Detail

      • delegate

        protected org.opendaylight.mdsal.binding.api.DataBroker delegate()
        Specified by:
        delegate in class org.opendaylight.mdsal.binding.spi.ForwardingDataBroker
      • failReads

        public void failReads​(org.opendaylight.mdsal.common.api.ReadFailedException exception)
        Description copied from interface: DataBrokerFailures
        Fails all future reads.
        Specified by:
        failReads in interface DataBrokerFailures
        Parameters:
        exception - a ReadFailedException to throw from a ReadOperations.read(LogicalDatastoreType, InstanceIdentifier) call.
      • failReads

        public void failReads​(int howManyTimes,
                              org.opendaylight.mdsal.common.api.ReadFailedException exception)
        Description copied from interface: DataBrokerFailures
        Fails N future reads.
        Specified by:
        failReads in interface DataBrokerFailures
        Parameters:
        howManyTimes - how many times to throw the passed exception, until it resets.
        exception - a ReadFailedException to throw from a ReadOperations.read(LogicalDatastoreType, InstanceIdentifier) call.
      • failSubmits

        public void failSubmits​(org.opendaylight.mdsal.common.api.TransactionCommitFailedException exception)
        Description copied from interface: DataBrokerFailures
        Fails all future Transaction submits.
        Specified by:
        failSubmits in interface DataBrokerFailures
        Parameters:
        exception - an Exception to throw from a WriteTransaction.commit() (also WriteTransaction.commit() ) method
      • failSubmits

        public void failSubmits​(int howManyTimes,
                                org.opendaylight.mdsal.common.api.TransactionCommitFailedException exception)
        Description copied from interface: DataBrokerFailures
        Fails N future Transaction submits.
        Specified by:
        failSubmits in interface DataBrokerFailures
        Parameters:
        howManyTimes - how many times to throw the passed exception, until it resets
        exception - an Exception to throw from a WriteTransaction.commit() (also WriteTransaction.commit() method
      • failButSubmitsAnyways

        public void failButSubmitsAnyways()
        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:
        failButSubmitsAnyways in interface DataBrokerFailures
      • handleRead

        public <T extends org.opendaylight.yangtools.yang.binding.DataObject> com.google.common.util.concurrent.FluentFuture<java.util.Optional<T>> handleRead​(java.util.function.BiFunction<org.opendaylight.mdsal.common.api.LogicalDatastoreType,​org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T>,​com.google.common.util.concurrent.FluentFuture<java.util.Optional<T>>> readMethod,
                                                                                                                                                               org.opendaylight.mdsal.common.api.LogicalDatastoreType store,
                                                                                                                                                               org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> path)
      • newReadWriteTransaction

        public org.opendaylight.mdsal.binding.api.ReadWriteTransaction newReadWriteTransaction()
        Specified by:
        newReadWriteTransaction in interface org.opendaylight.mdsal.binding.api.TransactionFactory
        Overrides:
        newReadWriteTransaction in class org.opendaylight.mdsal.binding.spi.ForwardingDataBroker
      • newWriteOnlyTransaction

        public org.opendaylight.mdsal.binding.api.WriteTransaction newWriteOnlyTransaction()
        Specified by:
        newWriteOnlyTransaction in interface org.opendaylight.mdsal.binding.api.TransactionFactory
        Overrides:
        newWriteOnlyTransaction in class org.opendaylight.mdsal.binding.spi.ForwardingDataBroker