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 Type
    Method
    Description
    Clear the topic so any existing messages are not considered on subsequent expect call.
    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.
    expectN(int total, Duration timeout)
    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 (see TopicImpl$.DefaultTimeout() for default value).
    void
    Waits for given amount of time.
    Waits for predefined amount of time (see TopicImpl$.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>
    Waits and returns the next unread message on this topic.
    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.
    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 multiple messages to this topic for the purposes of testing incoming message flow.
    void
    Simulate the publishing of a message to this topic for the purposes of testing incoming message flow.
    <T> void
    publish(T message, String subject)
    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 topic
      metadata - associated with the message
    • publish

      void publish(EventingTestKit.Message<?> message)
      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

      <T> void publish(T message, String subject)
      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 topic
      subject - to identify the entity
    • publish

      void publish(List<EventingTestKit.Message<?>> messages)
      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 (see TopicImpl$.DefaultTimeout() for default value). If a message arrives in the meantime or has arrived before but was not consumed, the test fails.
    • expectNone

      void expectNone(Duration timeout)
      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

      EventingTestKit.Message<com.google.protobuf.ByteString> expectOneRaw(Duration timeout)
      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 (see TopicImpl$.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

      EventingTestKit.Message<?> expectOne(Duration timeout)
      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

      <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.
      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

      <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. 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

      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

      List<EventingTestKit.Message<?>> expectN(int total)
      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

      List<EventingTestKit.Message<?>> expectN(int total, Duration timeout)
      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 returning
      timeout - maximum amount of time to wait for the messages
      Returns:
      list of messages, each message including the deserialized payload object and metadata
    • 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.