Show / Hide Table of Contents

    Class KafkaTestingHelper

    Exposes some helper methods and shortcuts to simplify testing.

    Inheritance
    object
    TestingHelper<KafkaBroker>
    KafkaTestingHelper
    Implements
    IKafkaTestingHelper
    ITestingHelper<KafkaBroker>
    Inherited Members
    TestingHelper<KafkaBroker>.Broker
    TestingHelper<KafkaBroker>.Spy
    TestingHelper<KafkaBroker>.WaitUntilConnectedAsync(TimeSpan?)
    TestingHelper<KafkaBroker>.WaitUntilConnectedAsync(bool, TimeSpan?)
    TestingHelper<KafkaBroker>.WaitUntilAllMessagesAreConsumedAsync(TimeSpan?)
    TestingHelper<KafkaBroker>.WaitUntilOutboxIsEmptyAsync(CancellationToken)
    TestingHelper<KafkaBroker>.IsOutboxEmptyAsync()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Silverback.Testing
    Assembly: Silverback.Integration.Kafka.Testing.dll
    Syntax
    public class KafkaTestingHelper : TestingHelper<KafkaBroker>, IKafkaTestingHelper, ITestingHelper<KafkaBroker>

    Constructors

    | Improve this doc View source

    KafkaTestingHelper(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 source

    GetTopic(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>?).

    | Improve this doc View source

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

    | Improve this doc View source

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

    | Improve this doc View source

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

    | Improve this doc View source

    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
    TestingHelper<KafkaBroker>.WaitUntilAllMessagesAreConsumedAsync(bool, TimeSpan?)
    Remarks

    This method works with the mocked brokers only.

    | Improve this doc View source

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

    Implements

    IKafkaTestingHelper
    ITestingHelper<TBroker>
    • Improve this doc
    • View source
    GitHub E-Mail
    ↑ Back to top © 2020 Sergio Aquilini