class NetworkBehavior
A simple emulation of the behavior of network calls.
This class models three properties of a network:
IOException). MockRetrofit. Behavior can also be applied elsewhere using #calculateDelay(TimeUnit) and #calculateIsFailure().
By default, instances of this class will use a 2 second delay with 40% variance. Failures will occur 3% of the time. HTTP errors will occur 0% of the time.
fun calculateDelay(unit: TimeUnit!): Long
Get the delay that should be used for delaying a response in accordance with configured behavior. |
|
fun calculateIsError(): Boolean
Randomly determine whether this call should result in an HTTP error in accordance with configured behavior. When true, |
|
fun calculateIsFailure(): Boolean
Randomly determine whether this call should result in a network failure in accordance with configured behavior. When true, |
|
static fun create(): NetworkBehavior!
Create an instance with default behavior. static fun create(random: Random!): NetworkBehavior!
Create an instance with default behavior which uses |
|
fun createErrorResponse(): Response<*>!
The HTTP error to be used when an error is triggered. |
|
fun delay(unit: TimeUnit!): Long
The network round trip delay. |
|
fun errorPercent(): Int
The percentage of calls to |
|
fun failureException(): Throwable!
The exception to be used when a failure is triggered. |
|
fun failurePercent(): Int
The percentage of calls to |
|
fun setDelay(amount: Long, unit: TimeUnit!): Unit
Set the network round trip delay. |
|
fun setErrorFactory(errorFactory: Callable<Response<*>!>!): Unit
Set the error response factory to be used when an error is triggered. This factory may only return responses for which |
|
fun setErrorPercent(errorPercent: Int): Unit
Set the percentage of calls to |
|
fun setFailureException(exception: Throwable!): Unit
Set the exception to be used when a failure is triggered. |
|
fun setFailurePercent(failurePercent: Int): Unit
Set the percentage of calls to |
|
fun setVariancePercent(variancePercent: Int): Unit
Set the plus-or-minus variance percentage of the network round trip delay. |
|
fun variancePercent(): Int
The plus-or-minus variance percentage of the network round trip delay. |