Beispiel #1
0
        public async Task AsyncRequestMessagePipelineShouldFireHandlers()
        {
            var preRequestHandledCount  = 0;
            var postRequestHandledCount = 0;
            var handled = false;
            var message = new TestAsyncRequestMessage
            {
                PreRequestAction = () =>
                {
                    preRequestHandledCount++;
                },
                HandlerAction = () =>
                {
                    handled = true;
                },
                PostRequestAction = () =>
                {
                    postRequestHandledCount++;
                }
            };

            await _dispatcher.HandleAsync(message);

            preRequestHandledCount.ShouldBe(3);
            postRequestHandledCount.ShouldBe(3);
            handled.ShouldBe(true);
        }
Beispiel #2
0
        public void Should_be_able_to_make_many_async_requests()
        {
            const int numberOfCalls  = 500;
            var       countdownEvent = new CountdownEvent(numberOfCalls);
            var       count          = 0;

            for (int i = 0; i < 1000; i++)
            {
                var request = new TestAsyncRequestMessage {
                    Text = "Hello async from the client! " + i
                };

                using (var publishChannel = bus.OpenPublishChannel())
                {
                    publishChannel.Request <TestAsyncRequestMessage, TestAsyncResponseMessage>(request,
                                                                                               response =>
                    {
                        Console.Out.WriteLine("response = {0}", response.Text);
                        Interlocked.Increment(ref count);
                        countdownEvent.Signal();
                    });
                }
            }
            countdownEvent.Wait(10000);
            count.ShouldEqual(numberOfCalls);
        }
Beispiel #3
0
        public void ShouldHandleAsyncRequest()
        {
            var message = new TestAsyncRequestMessage {
                Data = "before"
            };

            _dispatcher.HandleAsync(message);
            message.Data.ShouldBe("handled");
        }
Beispiel #4
0
        private static Task <TestAsyncResponseMessage> HandleAsyncRequest(TestAsyncRequestMessage request)
        {
            Console.Out.WriteLine("Got async request '{0}'", request.Text);

            return(RunDelayed(1000, () =>
            {
                Console.Out.WriteLine("Sending response");
                return new TestAsyncResponseMessage {
                    Text = request.Text + " ... completed."
                };
            }));
        }
Beispiel #5
0
        private static Task <TestAsyncResponseMessage> HandleAsyncRequest(TestAsyncRequestMessage request)
        {
            Console.WriteLine("Handling request: {0}", request.Text);

            var tcs = new TaskCompletionSource <TestAsyncResponseMessage>();

            tcs.SetResult(new TestAsyncResponseMessage {
                Id = request.Id, Text = request.Text + " ... completed."
            });

            return(tcs.Task);
        }
Beispiel #6
0
        public void Should_be_able_to_make_a_request_that_runs_async_on_the_server()
        {
            var autoResetEvent = new AutoResetEvent(false);
            var request        = new TestAsyncRequestMessage {
                Text = "Hello async from the client!"
            };

            Console.Out.WriteLine("Making request");
            bus.RequestAsync <TestAsyncRequestMessage, TestAsyncResponseMessage>(request).ContinueWith(response =>
            {
                Console.Out.WriteLine("response = {0}", response.Result.Text);
                autoResetEvent.Set();
            });

            autoResetEvent.WaitOne(2000);
        }
Beispiel #7
0
        public void Should_be_able_to_make_a_request_that_runs_async_on_the_server()
        {
            var autoResetEvent = new AutoResetEvent(false);
            var request        = new TestAsyncRequestMessage {
                Text = "Hello async from the client!"
            };

            Console.Out.WriteLine("Making request");
            using (var publishChannel = bus.OpenPublishChannel())
            {
                publishChannel.Request <TestAsyncRequestMessage, TestAsyncResponseMessage>(request,
                                                                                           response =>
                {
                    Console.Out.WriteLine("response = {0}", response.Text);
                    autoResetEvent.Set();
                });
            }

            autoResetEvent.WaitOne(2000);
        }
        public void Should_be_able_to_make_many_async_requests()
        {
            const int numberOfCalls  = 200;
            var       countdownEvent = new CountdownEvent(numberOfCalls);
            var       count          = 0;

            for (int i = 0; i < numberOfCalls; i++)
            {
                var request = new TestAsyncRequestMessage {
                    Text = "Hello async from the client! " + i
                };

                bus.RequestAsync <TestAsyncRequestMessage, TestAsyncResponseMessage>(request).ContinueWith(response =>
                {
                    Console.Out.WriteLine("response = {0}", response.Result.Text);
                    Interlocked.Increment(ref count);
                    countdownEvent.Signal();
                });
            }
            countdownEvent.Wait(10000);
            count.Should().Be(numberOfCalls);
        }
        public void Should_be_able_to_make_a_request_that_runs_async_on_the_server()
        {
            var autoResetEvent = new AutoResetEvent(false);
            var request = new TestAsyncRequestMessage {Text = "Hello async from the client!"};

            Console.Out.WriteLine("Making request");
            bus.RequestAsync<TestAsyncRequestMessage, TestAsyncResponseMessage>(request).ContinueWith(response =>
            {
                Console.Out.WriteLine("response = {0}", response.Result.Text);
                autoResetEvent.Set();
            });

            autoResetEvent.WaitOne(2000);
        }
        public void Should_be_able_to_make_many_async_requests()
        {
            const int numberOfCalls = 500;
            var countdownEvent = new CountdownEvent(numberOfCalls);
            var count = 0;

            for (int i = 0; i < 1000; i++)
            {
                var request = new TestAsyncRequestMessage { Text = "Hello async from the client! " + i };

                bus.RequestAsync<TestAsyncRequestMessage, TestAsyncResponseMessage>(request).ContinueWith(response =>
                {
                    Console.Out.WriteLine("response = {0}", response.Result.Text);
                    Interlocked.Increment(ref count);
                    countdownEvent.Signal();
                });
            }
            countdownEvent.Wait(10000);
            count.ShouldEqual(numberOfCalls);
        }
        public void Should_be_able_to_make_a_request_that_runs_async_on_the_server()
        {
            var autoResetEvent = new AutoResetEvent(false);
            var request = new TestAsyncRequestMessage {Text = "Hello async from the client!"};

            Console.Out.WriteLine("Making request");
            using (var publishChannel = bus.OpenPublishChannel())
            {
                publishChannel.Request<TestAsyncRequestMessage, TestAsyncResponseMessage>(request,
                    response =>
                    {
                        Console.Out.WriteLine("response = {0}", response.Text);
                        autoResetEvent.Set();
                    });
            }

            autoResetEvent.WaitOne(2000);
        }
Beispiel #12
0
        public async Task AsyncRequestMessagePipelineShouldFireHandlers()
        {
            var preRequestHandledCount = 0;
            var postRequestHandledCount = 0;
            var handled = false;
            var message = new TestAsyncRequestMessage
            {
                PreRequestAction = () =>
                {
                    preRequestHandledCount++;
                },
                HandlerAction = () =>
                {
                    handled = true;
                },
                PostRequestAction = () =>
                {
                    postRequestHandledCount++;
                }
            };

            await _dispatcher.HandleAsync(message);
            preRequestHandledCount.ShouldBe(3);
            postRequestHandledCount.ShouldBe(3);
            handled.ShouldBe(true);
        }
Beispiel #13
0
 public void ShouldHandleAsyncRequest()
 {
     var message = new TestAsyncRequestMessage { Data = "before" };
     _dispatcher.HandleAsync(message);
     message.Data.ShouldBe("handled");
 }