Exemple #1
0
    public WhenThereAreNoSubscribers(ITestOutputHelper testOutputHelper)
    {
        _outputHelper = testOutputHelper;
        var loggerFactory = testOutputHelper.ToLoggerFactory();

        MiddlewareBase <ReceiveMessagesContext, IList <Message> > sqsMiddleware =
            new DelegateMiddleware <ReceiveMessagesContext, IList <Message> >();

        var messages = new List <Message> {
            new TestMessage()
        };
        var queue = new FakeSqsQueue(ct =>
        {
            Interlocked.Increment(ref _callCount);
            return(Task.FromResult(messages.AsEnumerable()));
        });

        var monitor = new TrackingLoggingMonitor(
            loggerFactory.CreateLogger <TrackingLoggingMonitor>());

        _messageReceiveBuffer = new MessageReceiveBuffer(
            10,
            10,
            TimeSpan.FromSeconds(1),
            TimeSpan.FromSeconds(1),
            queue,
            sqsMiddleware,
            monitor,
            loggerFactory.CreateLogger <IMessageReceiveBuffer>());
    }
Exemple #2
0
    private ICollection <IMessageReceiveBuffer> CreateBuffers(
        ReceiveMiddleware receiveMiddleware,
        SubscriptionGroupSettings subscriptionGroupSettings)
    {
        var buffers = new List <IMessageReceiveBuffer>();

        var logger = _loggerFactory.CreateLogger <MessageReceiveBuffer>();

        foreach (ISqsQueue queue in subscriptionGroupSettings.Queues)
        {
            var buffer = new MessageReceiveBuffer(
                subscriptionGroupSettings.Prefetch,
                subscriptionGroupSettings.BufferSize,
                subscriptionGroupSettings.ReceiveBufferReadTimeout,
                subscriptionGroupSettings.ReceiveMessagesWaitTime,
                queue,
                receiveMiddleware,
                _monitor,
                logger);

            buffers.Add(buffer);
        }

        return(buffers);
    }
Exemple #3
0
    public WhenSqsIsSlow(ITestOutputHelper testOutputHelper)
    {
        var loggerFactory = testOutputHelper.ToLoggerFactory();

        MiddlewareBase <ReceiveMessagesContext, IList <Message> > sqsMiddleware =
            new DelegateMiddleware <ReceiveMessagesContext, IList <Message> >();

        var messages = new List <Message> {
            new TestMessage()
        };
        var queue = new FakeSqsQueue(async ct =>
        {
            await Task.Delay(100);
            Interlocked.Increment(ref _callCount);
            return(messages);
        });

        var monitor = new TrackingLoggingMonitor(
            loggerFactory.CreateLogger <TrackingLoggingMonitor>());

        _messageReceiveBuffer = new MessageReceiveBuffer(
            10,
            10,
            TimeSpan.FromSeconds(1),
            TimeSpan.FromSeconds(1),
            queue,
            sqsMiddleware,
            monitor,
            loggerFactory.CreateLogger <IMessageReceiveBuffer>());
    }
        public WhenSqsIsSlow(ITestOutputHelper testOutputHelper)
        {
            var loggerFactory = testOutputHelper.ToLoggerFactory();

            MiddlewareBase <ReceiveMessagesContext, IList <Message> > sqsMiddleware =
                new DelegateMiddleware <ReceiveMessagesContext, IList <Message> >();
            var sqsClient = Substitute.For <IAmazonSQS>();
            var queue     = Substitute.For <ISqsQueue>();

            queue.Uri.Returns(new Uri("http://test.com"));
            queue.Client.Returns(sqsClient);
            var monitor = new TrackingLoggingMonitor(
                loggerFactory.CreateLogger <TrackingLoggingMonitor>());

            sqsClient.ReceiveMessageAsync(Arg.Any <ReceiveMessageRequest>(), Arg.Any <CancellationToken>())
            .Returns(_ =>
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(100));
                Interlocked.Increment(ref _callCount);
                var messages = new List <Message> {
                    new TestMessage()
                };
                return(new ReceiveMessageResponse {
                    Messages = messages
                });
            });

            _messageReceiveBuffer = new MessageReceiveBuffer(
                10,
                10,
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(1),
                queue,
                sqsMiddleware,
                monitor,
                loggerFactory.CreateLogger <IMessageReceiveBuffer>());
        }