public void TestRequestReplyWithResponseCorrelatorInApplicationContext()
        {
            IApplicationContext context = TestUtils.GetContext(@"Gateway\gatewayWithResponseCorrelator.xml");
            ITestService        service = (ITestService)context.GetObject("proxy");
            string result = service.RequestReply("foo");

            Assert.That(result, Is.EqualTo("foo!!!"));
            TestChannelInterceptor interceptor = (TestChannelInterceptor)context.GetObject("interceptor");

            Assert.That(interceptor.SentCount, Is.EqualTo(1));
            Assert.That(interceptor.ReceivedCount, Is.EqualTo(1));
        }
        public void TestMultipleMessagesWithResponseCorrelator()
        {
            IApplicationContext context     = TestUtils.GetContext(@"Gateway\gatewayWithResponseCorrelator.xml");
            const int           numRequests = 500;
            ITestService        service     = (ITestService)context.GetObject("proxy");

            string[]       results  = new string[numRequests];
            CountDownLatch latch    = new CountDownLatch(numRequests);
            IExecutor      executor = Executors.NewFixedThreadPool(numRequests);

            for (int i = 0; i < numRequests; i++)
            {
                int count = i;
                executor.Execute(delegate
                {
                    // add some randomness to the ordering of requests
                    try
                    {
                        Thread.Sleep(new Random().Next(100));
                    }
                    catch (ThreadInterruptedException e)
                    {
                        // ignore
                    }
                    results[count] = service.RequestReply("test-" + count);
                    latch.CountDown();
                });
            }
            latch.Await(TimeSpan.FromSeconds(10));
            for (int i = 0; i < numRequests; i++)
            {
                Assert.That(results[i], Is.EqualTo("test-" + i + "!!!"));
            }
            TestChannelInterceptor interceptor = (TestChannelInterceptor)context.GetObject("interceptor");

            Assert.That(interceptor.SentCount, Is.EqualTo(numRequests));
            Assert.That(interceptor.ReceivedCount, Is.EqualTo(numRequests));
        }