RpcFaultInjector class

An IRpcInterceptor that injects errors or latency into specific RPC methods.

Useful for testing how clients and modules handle failures, retries, and timeouts without changing production handler code.

final faults = RpcFaultInjector()
  ..failMethod('UserService', 'getUser', RpcException('not found'))
  ..delayMethod('OrderService', 'createOrder', Duration(milliseconds: 200));

final app = await RpcTestApp.start(
  modules: [UserModule(), OrderModule()],
  interceptors: [faults],
);

Fault lookup key is 'ServiceName.methodName'. Delays are applied before error injection. Per-method one-shot errors (failMethodOnce) are queued and consumed in registration order; permanent errors (failMethod) fire after the one-shot queue is exhausted.

Constructors

RpcFaultInjector()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Remove all registered faults and delays.
delayMethod(String service, String method, Duration delay) → void
Add delay before processing each call to service.method.
failMethod(String service, String method, Object error) → void
Always throw error when service.method is called.
failMethodOnce(String service, String method, Object error) → void
Throw error on the next call to service.method, then remove it.
interceptBidirectionalStream<TRequest, TResponse>(RpcMiddlewareContext call, Stream<TRequest> requests, RpcBidirectionalStreamNext<TRequest, TResponse> next) FutureOr<Stream<TResponse>>
Bidirectional-stream call interceptor.
interceptClientStream<TRequest, TResponse>(RpcMiddlewareContext call, Stream<TRequest> requests, RpcClientStreamNext<TRequest, TResponse> next) Future<TResponse>
Client-stream call interceptor.
interceptServerStream<TRequest, TResponse>(RpcMiddlewareContext call, TRequest request, RpcServerStreamNext<TRequest, TResponse> next) FutureOr<Stream<TResponse>>
Server-stream call interceptor.
interceptUnary<TRequest, TResponse>(RpcMiddlewareContext call, TRequest request, RpcUnaryNext<TRequest, TResponse> next) Future<TResponse>
Unary call interceptor.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeMethod(String service, String method) → void
Remove all faults (permanent error, one-shot queue, and delay) for service.method.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited