Table of Contents

Interface IKafkaTestingHelper

Namespace
Silverback.Testing
Assembly
Silverback.Integration.Kafka.Testing.dll

Exposes some helper methods and shortcuts to simplify testing.

public interface IKafkaTestingHelper : ITestingHelper
Inherited Members

Properties

ConsumerGroups

Gets a collection of IMockedConsumerGroup representing all known consumer groups.

IReadOnlyCollection<IMockedConsumerGroup> ConsumerGroups { get; }

Property Value

IReadOnlyCollection<IMockedConsumerGroup>

The collection of IMockedConsumerGroup.

Methods

GetConsumerGroup(string)

Returns the IMockedConsumerGroup representing the consumer group with the specified id.

IMockedConsumerGroup GetConsumerGroup(string groupId)

Parameters

groupId string

The consumer group id.

Returns

IMockedConsumerGroup

The IMockedConsumerGroup.

Remarks

Exceptions

InvalidOperationException

No consumer group with the specified id exists, or more than one exists (with different bootstrap servers).

GetConsumerGroup(string, string)

Returns the IMockedConsumerGroup representing the consumer group with the specified id.

IMockedConsumerGroup GetConsumerGroup(string groupId, string bootstrapServers)

Parameters

groupId string

The consumer group id.

bootstrapServers string

The bootstrap servers string used to identify the target broker.

Returns

IMockedConsumerGroup

The IMockedConsumerGroup.

Remarks

Exceptions

InvalidOperationException

No consumer group with the specified id exists for the specified bootstrap servers.

GetProducer(Action<KafkaProducerConfigurationBuilder>)

Gets a new producer with the specified configuration.

IProducer GetProducer(Action<KafkaProducerConfigurationBuilder> configurationBuilderAction)

Parameters

configurationBuilderAction Action<KafkaProducerConfigurationBuilder>

An Action<T> that takes the KafkaProducerConfigurationBuilder and configures it.

Returns

IProducer

The IProducer.

Exceptions

BrokerConfigurationException

The producer configuration is not valid.

InvalidOperationException

The Kafka integration hasn't been added (AddKafka hasn't been called), the configuration defines more than one producer endpoint, or a producer endpoint with the same name has already been added.

GetTopic(string, string?)

Returns the IInMemoryTopic with the specified name.

IInMemoryTopic GetTopic(string name, string? bootstrapServers = null)

Parameters

name string

The name of the topic. Must not be empty.

bootstrapServers string

The bootstrap servers string used to identify the target broker. This must be specified when testing with multiple brokers. If specified, it must not be empty.

Returns

IInMemoryTopic

The IInMemoryTopic.

Remarks

Exceptions

InvalidOperationException

The bootstrapServers aren't specified and either more than one topic with the specified name exists, or the topic doesn't exist and the existing topics don't belong to exactly one broker (for example, because no topic exists yet).

WaitUntilAllMessagesAreCommittedAsync(bool, TimeSpan?)

Returns a ValueTask that completes when the offsets of all messages routed to the consumers have been committed to the mocked Kafka broker.

ValueTask WaitUntilAllMessagesAreCommittedAsync(bool throwTimeoutException, TimeSpan? timeout = null)

Parameters

throwTimeoutException bool

A value specifying whether a TimeoutException has to be thrown when the offsets aren't committed before the timeout elapses.

timeout TimeSpan?

The time to wait for the message offsets to be committed. The default is 30 seconds.

Returns

ValueTask

A ValueTask that completes when all message offsets have been committed.

Remarks

This method works with the mocked Kafka broker only and does not force offset commits.

Exceptions

TimeoutException

The throwTimeoutException is true and the timeout elapsed before all message offsets were committed.

WaitUntilAllMessagesAreCommittedAsync(bool, TimeSpan?, params string[])

Returns a ValueTask that completes when the offsets of all messages routed to the consumers have been committed to the mocked Kafka broker.

ValueTask WaitUntilAllMessagesAreCommittedAsync(bool throwTimeoutException, TimeSpan? timeout, params string[] endpointNames)

Parameters

throwTimeoutException bool

A value specifying whether a TimeoutException has to be thrown when the offsets aren't committed before the timeout elapses.

timeout TimeSpan?

