Пример #1
0
        public async Task TestWithMessagesForSeconds(int seconds)
        {
            var dummySQS = new GeneratedDataSqs(MakeResponse, CancelAfterSeconds(seconds));

            int receivedCount = 0;

            async Task <bool> Handler(Message message)
            {
                await Task.Delay(50);

                Console.WriteLine($"Handled message {message.Body}");

                Interlocked.Increment(ref receivedCount);
                return(true);
            }

            var wrappedHandler = Handlers.Wrap(Handler, dummySQS, OnTiming, OnException);

            var listener = new SimpleListener(dummySQS,
                                              wrappedHandler,
                                              CancelAfterSeconds(seconds),
                                              new NullListenerLogger());

            await listener.Listen();

            Assert.True(receivedCount > 10 * seconds);
        }
Пример #2
0
        public async Task TestWithOneMessage()
        {
            var responses = MakeResponses(1);
            var dummySQS  = new FixedDataSqs(responses);

            int receivedCount = 0;

            async Task <bool> Handler(Message message)
            {
                await Task.Delay(100);

                Console.WriteLine($"Handled message {message.Body}");

                Interlocked.Increment(ref receivedCount);
                return(true);
            }

            var wrappedHandler = Handlers.Wrap(Handler, dummySQS, OnTiming, OnException);

            var listener = new SimpleListener(dummySQS,
                                              wrappedHandler,
                                              CancelAfterSeconds(1),
                                              new NullListenerLogger());

            await listener.Listen();

            Assert.Equal(1, receivedCount);
        }
Пример #3
0
        public async Task RunForASecond()
        {
            var dummySqs = new FixedDataSqs(Enumerable.Empty <ReceiveMessageResponse>());

            var listener = new SimpleListener(
                dummySqs,
                Handler,
                CancelAfterSeconds(1),
                new NullListenerLogger());

            await listener.Listen();
        }
Пример #4
0
        public async Task RunForFiveSeconds()
        {
            var dummySQS = new FixedDataSqs(Enumerable.Empty <ReceiveMessageResponse>());

            var handler = Handlers.Wrap(Handler, dummySQS, OnTiming, OnException);

            var listener = new SimpleListener(dummySQS,
                                              handler,
                                              CancelAfterSeconds(5),
                                              new NullListenerLogger());

            await listener.Listen();
        }