public void DynamicReplyChannel()
 {
     QueueChannel replyChannel1 = new QueueChannel();
     QueueChannel replyChannel2 = new QueueChannel();
     replyChannel2.ObjectName = "replyChannel2";
     Object handler = new TestObject2();
     ServiceActivatingHandler endpoint = new ServiceActivatingHandler(handler, "Handle");
     TestChannelResolver channelResolver = new TestChannelResolver();
     channelResolver.AddChannel(replyChannel2);
     endpoint.ChannelResolver = channelResolver;
     IMessage testMessage1 = MessageBuilder.WithPayload("bar").SetReplyChannel(replyChannel1).Build();
     endpoint.HandleMessage(testMessage1);
     IMessage reply1 = replyChannel1.Receive(TimeSpan.FromMilliseconds(50));
     Assert.IsNotNull(reply1);
     Assert.That(reply1.Payload, Is.EqualTo("foobar"));
     IMessage reply2 = replyChannel2.Receive(TimeSpan.Zero);
     Assert.IsNull(reply2);
     IMessage testMessage2 =
         MessageBuilder.FromMessage(testMessage1).SetReplyChannelName("replyChannel2").Build();
     endpoint.HandleMessage(testMessage2);
     reply1 = replyChannel1.Receive(TimeSpan.Zero);
     Assert.IsNull(reply1);
     reply2 = replyChannel2.Receive(TimeSpan.Zero);
     Assert.IsNotNull(reply2);
     Assert.That(reply2.Payload, Is.EqualTo("foobar"));
 }
 public void TestCorrelationIdWithSplitter()
 {
     IMessage message = new StringMessage("test1,test2");
     QueueChannel testChannel = new QueueChannel();
     MethodInvokingSplitter splitter = new MethodInvokingSplitter(new TestBean(),
                                                                  typeof (TestBean).GetMethod("Split"));
     splitter.OutputChannel = testChannel;
     splitter.HandleMessage(message);
     IMessage reply1 = testChannel.Receive(TimeSpan.FromMilliseconds(100));
     IMessage reply2 = testChannel.Receive(TimeSpan.FromMilliseconds(100));
     Assert.That(reply1.Headers.CorrelationId, Is.EqualTo(message.Headers.Id));
     Assert.That(reply2.Headers.CorrelationId, Is.EqualTo(message.Headers.Id));
 }
 public void SimpleTargetWireTap()
 {
     QueueChannel mainChannel = new QueueChannel();
     QueueChannel secondaryChannel = new QueueChannel();
     mainChannel.AddInterceptor(new WireTap(secondaryChannel));
     Assert.IsNull(secondaryChannel.Receive(TimeSpan.Zero));
     mainChannel.Send(new StringMessage("testing"));
     IMessage original = mainChannel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(original);
     IMessage intercepted = secondaryChannel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(intercepted);
     Assert.That(original, Is.EqualTo(intercepted));
 }
 public void TestPostReceiveInterceptor()
 {
     AtomicInteger invokedCount = new AtomicInteger();
     AtomicInteger messageCount = new AtomicInteger();
     QueueChannel channel = new QueueChannel();
     channel.AddInterceptor(new TestPostReceiveInterceptorInterceptor(invokedCount, messageCount, channel));
     channel.Receive(TimeSpan.Zero);
     Assert.That(invokedCount.Value, Is.EqualTo(1));
     Assert.That(messageCount.Value, Is.EqualTo(0));
     channel.Send(new StringMessage("test"));
     IMessage result = channel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(result);
     Assert.That(invokedCount.Value, Is.EqualTo(2));
     Assert.That(messageCount.Value, Is.EqualTo(1));
 }
 public void CorrelationIdNotSetIfMessageIsReturnedUnaltered()
 {
     QueueChannel replyChannel = new QueueChannel(1);
     ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new TestObject3(), "Handle");
     IMessage message = MessageBuilder.WithPayload("test").SetReplyChannel(replyChannel).Build();
     endpoint.HandleMessage(message);
     IMessage reply = replyChannel.Receive(TimeSpan.FromMilliseconds(500));
     Assert.IsNull(reply.Headers.CorrelationId);
 }
 public void CorrelationIdSetByHandlerTakesPrecedence()
 {
     QueueChannel replyChannel = new QueueChannel(1);
     ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new TestObject4(), "Handle");
     IMessage message = MessageBuilder.WithPayload("test").SetReplyChannel(replyChannel).Build();
     endpoint.HandleMessage(message);
     IMessage reply = replyChannel.Receive(TimeSpan.FromMilliseconds(500));
     Object correlationId = reply.Headers.CorrelationId;
     Assert.IsFalse(message.Headers.Id.Equals(correlationId));
     Assert.That(correlationId, Is.EqualTo("ABC-123"));
 }
 public void testMultipleChannelsWithNoSelector()
 {
     QueueChannel channel1 = new QueueChannel();
     QueueChannel channel2 = new QueueChannel();
     channel1.Send(new StringMessage("test1"));
     channel1.Send(new StringMessage("test2"));
     channel2.Send(new StringMessage("test1"));
     channel2.Send(new StringMessage("test2"));
     ChannelPurger purger = new ChannelPurger(channel1, channel2);
     IList<IMessage> purgedMessages = purger.Purge();
     Assert.That(purgedMessages.Count, Is.EqualTo(4));
     Assert.IsNull(channel1.Receive(TimeSpan.Zero));
     Assert.IsNull(channel2.Receive(TimeSpan.Zero));
 }
 public void testMultipleChannelsWithSelector()
 {
     QueueChannel channel1 = new QueueChannel();
     QueueChannel channel2 = new QueueChannel();
     channel1.Send(new StringMessage("test1"));
     channel1.Send(new StringMessage("test2"));
     channel1.Send(new StringMessage("test3"));
     channel2.Send(new StringMessage("test1"));
     channel2.Send(new StringMessage("test2"));
     channel2.Send(new StringMessage("test3"));
     ChannelPurger purger = new ChannelPurger(delegate(IMessage msg) { return (msg.Payload.Equals("test2")); },
                                              channel1, channel2);
     IList<IMessage> purgedMessages = purger.Purge();
     Assert.That(purgedMessages.Count, Is.EqualTo(4));
     IMessage message1 = channel1.Receive(TimeSpan.Zero);
     Assert.IsNotNull(message1);
     Assert.That(message1.Payload, Is.EqualTo("test2"));
     Assert.IsNull(channel1.Receive(TimeSpan.Zero));
     IMessage message2 = channel2.Receive(TimeSpan.Zero);
     Assert.IsNotNull(message2);
     Assert.That(message2.Payload, Is.EqualTo("test2"));
     Assert.IsNull(channel2.Receive(TimeSpan.Zero));
 }
 public void TestCorrelationIdPassedIfAvailable()
 {
     object correlationId = "123-ABC";
     IMessage message = MessageBuilder.WithPayload("test").SetCorrelationId(correlationId).Build();
     DirectChannel inputChannel = new DirectChannel();
     QueueChannel outputChannel = new QueueChannel(1);
     ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "UpperCase");
     serviceActivator.OutputChannel = outputChannel;
     EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
     endpoint.Start();
     Assert.IsTrue(inputChannel.Send(message));
     IMessage reply = outputChannel.Receive(TimeSpan.Zero);
     Assert.That(reply.Headers.CorrelationId, Is.EqualTo(correlationId));
 }
 public void InterceptedMessageContainsHeaderValue()
 {
     QueueChannel mainChannel = new QueueChannel();
     QueueChannel secondaryChannel = new QueueChannel();
     mainChannel.AddInterceptor(new WireTap(secondaryChannel));
     string headerName = "testAttribute";
     IMessage message = MessageBuilder.WithPayload("testing").SetHeader(headerName, 123).Build();
     mainChannel.Send(message);
     IMessage original = mainChannel.Receive(TimeSpan.Zero);
     IMessage intercepted = secondaryChannel.Receive(TimeSpan.Zero);
     object originalAttribute = original.Headers.Get(headerName);
     object interceptedAttribute = intercepted.Headers.Get(headerName);
     Assert.IsNotNull(originalAttribute);
     Assert.IsNotNull(interceptedAttribute);
     Assert.That(original, Is.EqualTo(intercepted));
 }
 public void TestMessageAsReturnValue()
 {
     QueueChannel requestChannel = new QueueChannel();
     new Thread(new ThreadStart(delegate
                                    {
                                        IMessage input = requestChannel.Receive();
                                        StringMessage reply = new StringMessage(input.Payload + "bar");
                                        ((IMessageChannel) input.Headers.ReplyChannel).Send(reply);
                                    })).Start();
     GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();
     proxyFactory.ServiceInterface = typeof (ITestService);
     proxyFactory.DefaultRequestChannel = requestChannel;
     proxyFactory.AfterPropertiesSet();
     ITestService service = (ITestService) proxyFactory.GetObject();
     IMessage result = service.RequestReplyWithMessageReturnValue("foo");
     Assert.That(result.Payload, Is.EqualTo("foobar"));
 }
 public void TestBlockingReceiveWithTimeout()
 {
     QueueChannel channel = new QueueChannel();
     AtomicBoolean receiveInterrupted = new AtomicBoolean(false);
     CountDownLatch latch = new CountDownLatch(1);
     Thread t = new Thread(new ThreadStart(delegate
                                               {
                                                   IMessage message = channel.Receive(new TimeSpan(10000));
                                                   receiveInterrupted.Value = true;
                                                   Assert.IsTrue(message == null);
                                                   latch.CountDown();
                                               }));
     t.Start();
     //Assert.IsFalse(receiveInterrupted.Value);
     t.Interrupt();
     latch.Await();
     Assert.IsTrue(receiveInterrupted.Value);
 }
 public void TestPreReceiveInterceptorReturnsFalse()
 {
     QueueChannel channel = new QueueChannel();
     channel.AddInterceptor(new PreReceiveReturnsFalseInterceptor());
     IMessage message = new StringMessage("test");
     channel.Send(message);
     IMessage result = channel.Receive(TimeSpan.Zero);
     Assert.That(PreReceiveReturnsFalseInterceptor.counter.Value, Is.EqualTo(1));
     Assert.IsNull(result);
 }
 private void StartBackgroundReplier(QueueChannel channel)
 {
     new ThreadPerTaskExecutor().Execute(() =>
                                             {
                                                 Spring.Integration.Core.IMessage request =
                                                     channel.Receive(TimeSpan.FromMilliseconds(5000));
                                                 Spring.Integration.Core.IMessage reply =
                                                     new StringMessage(((string) request.Payload).ToUpper());
                                                 ((IMessageChannel) request.Headers.ReplyChannel).Send(reply,
                                                                                                       TimeSpan.
                                                                                                           FromMilliseconds
                                                                                                           (5000));
                                             });
 }
 public void testPurgeSubsetWithSelector()
 {
     QueueChannel channel = new QueueChannel();
     channel.Send(new StringMessage("test1"));
     channel.Send(new StringMessage("test2"));
     channel.Send(new StringMessage("test3"));
     ChannelPurger purger = new ChannelPurger(delegate(IMessage msg) { return (msg.Payload.Equals("test2")); },
                                              channel);
     IList<IMessage> purgedMessages = purger.Purge();
     Assert.That(purgedMessages.Count, Is.EqualTo(2));
     IMessage message = channel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(message);
     Assert.That(message.Payload, Is.EqualTo("test2"));
     Assert.IsNull(channel.Receive(TimeSpan.Zero));
 }
 public void testPurgeNoneWithSelectorAndMultipleChannels()
 {
     QueueChannel channel1 = new QueueChannel();
     QueueChannel channel2 = new QueueChannel();
     channel1.Send(new StringMessage("test1"));
     channel1.Send(new StringMessage("test2"));
     channel2.Send(new StringMessage("test1"));
     channel2.Send(new StringMessage("test2"));
     ChannelPurger purger = new ChannelPurger(delegate { return true; }, channel1, channel2);
     IList<IMessage> purgedMessages = purger.Purge();
     Assert.That(purgedMessages.Count, Is.EqualTo(0));
     Assert.IsNotNull(channel1.Receive(TimeSpan.Zero));
     Assert.IsNotNull(channel1.Receive(TimeSpan.Zero));
     Assert.IsNotNull(channel2.Receive(TimeSpan.Zero));
     Assert.IsNotNull(channel2.Receive(TimeSpan.Zero));
 }
 public void OutputChannelTakesPrecedence()
 {
     QueueChannel channel1 = new QueueChannel(1);
     QueueChannel channel2 = new QueueChannel(1);
     ServiceActivatingHandler endpoint = CreateEndpoint();
     endpoint.OutputChannel = channel1;
     IMessage message = MessageBuilder.WithPayload("foo").SetReplyChannel(channel2).Build();
     endpoint.HandleMessage(message);
     IMessage reply1 = channel1.Receive(TimeSpan.Zero);
     Assert.IsNotNull(reply1);
     Assert.That(reply1.Payload, Is.EqualTo("FOO"));
     IMessage reply2 = channel2.Receive(TimeSpan.Zero);
     Assert.IsNull(reply2);
 }
 public void ReceiveWithExplicitChannelTakesPrecedenceOverDefault()
 {
     QueueChannel explicitChannel = new QueueChannel();
     QueueChannel defaultChannel = new QueueChannel();
     explicitChannel.Send(new StringMessage("test"));
     MessageChannelTemplate template = new MessageChannelTemplate(defaultChannel);
     template.ReceiveTimeout = TimeSpan.Zero;
     IMessage reply = template.Receive(explicitChannel);
     Assert.That(reply.Payload, Is.EqualTo("test"));
     Assert.IsNull(defaultChannel.Receive(TimeSpan.Zero));
 }
 public void TestRequestReplyWithTypeConversion()
 {
     QueueChannel requestChannel = new QueueChannel();
     new Thread(new ThreadStart(delegate
                                    {
                                        IMessage input = requestChannel.Receive();
                                        StringMessage reply = new StringMessage(input.Payload + "456");
                                        ((IMessageChannel) input.Headers.ReplyChannel).Send(reply);
                                    })).Start();
     GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();
     proxyFactory.ServiceInterface = typeof (ITestService);
     proxyFactory.DefaultRequestChannel = requestChannel;
     proxyFactory.AfterPropertiesSet();
     ITestService service = (ITestService) proxyFactory.GetObject();
     int result = service.RequestReplyWithIntegers(123);
     Assert.That(result, Is.EqualTo(123456));
 }
 public void SendAndReceiveWithExplicitChannelTakesPrecedenceOverDefault()
 {
     QueueChannel defaultChannel = new QueueChannel();
     MessageChannelTemplate template = new MessageChannelTemplate(defaultChannel);
     IMessage message = new StringMessage("test");
     IMessage reply = template.SendAndReceive(message, requestChannel);
     Assert.That(reply.Payload, Is.EqualTo("TEST"));
     Assert.IsNull(defaultChannel.Receive(TimeSpan.Zero));
 }
 public void SendWithDefaultChannelProvidedBySetter()
 {
     QueueChannel channel = new QueueChannel();
     MessageChannelTemplate template = new MessageChannelTemplate();
     template.DefaultChannel = channel;
     template.Send(new StringMessage("test"));
     IMessage reply = channel.Receive();
     Assert.IsNotNull(reply);
     Assert.That(reply.Payload, Is.EqualTo("test"));
 }
 public void WireTapWithAcceptingSelector()
 {
     QueueChannel mainChannel = new QueueChannel();
     QueueChannel secondaryChannel = new QueueChannel();
     mainChannel.AddInterceptor(new WireTap(secondaryChannel, new TestSelector(true)));
     mainChannel.Send(new StringMessage("testing"));
     IMessage original = mainChannel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(original);
     IMessage intercepted = secondaryChannel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(intercepted);
     Assert.That(original, Is.EqualTo(intercepted));
 }
 public void NoOutputChannelFallsBackToReturnAddress()
 {
     QueueChannel channel = new QueueChannel(1);
     ServiceActivatingHandler endpoint = CreateEndpoint();
     IMessage message = MessageBuilder.WithPayload("foo").SetReplyChannel(channel).Build();
     endpoint.HandleMessage(message);
     IMessage reply = channel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(reply);
     Assert.That(reply.Payload, Is.EqualTo("FOO"));
 }
 public void NoReplyMessage()
 {
     QueueChannel channel = new QueueChannel(1);
     ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new TestNullReplyObject(), "Handle");
     endpoint.OutputChannel = channel;
     IMessage message = MessageBuilder.WithPayload("foo").Build();
     endpoint.HandleMessage(message);
     Assert.IsNull(channel.Receive(TimeSpan.Zero));
 }
 public void testPurgeAllWithoutSelector()
 {
     QueueChannel channel = new QueueChannel();
     channel.Send(new StringMessage("test1"));
     channel.Send(new StringMessage("test2"));
     channel.Send(new StringMessage("test3"));
     ChannelPurger purger = new ChannelPurger(channel);
     IList<IMessage> purgedMessages = purger.Purge();
     Assert.That(purgedMessages.Count, Is.EqualTo(3));
     Assert.IsNull(channel.Receive(TimeSpan.Zero));
 }
        public void TestImmediateReceive()
        {
            AtomicBoolean messageReceived = new AtomicBoolean(false);
            QueueChannel channel = new QueueChannel();
            CountDownLatch latch1 = new CountDownLatch(1);
            CountDownLatch latch2 = new CountDownLatch(1);
            IExecutor singleThreadExecutor = Executors.NewSingleThreadExecutor();

            singleThreadExecutor.Execute(
                delegate
                    {
                        IMessage message = channel.Receive(TimeSpan.Zero);
                        if (message != null)
                        {
                            messageReceived.Value = true;
                        }
                        latch1.CountDown();
                    });

            latch1.Await();
            singleThreadExecutor.Execute(
                delegate { channel.Send(new Message<string>("testing")); });

            Assert.IsFalse(messageReceived.Value);
            singleThreadExecutor.Execute(
                delegate
                    {
                        IMessage message = channel.Receive(TimeSpan.Zero);
                        if (message != null)
                        {
                            messageReceived.Value = true;
                        }
                        latch2.CountDown();
                    });

            latch2.Await();
            Assert.IsNotNull(messageReceived.Value);
        }
 public void TestOneWay()
 {
     QueueChannel requestChannel = new QueueChannel();
     GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();
     proxyFactory.DefaultRequestChannel = requestChannel;
     proxyFactory.ServiceInterface = typeof (ITestService);
     proxyFactory.AfterPropertiesSet();
     ITestService service = (ITestService) proxyFactory.GetObject();
     service.OneWay("test");
     IMessage message = requestChannel.Receive(TimeSpan.FromMilliseconds(1000));
     Assert.IsNotNull(message);
     Assert.That(message.Payload, Is.EqualTo("test"));
 }
        public void TestSimpleSendAndReceive()
        {
            AtomicBoolean messageReceived = new AtomicBoolean(false);
            CountDownLatch latch = new CountDownLatch(1);
            QueueChannel channel = new QueueChannel();
            new Thread(new ThreadStart(delegate
                                           {
                                               IMessage message = channel.Receive();
                                               if (message != null)
                                               {
                                                   messageReceived.Value = true;
                                                   latch.CountDown();
                                               }
                                           })).Start();

            Assert.That(messageReceived.Value, Is.False);
            channel.Send(new Message<string>("testing"));
            latch.Await(new TimeSpan(0, 0, 0, 0, 25));
            Assert.That(messageReceived.Value, Is.True);
        }
 public void Send()
 {
     MessageChannelTemplate template = new MessageChannelTemplate();
     QueueChannel channel = new QueueChannel();
     template.Send(new StringMessage("test"), channel);
     IMessage reply = channel.Receive();
     Assert.IsNotNull(reply);
     Assert.That(reply.Payload, Is.EqualTo("test"));
 }
 public void ReturnAddressHeaderWithChannelName()
 {
     QueueChannel channel = new QueueChannel(1);
     channel.ObjectName = "testChannel";
     TestChannelResolver channelResolver = new TestChannelResolver();
     channelResolver.AddChannel(channel);
     ServiceActivatingHandler endpoint = CreateEndpoint();
     endpoint.ChannelResolver = channelResolver;
     IMessage message = MessageBuilder.WithPayload("foo")
         .SetReplyChannelName("testChannel").Build();
     endpoint.HandleMessage(message);
     IMessage reply = channel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(reply);
     Assert.That(reply.Payload, Is.EqualTo("FOO"));
 }