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
groupIdstringThe consumer group id.
Returns
Remarks
This method works with the mocked Kafka broker only. See UseMockedKafka(SilverbackBuilder, Action<IMockedKafkaOptionsBuilder>?) or AddMockedKafka(BrokerOptionsBuilder, Action<IMockedKafkaOptionsBuilder>?).
GetConsumerGroup(string, string)
Returns the IMockedConsumerGroup representing the consumer group with the specified id.
IMockedConsumerGroup GetConsumerGroup(string groupId, string bootstrapServers)
Parameters
groupIdstringThe consumer group id.
bootstrapServersstringThe bootstrap servers string used to identify the target broker.
Returns
Remarks
This method works with the mocked Kafka broker only. See UseMockedKafka(SilverbackBuilder, Action<IMockedKafkaOptionsBuilder>?) or AddMockedKafka(BrokerOptionsBuilder, Action<IMockedKafkaOptionsBuilder>?).
GetProducer(Action<KafkaProducerConfigurationBuilder>)
Gets a new producer with the specified configuration.
IProducer GetProducer(Action<KafkaProducerConfigurationBuilder> configurationBuilderAction)
Parameters
configurationBuilderActionAction<KafkaProducerConfigurationBuilder>An Action<T> that takes the KafkaProducerConfigurationBuilder and configures it.
Returns
GetTopic(string, string?)
Returns the IInMemoryTopic with the specified name.
IInMemoryTopic GetTopic(string name, string? bootstrapServers = null)
Parameters
namestringThe name of the topic.
bootstrapServersstringThe bootstrap servers string used to identify the target broker. This must be specified when testing with multiple brokers.
Returns
Remarks
This method works with the mocked Kafka broker only. See UseMockedKafka(SilverbackBuilder, Action<IMockedKafkaOptionsBuilder>?) or AddMockedKafka(BrokerOptionsBuilder, Action<IMockedKafkaOptionsBuilder>?).
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
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the offsets aren't committed before the timeout elapses.
timeoutTimeSpan?The time to wait for the message offsets to be committed. The default is 30 seconds.
Returns
Remarks
This method works with the mocked Kafka broker only and does not force offset commits.
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
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the offsets aren't committed before the timeout elapses.
timeoutTimeSpan?The time to wait for the message offsets to be committed. The default is 30 seconds.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, all endpoints are considered.
Returns
Remarks
This method works with the mocked Kafka broker only and does not force offset commits.
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
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the offsets aren't committed before the timeout elapses.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, all endpoints are considered.
Returns
Remarks
This method works with the mocked Kafka broker only and does not force offset commits.
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
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the offsets aren't committed before the CancellationToken is canceled.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, all endpoints are considered.
Returns
Remarks
This method works with the mocked Kafka broker only and does not force offset commits.
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
timeoutTimeSpan?The time to wait for the message offsets to be committed. The default is 30 seconds.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, all endpoints are considered.
Returns
Remarks
This method works with the mocked Kafka broker only and does not force offset commits.
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
endpointNamesstring[]The names of the endpoints to wait for. If not specified, all endpoints are considered.
Returns
Remarks
This method works with the mocked Kafka broker only and does not force offset commits.
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
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, all endpoints are considered.
Returns
Remarks
This method works with the mocked Kafka broker only and does not force offset commits.