Package kalix.javasdk.testkit
Interface EventingTestKit.Topic
- Enclosing interface:
- EventingTestKit
@ApiMayChange
public static interface EventingTestKit.Topic
Testkit utility to mock broker's topic. Useful when doing integration tests for services that do incoming/outgoing flow of events.
Note: messages written to the topic with this utility are not readable with the expect* methods, unless they have been properly forwarded through a outgoing event to the same topic.
-
Method Summary
Modifier and TypeMethodDescriptionclear()
Clear the topic so any existing messages are not considered on subsequent expect call.expectN()
Waits for a default amount of time before returning all unread messages in the topic.expectN
(int total) Waits for a given amount of unread messages to be received before returning.Waits for a given amount of unread messages to be received before returning up to a given timeout.void
Waits for predefined amount of time (seeTopicImpl$.DefaultTimeout()
for default value).void
expectNone
(Duration timeout) Waits for given amount of time.Waits for predefined amount of time (seeTopicImpl$.DefaultTimeout()
for default value) and returns the next unread message on this topic.Waits for a specific amount and returns the next unread message on this topic.EventingTestKit.Message<com.google.protobuf.ByteString>
Waits and returns the next unread message on this topic.EventingTestKit.Message<com.google.protobuf.ByteString>
expectOneRaw
(Duration timeout) Waits and returns the next unread message on this topic.<T> EventingTestKit.Message<T>
expectOneTyped
(Class<T> instance) Waits and returns the next unread message on this topic and automatically parses and casts it to the specified given type.<T> EventingTestKit.Message<T>
expectOneTyped
(Class<T> instance, Duration timeout) Waits and returns the next unread message on this topic and automatically parses and casts it to the specified given type.void
publish
(com.google.protobuf.ByteString message) Simulate the publishing of a raw message to this topic for the purposes of testing incoming message flow.void
publish
(com.google.protobuf.ByteString message, kalix.javasdk.Metadata metadata) Simulate the publishing of a raw message to this topic for the purposes of testing incoming message flow.void
publish
(List<EventingTestKit.Message<?>> messages) Publish multiple messages to this topic for the purposes of testing incoming message flow.void
publish
(EventingTestKit.Message<?> message) Simulate the publishing of a message to this topic for the purposes of testing incoming message flow.<T> void
Simulate the publishing of a message to this topic for the purposes of testing incoming message flow.
-
Method Details
-
publish
void publish(com.google.protobuf.ByteString message) Simulate the publishing of a raw message to this topic for the purposes of testing incoming message flow.- Parameters:
message
- raw bytestring to be published in the topic
-
publish
void publish(com.google.protobuf.ByteString message, kalix.javasdk.Metadata metadata) Simulate the publishing of a raw message to this topic for the purposes of testing incoming message flow.- Parameters:
message
- raw bytestring to be published in the topicmetadata
- associated with the message
-
publish
Simulate the publishing of a message to this topic for the purposes of testing incoming message flow.- Parameters:
message
- to be published in the topic
-
publish
Simulate the publishing of a message to this topic for the purposes of testing incoming message flow.- Type Parameters:
T
-- Parameters:
message
- to be published in the topicsubject
- to identify the entity
-
publish
Publish multiple messages to this topic for the purposes of testing incoming message flow.- Parameters:
messages
- to be published in the topic
-
expectNone
void expectNone()Waits for predefined amount of time (seeTopicImpl$.DefaultTimeout()
for default value). If a message arrives in the meantime or has arrived before but was not consumed, the test fails. -
expectNone
Waits for given amount of time. If a message arrives in the meantime or has arrived before but was not consumed, the test fails.- Parameters:
timeout
- amount of time to wait for a message
-
expectOneRaw
EventingTestKit.Message<com.google.protobuf.ByteString> expectOneRaw()Waits and returns the next unread message on this topic. Note the message might have been received before this method was called. If no message is received, a timeout exception is thrown.- Returns:
- a Message with a ByteString payload
-
expectOneRaw
Waits and returns the next unread message on this topic. Note the message might have been received before this method was called. If no message is received, a timeout exception is thrown.- Parameters:
timeout
- amount of time to wait for a message- Returns:
- a Message with a ByteString payload
-
expectOne
EventingTestKit.Message<?> expectOne()Waits for predefined amount of time (seeTopicImpl$.DefaultTimeout()
for default value) and returns the next unread message on this topic. Note the message might have been received before this method was called. If no message is received, a timeout exception is thrown.- Returns:
- message including ByteString payload and metadata
-
expectOne
Waits for a specific amount and returns the next unread message on this topic. Note the message might have been received before this method was called. If no message is received, a timeout exception is thrown.- Parameters:
timeout
- amount of time to wait for a message if it was not received already- Returns:
- message including ByteString payload and metadata
-
expectOneTyped
Waits and returns the next unread message on this topic and automatically parses and casts it to the specified given type.- Type Parameters:
T
- a given domain type- Parameters:
instance
- class type to cast the received message bytes to- Returns:
- a Message of type T
-
expectOneTyped
Waits and returns the next unread message on this topic and automatically parses and casts it to the specified given type. Note the message might have been received before this method was called. If no message is received, a timeout exception is thrown.- Parameters:
timeout
- amount of time to wait for a message if it was not received already- Returns:
- message including ByteString payload and metadata
-
expectN
List<EventingTestKit.Message<?>> expectN()Waits for a default amount of time before returning all unread messages in the topic. If no message is received, a timeout exception is thrown.- Returns:
- list of messages, each message including the deserialized payload object and metadata
-
expectN
Waits for a given amount of unread messages to be received before returning. If no message is received, a timeout exception is thrown.- Parameters:
total
- number of messages to wait for before returning- Returns:
- list of messages, each message including the deserialized payload object and metadata
-
expectN
Waits for a given amount of unread messages to be received before returning up to a given timeout. If no message is received, a timeout exception is thrown.- Parameters:
total
- number of messages to wait for before returningtimeout
- maximum amount of time to wait for the messages- Returns:
- list of messages, each message including the deserialized payload object and metadata
-
clear
List<EventingTestKit.Message<?>> clear()Clear the topic so any existing messages are not considered on subsequent expect call.- Returns:
- the list of the unread messages when the topic was cleared.
-