public PollingConsumer(IPollableChannel inputChannel, IMessageHandler handler) { AssertUtils.ArgumentNotNull(inputChannel, "inputChannel"); AssertUtils.ArgumentNotNull(handler, "handler"); _inputChannel = inputChannel; _handler = handler; }
public void GatewayWithConnectionFactoryAndDestinationName() { XmlApplicationContext ctx = (XmlApplicationContext) NmsTestUtils.GetContext(@"Nms\Config\NmsGatewayWithConnectionFactoryAndDestinationName.xml"); IPollableChannel channel = (IPollableChannel)ctx.GetObject("requestChannel"); NmsMessageDrivenEndpoint gateway = (NmsMessageDrivenEndpoint)ctx.GetObject("nmsGateway"); Assert.That(gateway.GetType(), Is.EqualTo(typeof(NmsMessageDrivenEndpoint))); ctx.Start(); ThreadPerTaskExecutor executor = new ThreadPerTaskExecutor(); executor.Execute(delegate { SimpleMessageListenerContainer listenerContainer = (SimpleMessageListenerContainer) ctx.GetObject("Spring.Messaging.Nms.Listener.SimpleMessageListenerContainer#0"); ISessionAwareMessageListener messageListener = (ISessionAwareMessageListener)listenerContainer.MessageListener; messageListener.OnMessage(new StubTextMessage("message-driven-test"), new StubSession("message-driven-test")); }); IMessage message = channel.Receive(TimeSpan.FromMilliseconds(3000)); Assert.That(message, Is.Not.Null); Assert.That(message.Payload, Is.EqualTo("message-driven-test")); ctx.Stop(); }
public void TestPriorityChannelWithIntegerDatatypeEnforced2() { IApplicationContext ctx = TestUtils.GetContext(@"Channel\Config\PriorityChannelParserTests.xml"); IPollableChannel channel = (IPollableChannel)ctx.GetObject("integerOnlyPriorityChannel"); channel.Send(new StringMessage("wrong type")); }
public void TestAggregatorWithPojoCompletionStrategy() { IMessageChannel input = (IMessageChannel)_ctx.GetObject("aggregatorWithPojoCompletionStrategyInput"); EventDrivenConsumer endpoint = (EventDrivenConsumer)_ctx.GetObject("aggregatorWithPojoCompletionStrategy"); ICompletionStrategy completionStrategy = (ICompletionStrategy) TestUtils.GetFieldValue(TestUtils.GetFieldValue(endpoint, "_handler"), "_completionStrategy"); Assert.IsTrue(completionStrategy is CompletionStrategyAdapter); //DirectFieldAccessor completionStrategyAccessor = new DirectFieldAccessor(completionStrategy); IMethodInvoker invoker = (IMethodInvoker)TestUtils.GetFieldValue(completionStrategy, "_invoker"); Assert.IsTrue(TestUtils.GetFieldValue(invoker, "_obj") is MaxValueCompletionStrategy); Assert.IsTrue( ((MethodInfo)TestUtils.GetFieldValue(completionStrategy, "_method")).Name.Equals("CheckCompleteness")); input.Send(CreateMessage(1l, "id1", 0, 0, null)); input.Send(CreateMessage(2l, "id1", 0, 0, null)); input.Send(CreateMessage(3l, "id1", 0, 0, null)); IPollableChannel outputChannel = (IPollableChannel)_ctx.GetObject("outputChannel"); IMessage reply = outputChannel.Receive(TimeSpan.Zero); Assert.IsNull(reply); input.Send(CreateMessage(5l, "id1", 0, 0, null)); reply = outputChannel.Receive(TimeSpan.Zero); Assert.IsNotNull(reply); Assert.That(reply.Payload, Is.EqualTo(11l)); }
public PollingConsumer(IPollableChannel inputChannel, IMessageHandler handler) { AssertUtils.ArgumentNotNull(inputChannel, "inputChannel"); AssertUtils.ArgumentNotNull(handler, "handler"); _inputChannel = inputChannel; _handler = handler; }
/// <summary> /// receive a <see cref="IMessage"/> from the <see cref="RequiredDefaultChannel"/> /// </summary> /// <returns>the received <see cref="IMessage"/> or <c>null</c> if no message could be received</returns> public IMessage Receive() { IPollableChannel channel = RequiredDefaultChannel as IPollableChannel; AssertUtils.State(channel != null, "The 'defaultChannel' must be a PollableChannel for receive operations."); return(Receive(channel)); }
protected IMessage Receive(IPollableChannel channel, int additionalMultiplier) { var startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); var receive = channel.Receive((int)(1000 * TimeoutMultiplier * additionalMultiplier)); var elapsed = DateTimeOffset.Now.ToUnixTimeMilliseconds() - startTime; return(receive); }
// TODO public void TestCheckedExceptionRethrownAsIs //[Test, ExpectedException(typeof(TestException))] //public void TestCheckedExceptionRethrownAsIs() { // GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject(); // DirectChannel channel = new DirectChannel(); // EventDrivenConsumer consumer = new EventDrivenConsumer(channel, new MessageHandler() { // public void handleMessage(Message<?> message) { // MethodInfo method = ReflectionUtils.GetMethod(typeof(GatewayProxyFactoryObjectTests), "throwTestException",null); // method.Invoke(this, null); // } // }); // consumer.start(); // proxyFactory.setDefaultRequestChannel(channel); // proxyFactory.setServiceInterface(TestExceptionThrowingInterface.class); // proxyFactory.afterPropertiesSet(); // TestExceptionThrowingInterface proxy = (TestExceptionThrowingInterface) proxyFactory.getObject(); // proxy.throwCheckedException("test"); //} private static void StartResponder(IPollableChannel requestChannel) { new Thread(new ThreadStart(delegate { IMessage input = requestChannel.Receive(); StringMessage reply = new StringMessage(input.Payload + "bar"); ((IMessageChannel)input.Headers.ReplyChannel).Send(reply); })).Start(); }
public void AdapterWithConnectionFactoryAndDestination() { IApplicationContext ctx = NmsTestUtils.GetContext(@"Nms\Config\NmsInboundWithConnectionFactoryAndDestinationName.xml"); IPollableChannel output = (IPollableChannel)ctx.GetObject("output"); IMessage message = output.Receive(timeoutOnReceive); Assert.That(message, Is.Not.Null); Assert.That(message.Payload, Is.EqualTo("polling-test")); }
public void AdpaterWithDestinationAndDefaultConnectionFactory() { XmlApplicationContext ctx = (XmlApplicationContext)NmsTestUtils.GetContext(@"Nms\Config\NmsInboundWithDestinationAndDefaultConnectionFactory.xml"); IPollableChannel output = (IPollableChannel)ctx.GetObject("output"); IMessage message = output.Receive(timeoutOnReceive); Assert.That(message, Is.Not.Null); Assert.That(message.Payload, Is.EqualTo("polling-test")); ctx.Stop(); }
public void TestChannelInteceptorInnerBean() { IApplicationContext ctx = TestUtils.GetContext(@"Channel\Config\ChannelInterceptorParserTests.xml"); IPollableChannel channel = (IPollableChannel)ctx.GetObject("channelWithInterceptorInnerBean"); channel.Send(new StringMessage("test")); IMessage transformed = channel.Receive(TimeSpan.FromMilliseconds(1000)); Assert.That(transformed.Payload, Is.EqualTo("TEST")); }
/// <summary> /// receive a <see cref="IMessage"/> from <paramref name="channel"/> /// </summary> /// <param name="channel">the channel the <see cref="IMessage"/> should be received from</param> /// <returns>the received <see cref="IMessage"/> or <c>null</c> if no message could be received</returns> public IMessage Receive(IPollableChannel channel) { TransactionTemplate txTemplate = TransactionTemplate; if (txTemplate != null) { return((IMessage)txTemplate.Execute(delegate { return DoReceive(channel); })); } return(DoReceive(channel)); }
public void CheckExceptionPlacedOnErrorChannel() { IApplicationContext context = TestUtils.GetContext(@"Endpoint\pollingEndpointErrorHandlingTests.xml"); IPollableChannel errorChannel = (IPollableChannel)context.GetObject("errorChannel"); IMessage errorMessage = errorChannel.Receive(TimeSpan.FromMilliseconds(5000)); Assert.IsNotNull(errorMessage, "No error message received"); Assert.That(errorMessage.GetType(), Is.EqualTo(typeof(ErrorMessage)), "Message received was not an ErrorMessage"); }
private static void StartResponder(IPollableChannel requestChannel, IMessageChannel replyChannel) { Executors.NewSingleThreadExecutor().Execute(delegate { IMessage request = requestChannel.Receive(); IMessage reply = MessageBuilder.FromMessage(request).SetCorrelationId (request.Headers.Id).Build(); replyChannel.Send(reply); }); }
public void TestSolicitResponse() { IApplicationContext context = TestUtils.GetContext(@"Config\Xml\gatewayParserTests.xml"); IPollableChannel channel = (IPollableChannel)context.GetObject("replyChannel"); channel.Send(new StringMessage("foo")); ITestService service = (ITestService)context.GetObject("solicitResponse"); string result = service.SolicitResponse(); Assert.That(result, Is.EqualTo("foo")); }
public void TestOneWay() { IApplicationContext context = TestUtils.GetContext(@"Config\Xml\gatewayParserTests.xml"); ITestService service = (ITestService)context.GetObject("oneWay"); service.OneWay("foo"); IPollableChannel channel = (IPollableChannel)context.GetObject("requestChannel"); IMessage result = channel.Receive(TimeSpan.FromMilliseconds(1000)); Assert.That(result.Payload, Is.EqualTo("foo")); }
private static void StartResponder(IPollableChannel requestChannel, IMessageChannel replyChannel) { Executors.NewSingleThreadExecutor().Execute(delegate { IMessage request = requestChannel.Receive(); IMessage reply = MessageBuilder.FromMessage(request).SetCorrelationId (request.Headers.Id).Build(); replyChannel.Send(reply); }); }
public void AdapterWithHeaderMapper() { IApplicationContext ctx = NmsTestUtils.GetContext(@"Nms\Config\NmsInboundWithHeaderMapper.xml"); IPollableChannel output = (IPollableChannel)ctx.GetObject("output"); IMessage message = output.Receive(timeoutOnReceive); Assert.That(message, Is.Not.Null); Assert.That(message.Payload, Is.EqualTo("polling-test")); Assert.That(message.Headers["testProperty"], Is.EqualTo("foo")); Assert.That(message.Headers["testAttribute"], Is.EqualTo(123)); }
public void exceptionThrowingFilterAccepts() { IApplicationContext ctx = TestUtils.GetContext(@"Config\FilterParserTests-context.xml"); IMessageChannel exceptionInput = (IMessageChannel)ctx.GetObject("exceptionInput"); exceptionInput.Send(new StringMessage("test")); IPollableChannel implementationOutput = (IPollableChannel)ctx.GetObject("implementationOutput"); IMessage reply = implementationOutput.Receive(TimeSpan.Zero); Assert.IsNotNull(reply); }
public void filterWithSelectorAdapterRejects() { IApplicationContext ctx = TestUtils.GetContext(@"Config\FilterParserTests-context.xml"); IMessageChannel adapterInput = (IMessageChannel)ctx.GetObject("adapterInput"); adapterInput.Send(new StringMessage("")); IPollableChannel adapterOutput = (IPollableChannel)ctx.GetObject("adapterOutput"); IMessage reply = adapterOutput.Receive(TimeSpan.Zero); Assert.IsNull(reply); }
public void TestPriorityChannelWithIntegerDatatypeEnforced() { IApplicationContext ctx = TestUtils.GetContext(@"Channel\Config\PriorityChannelParserTests.xml"); IPollableChannel channel = (IPollableChannel)ctx.GetObject("integerOnlyPriorityChannel"); channel.Send(new Message <int>(3)); channel.Send(new Message <int>(2)); channel.Send(new Message <int>(1)); Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo(1)); Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo(2)); Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo(3)); }
public void PollableChannel() { IApplicationContext context = TestUtils.GetContext(@"Config\Xml\BridgeParserTests-context.xml"); IMessage message = new StringMessage("test1"); IPollableChannel pollableChannel = (IPollableChannel)context.GetObject("pollableChannel"); pollableChannel.Send(message); IPollableChannel output1 = (IPollableChannel)context.GetObject("output1"); IMessage reply = output1.Receive(TimeSpan.FromMilliseconds(1000)); Assert.That(reply, Is.EqualTo(message)); }
public void filterWithSelectorImplementationAccepts() { IApplicationContext ctx = TestUtils.GetContext(@"Config\FilterParserTests-context.xml"); IMessageChannel implementationInput = (IMessageChannel)ctx.GetObject("implementationInput"); implementationInput.Send(new StringMessage("test")); IPollableChannel implementationOutput = (IPollableChannel)ctx.GetObject("implementationOutput"); IMessage reply = implementationOutput.Receive(TimeSpan.Zero); Assert.IsNotNull(reply); Assert.That(reply.Payload, Is.EqualTo("test")); }
public void SubscribableChannel() { IApplicationContext context = TestUtils.GetContext(@"Config\Xml\BridgeParserTests-context.xml"); IMessage message = new StringMessage("test2"); IMessageChannel subscribableChannel = (IMessageChannel)context.GetObject("subscribableChannel"); subscribableChannel.Send(message); IPollableChannel output2 = (IPollableChannel)context.GetObject("output2"); IMessage reply = output2.Receive(TimeSpan.Zero); Assert.That(reply, Is.EqualTo(message)); }
public void TestRequestReply() { IApplicationContext context = TestUtils.GetContext(@"Config\Xml\gatewayParserTests.xml"); IPollableChannel requestChannel = (IPollableChannel)context.GetObject("requestChannel"); IMessageChannel replyChannel = (IMessageChannel)context.GetObject("replyChannel"); StartResponder(requestChannel, replyChannel); ITestService service = (ITestService)context.GetObject("requestReply"); string result = service.RequestReply("foo"); Assert.That(result, Is.EqualTo("foo")); }
private IMessage DoReceive(IPollableChannel channel) { AssertUtils.ArgumentNotNull(channel, "channel", "channel must not be null"); TimeSpan timeout = _receiveTimeout; IMessage message = (timeout.TotalMilliseconds >= 0) ? channel.Receive(timeout) : channel.Receive(); if (message == null && _logger.IsTraceEnabled) { _logger.Trace("failed to receive message from channel '" + channel + "' within timeout: " + timeout); } return(message); }
public void TestChannelInteceptorRef() { IApplicationContext ctx = TestUtils.GetContext(@"Channel\Config\ChannelInterceptorParserTests.xml"); IPollableChannel channel = (IPollableChannel)ctx.GetObject("channelWithInterceptorRef"); TestChannelInterceptor interceptor = (TestChannelInterceptor)ctx.GetObject("interceptor"); Assert.That(interceptor.SendCount, Is.EqualTo(0)); channel.Send(new StringMessage("test")); Assert.That(interceptor.SendCount, Is.EqualTo(1)); Assert.That(interceptor.ReceiveCount, Is.EqualTo(0)); channel.Receive(); Assert.That(interceptor.ReceiveCount, Is.EqualTo(1)); }
public void Init() { _consumer.Counter.Value = 0; _trigger.Reset(); _channelMock = _mocks.StrictMock<IPollableChannel>(); _endpoint = new PollingConsumer(_channelMock, _consumer); _endpoint.TaskScheduler = _taskScheduler; _taskScheduler.ErrorHandler = _errorHandler; _taskScheduler.Start(); _endpoint.Trigger = _trigger; _endpoint.ReceiveTimeout = TimeSpan.FromMilliseconds(-1); //reset(_channelMock); }
public void Init() { _consumer.Counter.Value = 0; _trigger.Reset(); _channelMock = _mocks.StrictMock <IPollableChannel>(); _endpoint = new PollingConsumer(_channelMock, _consumer); _endpoint.TaskScheduler = _taskScheduler; _taskScheduler.ErrorHandler = _errorHandler; _taskScheduler.Start(); _endpoint.Trigger = _trigger; _endpoint.ReceiveTimeout = TimeSpan.FromMilliseconds(-1); //reset(_channelMock); }
public void chainWithRejectingFilter() { IApplicationContext ctx = TestUtils.GetContext(@"Config\ChainParserTests-context.xml"); IMessage message = MessageBuilder.WithPayload(123).Build(); IMessageChannel filterInput = (IMessageChannel)ctx.GetObject("filterInput"); filterInput.Send(message); IPollableChannel output = (IPollableChannel)ctx.GetObject("output"); IMessage reply = output.Receive(TimeSpan.Zero); Assert.IsNull(reply); }
public void DirectChannelWithObjectMessage() { IApplicationContext context = TestUtils.GetContext(@"Config\Xml\ObjectToStringTransformerParserTests-context.xml"); IMessageChannel directInput = (IMessageChannel)context.GetObject("directInput"); directInput.Send(new Message <TestBean>(new TestBean())); IPollableChannel output = (IPollableChannel)context.GetObject("output"); IMessage result = output.Receive(TimeSpan.Zero); Assert.IsNotNull(result); Assert.That(result.Payload, Is.EqualTo("test")); }
public void QueueChannelWithStringMessage() { IApplicationContext context = TestUtils.GetContext(@"Config\Xml\ObjectToStringTransformerParserTests-context.xml"); IMessageChannel queueInput = (IMessageChannel)context.GetObject("queueInput"); queueInput.Send(new StringMessage("foo")); IPollableChannel output = (IPollableChannel)context.GetObject("output"); IMessage result = output.Receive(TimeSpan.FromMilliseconds(3000)); Assert.IsNotNull(result); Assert.That(result.Payload, Is.EqualTo("foo")); }
public void InitializeSample() { _mocks = new MockRepository(); _requestChannel = _mocks.StrictMock <IMessageChannel>(); _replyChannel = _mocks.StrictMock <IPollableChannel>(); _messageMock = _mocks.StrictMock <IMessage>(); _simpleMessagingGateway = new SimpleMessagingGateway(); _simpleMessagingGateway.RequestChannel = _requestChannel; _simpleMessagingGateway.ReplyChannel = _replyChannel; _simpleMessagingGateway.ObjectFactory = TestUtils.CreateTestApplicationContext(); //reset(_allmocks); }
public void InitializeSample() { _mocks = new MockRepository(); _requestChannel = _mocks.StrictMock<IMessageChannel>(); _replyChannel = _mocks.StrictMock<IPollableChannel>(); _messageMock = _mocks.StrictMock<IMessage>(); _simpleMessagingGateway = new SimpleMessagingGateway(); _simpleMessagingGateway.RequestChannel = _requestChannel; _simpleMessagingGateway.ReplyChannel = _replyChannel; _simpleMessagingGateway.ObjectFactory = TestUtils.CreateTestApplicationContext(); //reset(_allmocks); }
// TODO public void TestCheckedExceptionRethrownAsIs //[Test, ExpectedException(typeof(TestException))] //public void TestCheckedExceptionRethrownAsIs() { // GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject(); // DirectChannel channel = new DirectChannel(); // EventDrivenConsumer consumer = new EventDrivenConsumer(channel, new MessageHandler() { // public void handleMessage(Message<?> message) { // MethodInfo method = ReflectionUtils.GetMethod(typeof(GatewayProxyFactoryObjectTests), "throwTestException",null); // method.Invoke(this, null); // } // }); // consumer.start(); // proxyFactory.setDefaultRequestChannel(channel); // proxyFactory.setServiceInterface(TestExceptionThrowingInterface.class); // proxyFactory.afterPropertiesSet(); // TestExceptionThrowingInterface proxy = (TestExceptionThrowingInterface) proxyFactory.getObject(); // proxy.throwCheckedException("test"); //} private static void StartResponder(IPollableChannel requestChannel) { new Thread(new ThreadStart(delegate { IMessage input = requestChannel.Receive(); StringMessage reply = new StringMessage(input.Payload + "bar"); ((IMessageChannel) input.Headers.ReplyChannel).Send(reply); })).Start(); }