Example #1
0
    public async Task QueueMonitor_GetCurrentState_MultipleMessages_ReadyMessagesGreaterZero()
    {
        var builder = RabbitMQTestBuilder
                      .CreateWithQueueDeclare(_fixture)
                      .WithMultipleRandomPublishedMessage()
                      .Build();

        var monitor = new RabbitMQQueueMonitor <string>(
            Mock.Of <ILogger <RabbitMQQueueMonitor <string> > >(),
            Opts.Create(new RabbitMQConsumerOptions <string>
        {
            Queue =
            {
                Name = builder.QueueName
            }
        }),
            _fixture.ConnectionFactory <string>()
            );

        var state = await monitor.GetCurrentState();

        Assert.Equal(builder.QueueName, state.QueueName);
        Assert.Equal(0, state.ConsumerCount);
        Assert.Equal(RabbitMQTestBuilder.PrefetchCount, state.ReadyMessages);
    }
Example #2
0
    public async Task QueueMonitor_GetCurrentState_ActiveConsumer_ConsumerCountGreaterZero()
    {
        var builder = RabbitMQTestBuilder
                      .CreateWithQueueDeclare(_fixture)
                      .WithMultipleRandomPublishedMessage()
                      .Build();

        var random   = new Random();
        var consumer = builder.GetConsumer <string>();

        consumer.ConsumeCallbackAsync = async(_, token) =>
        {
            await Task.Delay(random.Next(500), token);

            return(ProcessedMessageStatus.Success);
        };

        await consumer.StartAsync();

        var monitor = new RabbitMQQueueMonitor <string>(
            Mock.Of <ILogger <RabbitMQQueueMonitor <string> > >(),
            Opts.Create(new RabbitMQConsumerOptions <string>
        {
            Queue =
            {
                Name = builder.QueueName
            }
        }),
            _fixture.ConnectionFactory <string>()
            );

        var state = await monitor.GetCurrentState();

        Assert.Equal(builder.QueueName, state.QueueName);
        Assert.Equal(1, state.ConsumerCount);
        Assert.InRange(state.ReadyMessages, 0, RabbitMQTestBuilder.PrefetchCount);
    }