Table of Contents

Class KafkaTestingHelper

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

Exposes some helper methods and shortcuts to simplify testing.

public class KafkaTestingHelper : TestingHelper, IKafkaTestingHelper, ITestingHelper
Inheritance
KafkaTestingHelper
Implements
Inherited Members

Constructors

KafkaTestingHelper(IServiceProvider, ILogger<KafkaTestingHelper>)

Initializes a new instance of the KafkaTestingHelper class.

public KafkaTestingHelper(IServiceProvider serviceProvider, ILogger<KafkaTestingHelper> logger)

Parameters

serviceProvider IServiceProvider

The IServiceProvider.

logger ILogger<KafkaTestingHelper>

The ISilverbackLogger.

Properties

ConsumerGroups

Gets a collection of IMockedConsumerGroup representing all known consumer groups.

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

public IMockedConsumerGroup GetConsumerGroup(string groupId)

Parameters

groupId string

The consumer group id.

Returns

IMockedConsumerGroup

The IMockedConsumerGroup.

Remarks

GetConsumerGroup(string, string)

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

public 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

GetProducer(Action<KafkaProducerConfigurationBuilder>)

Gets a new producer with the specified configuration.

public IProducer GetProducer(Action<KafkaProducerConfigurationBuilder> configurationBuilderAction)

Parameters

configurationBuilderAction Action<KafkaProducerConfigurationBuilder>

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

Returns

IProducer

The IProducer.

GetProducerForConsumer(IConsumerCollection, string)

Gets an existing producer for the endpoint consumed by the specified consumer or initializes a new one mirroring the consumer configuration.

protected override IProducer? GetProducerForConsumer(IConsumerCollection consumers, string endpointName)

Parameters

consumers IConsumerCollection

The existing consumers.

endpointName string

The endpoint name. It could be either the topic/queue name or the friendly name.

Returns

IProducer

The IProducer.

GetTopic(string, string?)

Returns the IInMemoryTopic with the specified name.

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

Parameters

name string

The name of the topic.

bootstrapServers string

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

Returns

IInMemoryTopic

The IInMemoryTopic.

Remarks

WaitUntilAllMessagesAreConsumedCoreAsync(IReadOnlyCollection<string>, CancellationToken)

Returns a ValueTask that completes when all messages routed to the consumers have been processed and committed.

protected override Task WaitUntilAllMessagesAreConsumedCoreAsync(IReadOnlyCollection<string> endpointNames, CancellationToken cancellationToken)

Parameters

endpointNames IReadOnlyCollection<string>

The names of the endpoints to wait for. If not specified, all endpoints are considered.

cancellationToken CancellationToken

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

Returns

Task

A ValueTask that completes when all messages have been processed.

Remarks

This method works with the mocked brokers only.