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 ReceiveWithDefaultChannelProvidedByConstructor() { QueueChannel channel = new QueueChannel(); channel.Send(new StringMessage("test")); MessageChannelTemplate template = new MessageChannelTemplate(channel); IMessage reply = template.Receive(); Assert.That(reply.Payload, Is.EqualTo("test")); }
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 testSingleSelectorAccepts() { AtomicInteger counter = new AtomicInteger(); IMessageSelector selector = new TestMessageSelector(true, counter); MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector); QueueChannel channel = new QueueChannel(); channel.AddInterceptor(interceptor); Assert.That(channel.Send(new StringMessage("test1")), Is.True); }
public void TestPostSendInterceptorWithSentMessage() { QueueChannel channel = new QueueChannel(); AtomicBoolean invoked = new AtomicBoolean(false); channel.AddInterceptor(new TestPostSendInterceptorWithSentMessageInterceptor(invoked, channel)); channel.Send(new StringMessage("test")); Assert.IsTrue(invoked.Value); }
public void mapDoesNotContainChannel() { IMessageChannel testChannel = new QueueChannel(); IDictionary<string, IMessageChannel> channelMap = new Dictionary<string, IMessageChannel>(); channelMap.Add("testChannel", testChannel); MapBasedChannelResolver resolver = new MapBasedChannelResolver(); resolver.ChannelMap = channelMap; IMessageChannel result = resolver.ResolveChannelName("noSuchChannel"); Assert.IsNull(result); }
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 mapContainsChannel() { IMessageChannel testChannel = new QueueChannel(); IDictionary<string, IMessageChannel> channelMap = new Dictionary<string, IMessageChannel>(); channelMap.Add("testChannel", testChannel); MapBasedChannelResolver resolver = new MapBasedChannelResolver(); resolver.ChannelMap = channelMap; IMessageChannel result = resolver.ResolveChannelName("testChannel"); Assert.IsNotNull(result); Assert.That(result, Is.EqualTo(testChannel)); }
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 testMultipleSelectorsAccept() { AtomicInteger counter = new AtomicInteger(); IMessageSelector selector1 = new TestMessageSelector(true, counter); IMessageSelector selector2 = new TestMessageSelector(true, counter); MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector1, selector2); QueueChannel channel = new QueueChannel(); channel.AddInterceptor(interceptor); Assert.That(channel.Send(new StringMessage("test1")), Is.True); Assert.That(counter.Value, Is.EqualTo(2)); }
public void TestMessageAsMethodArgument() { QueueChannel requestChannel = new QueueChannel(); StartResponder(requestChannel); GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject(); proxyFactory.ServiceInterface = typeof (ITestService); proxyFactory.DefaultRequestChannel = requestChannel; proxyFactory.AfterPropertiesSet(); ITestService service = (ITestService) proxyFactory.GetObject(); String result = service.RequestReplyWithMessageParameter(new StringMessage("foo")); Assert.That(result, Is.EqualTo("foobar")); }
public void LookupRegisteredChannel() { GenericApplicationContext context = new GenericApplicationContext(); QueueChannel testChannel = new QueueChannel(); testChannel.ObjectName = "testChannel"; context.ObjectFactory.RegisterSingleton("testChannel", testChannel); ObjectFactoryChannelResolver resolver = new ObjectFactoryChannelResolver(context); IMessageChannel lookedUpChannel = resolver.ResolveChannelName("testChannel"); Assert.IsNotNull(testChannel); Assert.That(lookedUpChannel, Is.SameAs(testChannel)); }
public void NoReplyToAndNoDefault() { QueueChannel requestChannel = new QueueChannel(); StartBackgroundReplier(requestChannel); ChannelPublishingJmsMessageListener listener = new ChannelPublishingJmsMessageListener(); listener.ExpectReply = true; listener.RequestChannel = requestChannel; listener.MessageConverter = new TestMessageConverter(); Apache.NMS.IMessage nmsMessage = session.CreateTextMessage("test"); listener.AfterPropertiesSet(); listener.OnMessage(nmsMessage, session); }
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 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 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 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 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 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 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 TestPostSendInterceptorWithUnsentMessage() { AtomicInteger invokedCounter = new AtomicInteger(0); AtomicInteger sentCounter = new AtomicInteger(0); QueueChannel singleItemChannel = new QueueChannel(1); singleItemChannel.AddInterceptor(new TestPostSendInterceptorWithUnsentMessageInterceptor(invokedCounter, sentCounter, singleItemChannel)); Assert.That(invokedCounter.Value, Is.EqualTo(0)); Assert.That(sentCounter.Value, Is.EqualTo(0)); singleItemChannel.Send(new StringMessage("test1")); Assert.That(invokedCounter.Value, Is.EqualTo(1)); Assert.That(sentCounter.Value, Is.EqualTo(1)); singleItemChannel.Send(new StringMessage("test2"), TimeSpan.Zero); Assert.That(invokedCounter.Value, Is.EqualTo(2)); Assert.That(sentCounter.Value, Is.EqualTo(1)); }
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 testMultipleSelectorsReject() { bool exceptionThrown = false; AtomicInteger counter = new AtomicInteger(); IMessageSelector selector1 = new TestMessageSelector(true, counter); IMessageSelector selector2 = new TestMessageSelector(false, counter); IMessageSelector selector3 = new TestMessageSelector(false, counter); IMessageSelector selector4 = new TestMessageSelector(true, counter); MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector1, selector2, selector3, selector4); QueueChannel channel = new QueueChannel(); channel.AddInterceptor(interceptor); try { channel.Send(new StringMessage("test1")); } catch (MessageDeliveryException) { exceptionThrown = true; } Assert.That(exceptionThrown, Is.True); Assert.That(counter.Value, Is.EqualTo(2)); }
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 TestSolicitResponse() { QueueChannel replyChannel = new QueueChannel(); replyChannel.Send(new StringMessage("foo")); GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject(); proxyFactory.ServiceInterface = typeof (ITestService); proxyFactory.DefaultRequestChannel = new DirectChannel(); proxyFactory.DefaultReplyChannel = replyChannel; proxyFactory.AfterPropertiesSet(); ITestService service = (ITestService) proxyFactory.GetObject(); string result = service.SolicitResponse(); Assert.IsNotNull(result); Assert.That(result, Is.EqualTo("foo")); }
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 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 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 testEmptyChannelArray() { QueueChannel[] channels = new QueueChannel[0]; new ChannelPurger(channels); }