class SwitchableLoggedBehavior[A, B] extends Behavior[A, B]
Test utility to make behavior of functions that return some Future[B] controllable from tests. This tool is able to overwrite default behavior with any generic behavior, including failure, and exposes control to the timing of the completion of the returned future.
The utility is implemented as a stack of behaviors, where the behavior on the top of the stack represents the currently active behavior. The bottom of the stack always contains the defaultBehavior which can not be popped out.
- Source
- TestTransport.scala
- Alphabetic
- By Inheritance
- SwitchableLoggedBehavior
- Function1
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new SwitchableLoggedBehavior(defaultBehavior: Behavior[A, B], logCallback: (A) => Unit)
- defaultBehavior
The original behavior that might be overwritten. It is always possible to restore this behavior
- logCallback
Function that will be called independently of the current active behavior type parameter A:
- Parameter type of the wrapped function. If it takes multiple parameters it must be wrapped in a tuple. type parameter B:
- Type parameter of the future that the original function returns.
Value Members
- def andThen[A](g: (Future[B]) => A): (A) => A
- Definition Classes
- Function1
- Annotations
- @unspecialized()
- def apply(params: A): Future[B]
Applies the current behavior, and invokes the callback.
Applies the current behavior, and invokes the callback.
- params
The parameters of this behavior.
- returns
The result of this behavior wrapped in a future.
- Definition Classes
- SwitchableLoggedBehavior → Function1
- def compose[A](g: (A) => A): (A) => Future[B]
- Definition Classes
- Function1
- Annotations
- @unspecialized()
- def pop(): Unit
Restores the previous behavior.
- def push(behavior: Behavior[A, B]): Unit
Changes the current behavior to the provided one.
Changes the current behavior to the provided one.
- behavior
Function that takes a parameter type A and returns a Future[B].
- def pushConstant(c: B): Unit
Changes the behavior to return a completed future with the given constant value.
Changes the behavior to return a completed future with the given constant value.
- c
The constant the future will be completed with.
- def pushDelayed: Promise[Unit]
Enables control of the completion of the previously active behavior.
Enables control of the completion of the previously active behavior. Wraps the previous behavior in a new one, returns a control promise that starts the original behavior after the control promise is completed.
- returns
A promise, which delays the completion of the original future until after this promise is completed.
- def pushError(e: Throwable): Unit
Changes the current behavior to return a failed future containing the given Throwable.
Changes the current behavior to return a failed future containing the given Throwable.
- e
The throwable the failed future will contain.
- def toString(): String
- Definition Classes
- Function1 → AnyRef → Any