Class KalixTestKit

Object
kalix.javasdk.testkit.KalixTestKit

public class KalixTestKit extends Object
Testkit for running Kalix services locally.

Requires Docker for starting a local instance of the Kalix Runtime.

Create a KalixTestkit with an Kalix service descriptor, and then start() the testkit before testing the service with gRPC or HTTP clients. Call stop() after tests are complete.

  • Constructor Details

    • KalixTestKit

      public KalixTestKit(kalix.javasdk.Kalix kalix)
      Create a new testkit for a Kalix service descriptor.
      Parameters:
      kalix - Kalix service descriptor
    • KalixTestKit

      public KalixTestKit(kalix.javasdk.Kalix kalix, KalixTestKit.Settings settings)
      Create a new testkit for a Kalix service descriptor with custom settings.
      Parameters:
      kalix - Kalix service descriptor
      settings - custom testkit settings
    • KalixTestKit

      public KalixTestKit(kalix.javasdk.Kalix kalix, kalix.javasdk.impl.MessageCodec messageCodec, KalixTestKit.Settings settings)
      Create a new testkit for a Kalix service descriptor with custom settings.
      Parameters:
      kalix - Kalix service descriptor
      messageCodec - message codec
      settings - custom testkit settings
  • Method Details

    • start

      public KalixTestKit start()
      Start this testkit with default configuration (loaded from application.conf).
      Returns:
      this KalixTestkit
    • start

      public KalixTestKit start(com.typesafe.config.Config config)
      Start this testkit with custom configuration (overrides application.conf).
      Parameters:
      config - custom test configuration for the KalixRunner
      Returns:
      this KalixTestkit
    • getHost

      public String getHost()
      Get the host name/IP address where the Kalix service is available. This is relevant in certain Continuous Integration environments.
      Returns:
      Kalix host
    • getPort

      public int getPort()
      Get the local port where the Kalix service is available.
      Returns:
      local Kalix port
    • getGrpcClient

      public <T> T getGrpcClient(Class<T> clientClass)
      Get an Akka gRPC client for the given service name. The same client instance is shared for the test. The lifecycle of the client is managed by the SDK and it should not be stopped by user code.
      Type Parameters:
      T - The "service" interface generated for the service by Akka gRPC
      Parameters:
      clientClass - The class of a gRPC service generated by Akka gRPC
    • getGrpcClientForPrincipal

      public <T> T getGrpcClientForPrincipal(Class<T> clientClass, kalix.javasdk.Principal principal)
      Get an Akka gRPC client for the given service name, authenticating using the given principal. The same client instance is shared for the test. The lifecycle of the client is managed by the SDK and it should not be stopped by user code.
      Type Parameters:
      T - The "service" interface generated for the service by Akka gRPC
      Parameters:
      clientClass - The class of a gRPC service generated by Akka gRPC
      principal - The principal to authenticate calls to the service as.
    • getMaterializer

      public akka.stream.Materializer getMaterializer()
      An Akka Stream materializer to use for running streams. Needed for example in a command handler which accepts streaming elements but returns a single async reply once all streamed elements has been consumed.
    • getActorSystem

      public akka.actor.ActorSystem getActorSystem()
      Get an ActorSystem for creating Akka HTTP clients.
      Returns:
      test actor system
    • getGrpcClientSettings

      @Deprecated(since="0.8.1", forRemoval=true) public akka.grpc.GrpcClientSettings getGrpcClientSettings()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getGrpcClient instead.
      Get GrpcClientSettings for creating Akka gRPC clients.
      Returns:
      test gRPC client settings
    • getTopic

      @Deprecated public EventingTestKit.Topic getTopic(String topic)
      Deprecated.
      Use getTopicIncomingMessages or getTopicOutgoingMessages instead.

      Get EventingTestKit.Topic for mocking interactions, avoiding the need for a real broker instance.

      Parameters:
      topic - the name of the topic configured in your service which you want to mock
      Returns:
      mocked topic to read/publish messages from/to
    • getValueEntityIncomingMessages

      public EventingTestKit.IncomingMessages getValueEntityIncomingMessages(String typeId)
      Get incoming messages for ValueEntity.
      Parameters:
      typeId -
    • getEventSourcedEntityIncomingMessages

      public EventingTestKit.IncomingMessages getEventSourcedEntityIncomingMessages(String typeId)
      Get incoming messages for EventSourcedEntity.
      Parameters:
      typeId -
    • getStreamIncomingMessages

      public EventingTestKit.IncomingMessages getStreamIncomingMessages(String service, String streamId)
      Get incoming messages for Stream (eventing.in.direct in case of protobuf SDKs).
      Parameters:
      service - service name
      streamId - service stream id
    • getTopicIncomingMessages

      public EventingTestKit.IncomingMessages getTopicIncomingMessages(String topic)
      Get incoming messages for Topic.
      Parameters:
      topic - topic name
    • getTopicOutgoingMessages

      public EventingTestKit.OutgoingMessages getTopicOutgoingMessages(String topic)
      Get mocked topic destination.
      Parameters:
      topic - topic name
    • stop

      public void stop()
      Stop the testkit and local Kalix.
    • availableLocalPort

      public static int availableLocalPort()
      Get an available local port for testing.
      Returns:
      available local port
    • getMessageCodec

      @InternalApi public kalix.javasdk.impl.MessageCodec getMessageCodec()
      INTERNAL API
    • getRunner

      @InternalApi public kalix.javasdk.KalixRunner getRunner()
      INTERNAL API
    • getMessageBuilder

      public EventingTestKit.MessageBuilder getMessageBuilder()
      Returns EventingTestKit.MessageBuilder utility to create EventingTestKit.Messages for the eventing testkit.