The time to wait for the message offsets to be committed. The default is 30 seconds.

endpointNames string[]

The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.

Returns

ValueTask

A ValueTask that completes when all message offsets have been committed.

Remarks

This method works with the mocked Kafka broker only and does not force offset commits.

Exceptions

TimeoutException

The throwTimeoutException is true and the timeout elapsed before all message offsets were committed.

InvalidOperationException

One of the endpointNames doesn't match any endpoint.

WaitUntilAllMessagesAreCommittedAsync(bool, params string[])

Returns a ValueTask that completes when the offsets of all messages routed to the consumers have been committed to the mocked Kafka broker.

ValueTask WaitUntilAllMessagesAreCommittedAsync(bool throwTimeoutException, params string[] endpointNames)

Parameters

throwTimeoutException bool

A value specifying whether a TimeoutException has to be thrown when the offsets aren't committed before the timeout elapses.

endpointNames string[]

The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.

Returns

ValueTask

A ValueTask that completes when all message offsets have been committed.

Remarks

This method works with the mocked Kafka broker only and does not force offset commits.

Exceptions

TimeoutException

The throwTimeoutException is true and the default timeout elapsed before all message offsets were committed.

InvalidOperationException

One of the endpointNames doesn't match any endpoint.

WaitUntilAllMessagesAreCommittedAsync(bool, CancellationToken, params string[])

Returns a ValueTask that completes when the offsets of all messages routed to the consumers have been committed to the mocked Kafka broker.

ValueTask WaitUntilAllMessagesAreCommittedAsync(bool throwTimeoutException, CancellationToken cancellationToken, params string[] endpointNames)

Parameters

throwTimeoutException bool

A value specifying whether a TimeoutException has to be thrown when the offsets aren't committed before the CancellationToken is canceled.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

endpointNames string[]

The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.

Returns

ValueTask

A ValueTask that completes when all message offsets have been committed.

Remarks

This method works with the mocked Kafka broker only and does not force offset commits.

Exceptions

TimeoutException

The throwTimeoutException is true and the cancellationToken was canceled before all message offsets were committed.

InvalidOperationException

One of the endpointNames doesn't match any endpoint.

WaitUntilAllMessagesAreCommittedAsync(TimeSpan?, params string[])

Returns a ValueTask that completes when the offsets of all messages routed to the consumers have been committed to the mocked Kafka broker.

ValueTask WaitUntilAllMessagesAreCommittedAsync(TimeSpan? timeout, params string[] endpointNames)

Parameters

timeout TimeSpan?

The time to wait for the message offsets to be committed. The default is 30 seconds.

endpointNames string[]

The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.

Returns

ValueTask

A ValueTask that completes when all message offsets have been committed.

Remarks

This method works with the mocked Kafka broker only and does not force offset commits.

Exceptions

TimeoutException

The timeout elapsed before all message offsets were committed.

InvalidOperationException

One of the endpointNames doesn't match any endpoint.

WaitUntilAllMessagesAreCommittedAsync(params string[])

Returns a ValueTask that completes when the offsets of all messages routed to the consumers have been committed to the mocked Kafka broker.

ValueTask WaitUntilAllMessagesAreCommittedAsync(params string[] endpointNames)

Parameters

endpointNames string[]

The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.

Returns

ValueTask

A ValueTask that completes when all message offsets have been committed.

Remarks

This method works with the mocked Kafka broker only and does not force offset commits.

Exceptions

TimeoutException

The default timeout elapsed before all message offsets were committed.

InvalidOperationException

One of the endpointNames doesn't match any endpoint.

WaitUntilAllMessagesAreCommittedAsync(CancellationToken, params string[])

Returns a ValueTask that completes when the offsets of all messages routed to the consumers have been committed to the mocked Kafka broker.

ValueTask WaitUntilAllMessagesAreCommittedAsync(CancellationToken cancellationToken, params string[] endpointNames)

Parameters

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

endpointNames string[]

The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.

Returns

ValueTask

A ValueTask that completes when all message offsets have been committed.

Remarks

This method works with the mocked Kafka broker only and does not force offset commits.

Exceptions

TimeoutException

The cancellationToken was canceled before all message offsets were committed.

InvalidOperationException

One of the endpointNames doesn't match any endpoint.