Interface MockedGrpcServices


@DoNotInherit public interface MockedGrpcServices
Registry of mocked gRPC services for a running TestKit. Lets individual tests install or replace mock instances without re-creating the testkit.

Entries declared via TestKit.Settings.withMockedGrpcService(String, Class, AkkaGrpcClient) are used to seed the registry at testkit startup and are restored by reset().

The mock instance is shared across calls and method invocations can overlap when the service under test issues concurrent requests, so any state shared between the mock and the test class (captured fields, counters, queues) must be thread-safe.

Not for user extension.

  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends akka.grpc.javadsl.AkkaGrpcClient>
    void
    mockResponse(String serviceName, Class<T> serviceClass, T mockInstance)
    Register or replace a mock instance for calls made through grpcClientProvider.grpcClientFor(serviceClass, serviceName).
    <T extends akka.grpc.javadsl.AkkaGrpcClient>
    void
    remove(String serviceName, Class<T> serviceClass)
    Remove the mock for the given service name and client class, if any.
    void
    Reset the registry back to the mocks declared in TestKit.Settings.
  • Method Details

    • mockResponse

      <T extends akka.grpc.javadsl.AkkaGrpcClient> void mockResponse(String serviceName, Class<T> serviceClass, T mockInstance)
      Register or replace a mock instance for calls made through grpcClientProvider.grpcClientFor(serviceClass, serviceName).
    • remove

      <T extends akka.grpc.javadsl.AkkaGrpcClient> void remove(String serviceName, Class<T> serviceClass)
      Remove the mock for the given service name and client class, if any.
    • reset

      void reset()
      Reset the registry back to the mocks declared in TestKit.Settings.