Package akka.javasdk.testkit
Class TestKit
Object
akka.javasdk.testkit.TestKit
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classSettings for testkit. -
Constructor Summary
ConstructorsConstructorDescriptionTestKit()Create a new testkit for a service descriptor with the default settings.TestKit(TestKit.Settings settings) Create a new testkit for a service descriptor with custom settings. -
Method Summary
Modifier and TypeMethodDescriptionstatic intGet an available local port for testing.akka.actor.typed.ActorSystem<?> Get anActorSystemfor creating Akka HTTP clients.akka.javasdk.agent.AgentRegistrycom.typesafe.config.Configakka.javasdk.client.ComponentClientGet anComponentClientfor interacting "internally" with the components of a service.static StringgetComponentDescription(Class<?> componentClass) Utility method to get the component description from a component class.static StringgetComponentIdValue(Class<?> componentClass) Utility method to get the component ID from a component class.static StringgetComponentName(Class<?> componentClass) Utility method to get the component name from a component class.Optional<akka.javasdk.DependencyProvider> getEventSourcedEntityIncomingMessages(Class<? extends akka.javasdk.eventsourcedentity.EventSourcedEntity<?, ?>> eventSourcedEntityClass) Get incoming messages for EventSourcedEntity.akka.javasdk.grpc.GrpcClientProviderGet aGrpcClientProviderfor looking up gRPC clients to interact with services other than the current.<T extends akka.grpc.javadsl.AkkaGrpcClient>
TgetGrpcEndpointClient(Class<T> grpcClientClass) Get a gRPC client for an endpoint provided by this service.<T extends akka.grpc.javadsl.AkkaGrpcClient>
TgetGrpcEndpointClient(Class<T> grpcClientClass, akka.javasdk.Principal requestPrincipal) Get a gRPC client for an endpoint provided by this service but specify the client principal for the ACLs.getHost()Get the host name/IP address where the service is available.akka.javasdk.http.HttpClientProviderGet aHttpClientProviderfor looking up HTTP clients to interact with other services than the current.kalix.runtime.telemetry.tracing.TracingSetup.AkkaInMemorySpanExportergetKeyValueEntityIncomingMessages(Class<? extends akka.javasdk.keyvalueentity.KeyValueEntity<?>> keyValueEntityClass) Get incoming messages for KeyValueEntity.akka.stream.MaterializerAn Akka Stream materializer to use for running streams.ReturnsEventingTestKit.MessageBuilderutility to createEventingTestKit.Messages for the eventing testkit.Registry for managing gRPC service mocks on the running testkit.Registry for managing HTTP service mocks on the running testkit.intgetPort()Get the local port where the service is available.akka.javasdk.Sanitizerakka.javasdk.http.HttpClientGet aHttpClientfor interacting with the service itself, the client will not be authenticated and will appear to the service as a request with the internet principal.getStreamIncomingMessages(String service, String streamId) Get incoming messages for Consume.ServiceStream.getStreamOutgoingMessages(String service, String streamId) Get outgoing messages produced by a@Produce.ServiceStreamproducer in the service under test.akka.javasdk.timer.TimerSchedulerGet aTimerSchedulerfor scheduling TimedAction.getTopicIncomingMessages(String topic) Get incoming messages for Topic.getTopicOutgoingMessages(String topic) Get mocked topic destination.getWorkflowIncomingMessages(Class<? extends akka.javasdk.workflow.Workflow<?>> workflowClass) Get incoming messages for Workflow.start()Start this testkit with default configuration.voidstop()Stop the testkit and local runtime.
-
Constructor Details
-
TestKit
public TestKit()Create a new testkit for a service descriptor with the default settings. -
TestKit
Create a new testkit for a service descriptor with custom settings.- Parameters:
settings- custom testkit settings
-
-
Method Details
-
start
Start this testkit with default configuration. The default configuration is loaded fromapplication-test.confif that exists, otherwise fromapplication.conf.- Returns:
- this TestKit instance
-
getHost
Get the host name/IP address where the service is available. This is relevant in certain Continuous Integration environments. -
getPort
public int getPort()Get the local port where the service is available. -
getApplicationConfig
public com.typesafe.config.Config getApplicationConfig()- Returns:
- The config as the components of the service under test sees it, if injected.
-
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.typed.ActorSystem<?> getActorSystem()Get anActorSystemfor creating Akka HTTP clients.- Returns:
- test actor system
-
getComponentClient
public akka.javasdk.client.ComponentClient getComponentClient()Get anComponentClientfor interacting "internally" with the components of a service. -
getTimerScheduler
public akka.javasdk.timer.TimerScheduler getTimerScheduler()Get aTimerSchedulerfor scheduling TimedAction. -
getHttpClientProvider
public akka.javasdk.http.HttpClientProvider getHttpClientProvider()Get aHttpClientProviderfor looking up HTTP clients to interact with other services than the current. Requests will appear as coming from this service from an ACL perspective. -
getGrpcClientProvider
public akka.javasdk.grpc.GrpcClientProvider getGrpcClientProvider()Get aGrpcClientProviderfor looking up gRPC clients to interact with services other than the current. Requests will appear as coming from this service from an ACL perspective. -
getMockedHttpServices
Registry for managing HTTP service mocks on the running testkit. Lets individual tests install or replace handlers without re-creating the testkit; callMockedHttpServices.reset()in an@AfterEachto restore the mocks declared viaTestKit.Settings.withMockedHttpService(String, java.util.function.Function). -
getMockedGrpcServices
Registry for managing gRPC service mocks on the running testkit. Lets individual tests install or replace mock instances without re-creating the testkit; callMockedGrpcServices.reset()in an@AfterEachto restore the mocks declared viaTestKit.Settings.withMockedGrpcService(String, Class, AkkaGrpcClient). -
getGrpcEndpointClient
public <T extends akka.grpc.javadsl.AkkaGrpcClient> T getGrpcEndpointClient(Class<T> grpcClientClass) Get a gRPC client for an endpoint provided by this service. Requests will appear as coming from this service itself from an ACL perspective.- Parameters:
grpcClientClass- The generated Akka gRPC client interface for a gRPC endpoint in this service
-
getGrpcEndpointClient
public <T extends akka.grpc.javadsl.AkkaGrpcClient> T getGrpcEndpointClient(Class<T> grpcClientClass, akka.javasdk.Principal requestPrincipal) Get a gRPC client for an endpoint provided by this service but specify the client principal for the ACLs.- Parameters:
grpcClientClass- The generated Akka gRPC client interface for a gRPC endpoint in this servicerequestPrincipal- A principal that any request from the returned service will have when requests are handled in the endpoint.
-
getSelfHttpClient
public akka.javasdk.http.HttpClient getSelfHttpClient()Get aHttpClientfor interacting with the service itself, the client will not be authenticated and will appear to the service as a request with the internet principal. -
getSelfSseRouteTester
-
getSelfWebSocketRouteTester
-
getInMemorySpanExporter
public kalix.runtime.telemetry.tracing.TracingSetup.AkkaInMemorySpanExporter getInMemorySpanExporter() -
getKeyValueEntityIncomingMessages
public EventingTestKit.IncomingMessages getKeyValueEntityIncomingMessages(Class<? extends akka.javasdk.keyvalueentity.KeyValueEntity<?>> keyValueEntityClass) Get incoming messages for KeyValueEntity. -
getEventSourcedEntityIncomingMessages
public EventingTestKit.IncomingMessages getEventSourcedEntityIncomingMessages(Class<? extends akka.javasdk.eventsourcedentity.EventSourcedEntity<?, ?>> eventSourcedEntityClass) Get incoming messages for EventSourcedEntity. -
getComponentIdValue
Utility method to get the component ID from a component class.- Parameters:
componentClass- the component class annotated with @Component- Returns:
- the component ID
-
getComponentName
Utility method to get the component name from a component class.- Parameters:
componentClass- the component class annotated with @Component- Returns:
- the component name, or null if not specified or using @ComponentId
-
getComponentDescription
Utility method to get the component description from a component class.- Parameters:
componentClass- the component class annotated with @Component- Returns:
- the component description, or null if not specified or using @ComponentId
-
getWorkflowIncomingMessages
public EventingTestKit.IncomingMessages getWorkflowIncomingMessages(Class<? extends akka.javasdk.workflow.Workflow<?>> workflowClass) Get incoming messages for Workflow. -
getStreamIncomingMessages
Get incoming messages for Consume.ServiceStream.- Parameters:
service- service namestreamId- service stream id
-
getTopicIncomingMessages
Get incoming messages for Topic.- Parameters:
topic- topic name
-
getTopicOutgoingMessages
Get mocked topic destination.- Parameters:
topic- topic name
-
getStreamOutgoingMessages
Get outgoing messages produced by a@Produce.ServiceStreamproducer in the service under test. Theservicemust match the service name used by consumers in their@Consume.FromServiceStreamannotation.Note: the
servicevalue is used by the testkit as a lookup key (and must match what was registered viaTestKit.Settings.withStreamOutgoingMessages(String, String)); the underlying subscription itself is resolved against the service-under-test bystreamId.Each call returns a handle whose subscription replays events from the beginning of the stream. In a suite that shares a single
TestKitacross multiple tests, callEventingTestKit.OutgoingMessages.clear()at the start of each test to drop events produced by prior tests.- Parameters:
service- service namestreamId- service stream id
-
getAgentRegistry
public akka.javasdk.agent.AgentRegistry getAgentRegistry() -
getSanitizer
public akka.javasdk.Sanitizer getSanitizer()- Returns:
- The configured sanitizer for the service, for test assertions that the expected anonymization is applied. Will always return an instance, if no sanitization rules are configured, the returned sanitizer will return all text fed to it as is.
-
stop
public void stop()Stop the testkit and local runtime. -
availableLocalPort
public static int availableLocalPort()Get an available local port for testing.- Returns:
- available local port
-
getMessageBuilder
ReturnsEventingTestKit.MessageBuilderutility to createEventingTestKit.Messages for the eventing testkit. -
getDependencyProvider
- Returns:
- The custom dependency provider used in this test, if one is defined, when overriding
the dependency provided through
TestKit.Settings.withDependencyProvider(DependencyProvider)the overridden provider is returned.
-