Class KafkaTestingHelper
Exposes some helper methods and shortcuts to simplify testing.
Inherited Members
Namespace: Silverback.Testing
Assembly: Silverback.Integration.Kafka.Testing.dll
Syntax
public class KafkaTestingHelper : TestingHelper<KafkaBroker>, IKafkaTestingHelper, ITestingHelper<KafkaBroker>
Constructors
| Improve this doc View sourceKafkaTestingHelper(IServiceProvider, ILogger<KafkaTestingHelper>)
Initializes a new instance of the KafkaTestingHelper class.
Declaration
public KafkaTestingHelper(IServiceProvider serviceProvider, ILogger<KafkaTestingHelper> logger)
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | serviceProvider | The IServiceProvider. |
ILogger<KafkaTestingHelper> | logger | The ISilverbackLogger. |
Methods
| Improve this doc View sourceGetTopic(string)
Returns the IInMemoryTopic with the specified name.
Declaration
public IInMemoryTopic GetTopic(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the topic. |
Returns
Type | Description |
---|---|
IInMemoryTopic | The IInMemoryTopic. |
Remarks
This method works with the mocked Kafka broker only. See UseMockedKafka(ISilverbackBuilder, Action<IMockedKafkaOptionsBuilder>?) or AddMockedKafka(IBrokerOptionsBuilder, Action<IMockedKafkaOptionsBuilder>?).
GetTopic(string, string)
Returns the IInMemoryTopic with the specified name.
Declaration
public IInMemoryTopic GetTopic(string name, string bootstrapServers)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the topic. |
string | bootstrapServers | The bootstrap servers string used to identify the target broker. |
Returns
Type | Description |
---|---|
IInMemoryTopic | The IInMemoryTopic. |
Remarks
This method works with the mocked Kafka broker only. See UseMockedKafka(ISilverbackBuilder, Action<IMockedKafkaOptionsBuilder>?) or AddMockedKafka(IBrokerOptionsBuilder, Action<IMockedKafkaOptionsBuilder>?).
GetTopics(string, string?)
Returns the collection of IInMemoryTopic with the specified name.
Declaration
public IReadOnlyCollection<IInMemoryTopic> GetTopics(string name, string? bootstrapServers = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the topic. |
string | bootstrapServers | The bootstrap servers string used to identify the target broker. |
Returns
Type | Description |
---|---|
IReadOnlyCollection<IInMemoryTopic> | The collection of IInMemoryTopic. |
Remarks
This method works with the mocked Kafka broker only. See UseMockedKafka(ISilverbackBuilder, Action<IMockedKafkaOptionsBuilder>?) or AddMockedKafka(IBrokerOptionsBuilder, Action<IMockedKafkaOptionsBuilder>?).
WaitUntilAllMessagesAreConsumedAsync(bool, IReadOnlyCollection<string>, TimeSpan?)
Returns a Task that completes when all messages routed to the consumers have been processed and committed.
Declaration
public Task WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, IReadOnlyCollection<string> topicNames, TimeSpan? timeout = null)
Parameters
Type | Name | Description |
---|---|---|
bool | throwTimeoutException | |
IReadOnlyCollection<string> | topicNames | The name of the topics to be monitored. |
TimeSpan? | timeout | The time to wait for the messages to be consumed and processed. The default is 30 seconds. |
Returns
Type | Description |
---|---|
Task | A Task that completes when all messages have been processed. |
Remarks
This method works with the mocked Kafka broker only. See UseMockedKafka(ISilverbackBuilder, Action<IMockedKafkaOptionsBuilder>?) or AddMockedKafka(IBrokerOptionsBuilder, Action<IMockedKafkaOptionsBuilder>?).
WaitUntilAllMessagesAreConsumedAsync(bool, TimeSpan?)
Returns a Task that completes when all messages routed to the consumers have been processed and committed.
Declaration
public override Task WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, TimeSpan? timeout = null)
Parameters
Type | Name | Description |
---|---|---|
bool | throwTimeoutException | A value specifying whether a TimeoutException has to be thrown when the messages aren't consumed before the timeout expires. |
TimeSpan? | timeout | The time to wait for the messages to be consumed and processed. The default is 30 seconds. |
Returns
Type | Description |
---|---|
Task | A Task that completes when all messages have been processed. |
Overrides
Remarks
This method works with the mocked brokers only.
WaitUntilAllMessagesAreConsumedAsync(IReadOnlyCollection<string>, TimeSpan?)
Returns a Task that completes when all messages routed to the consumers have been processed and committed.
Declaration
public Task WaitUntilAllMessagesAreConsumedAsync(IReadOnlyCollection<string> topicNames, TimeSpan? timeout = null)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyCollection<string> | topicNames | The name of the topics to be monitored. |
TimeSpan? | timeout | The time to wait for the messages to be consumed and processed. The default is 30 seconds. |
Returns
Type | Description |
---|---|
Task | A Task that completes when all messages have been processed. |
Remarks
This method works with the mocked Kafka broker only. See UseMockedKafka(ISilverbackBuilder, Action<IMockedKafkaOptionsBuilder>?) or AddMockedKafka(IBrokerOptionsBuilder, Action<IMockedKafkaOptionsBuilder>?).