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));
        }
        private void RegisterReplyMessageCorrelator()
        {
            lock (_replyMessageCorrelatorMonitor) {
                if (_replyMessageCorrelator != null)
                {
                    return;
                }
                AbstractEndpoint correlator = null;
                IMessageHandler  handler    = new LocalReplyProducingMessageHandler();

                if (_replyChannel is ISubscribableChannel)
                {
                    correlator = new EventDrivenConsumer((ISubscribableChannel)_replyChannel, handler);
                }
                else if (_replyChannel is IPollableChannel)
                {
                    PollingConsumer endpoint = new PollingConsumer(
                        (IPollableChannel)_replyChannel, handler);
                    endpoint.Trigger       = new IntervalTrigger(TimeSpan.FromMilliseconds(10));
                    endpoint.ObjectFactory = ObjectFactory;
                    endpoint.AfterPropertiesSet();
                    correlator = endpoint;
                }
                if (IsRunning)
                {
                    if (correlator == null)
                    {
                        throw new InvalidOperationException("correlator must not be null");
                    }

                    ((ILifecycle)correlator).Start();
                }
                _replyMessageCorrelator = correlator;
            }
        }
        public void testDefaultResequencerProperties()
        {
            EventDrivenConsumer endpoint    = (EventDrivenConsumer)context.GetObject("defaultResequencer");
            Resequencer         resequencer = (Resequencer)TestUtils.GetFieldValue(endpoint, "_handler");

            Assert.IsNull(TestUtils.GetFieldValue(resequencer, "_outputChannel"));
            Assert.IsNull(TestUtils.GetFieldValue(resequencer, "_discardChannel"));
            MessageChannelTemplate channelTemplate =
                (MessageChannelTemplate)TestUtils.GetFieldValue(resequencer, "_channelTemplate");

            Assert.That(TestUtils.GetFieldValue(channelTemplate, "_sendTimeout"),
                        Is.EqualTo(TimeSpan.FromMilliseconds(1000l)),
                        "The ResequencerEndpoint is not set with the appropriate timeout value");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_sendPartialResultOnTimeout"), Is.EqualTo(false),
                        "The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' flag");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_reaperInterval"),
                        Is.EqualTo(TimeSpan.FromMilliseconds(1000l)),
                        "The ResequencerEndpoint is not configured with the appropriate reaper interval");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_trackedCorrelationIdCapacity"), Is.EqualTo(1000),
                        "The ResequencerEndpoint is not configured with the appropriate tracked correlationId capacity");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_timeout"), Is.EqualTo(TimeSpan.FromMilliseconds(60000l)),
                        "The ResequencerEndpoint is not configured with the appropriate timeout");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_releasePartialSequences"), Is.EqualTo(true),
                        "The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag");
        }
        public void testPropertyAssignment()
        {
            EventDrivenConsumer endpoint       = (EventDrivenConsumer)context.GetObject("completelyDefinedResequencer");
            IMessageChannel     outputChannel  = (IMessageChannel)context.GetObject("outputChannel");
            IMessageChannel     discardChannel = (IMessageChannel)context.GetObject("discardChannel");
            Resequencer         resequencer    = (Resequencer)TestUtils.GetFieldValue(endpoint, "_handler");

            Assert.That(TestUtils.GetFieldValue(resequencer, "_outputChannel"), Is.EqualTo(outputChannel),
                        "The ResequencerEndpoint is not injected with the appropriate output channel");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_discardChannel"), Is.EqualTo(discardChannel),
                        "The ResequencerEndpoint is not injected with the appropriate discard channel");
            MessageChannelTemplate channelTemplate =
                (MessageChannelTemplate)TestUtils.GetFieldValue(resequencer, "_channelTemplate");

            Assert.That(TestUtils.GetFieldValue(channelTemplate, "_sendTimeout"),
                        Is.EqualTo(TimeSpan.FromMilliseconds(86420000l)),
                        "The ResequencerEndpoint is not set with the appropriate timeout value");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_sendPartialResultOnTimeout"), Is.EqualTo(true),
                        "The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' flag");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_reaperInterval"),
                        Is.EqualTo(TimeSpan.FromMilliseconds(135l)),
                        "The ResequencerEndpoint is not configured with the appropriate reaper interval");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_trackedCorrelationIdCapacity"), Is.EqualTo(99),
                        "The ResequencerEndpoint is not configured with the appropriate tracked correlationId capacity");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_timeout"), Is.EqualTo(TimeSpan.FromMilliseconds(42l)),
                        "The ResequencerEndpoint is not configured with the appropriate timeout");
            Assert.That(TestUtils.GetFieldValue(resequencer, "_releasePartialSequences"), Is.EqualTo(false),
                        "The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag");
        }
Пример #5
0
        public void GatewayWithOrder()
        {
            XmlApplicationContext ctx      = (XmlApplicationContext)NmsTestUtils.GetContext(@"Nms\Config\NmsOutboundGatewayWithOrder.xml");
            EventDrivenConsumer   endpoint = (EventDrivenConsumer)ctx.GetObject("nmsGateway");
            // NmsOutboundGateway._handler.
            object order = TestUtils.GetFieldValue(TestUtils.GetFieldValue(endpoint, "_handler"),
                                                   "order");

            Assert.That(order, Is.EqualTo(99));
        }
        public void AdapterWithConnectionFactoryAndDestination()
        {
            IApplicationContext ctx      = NmsTestUtils.GetContext(@"Nms\Config\NmsOutboundWithConnectionFactoryAndDestination.xml");
            EventDrivenConsumer endpoint = (EventDrivenConsumer)ctx.GetObject("adapter");
            object handler = TestUtils.GetFieldValue(endpoint, "_handler");

            Assert.That(handler, Is.Not.Null);
            object template = TestUtils.GetFieldValue(handler, "nmsTemplate");

            Assert.That(template, Is.Not.Null);
        }
        public void TestCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler()
        {
            IMessage                 message          = new StringMessage("test");
            DirectChannel            inputChannel     = new DirectChannel();
            QueueChannel             outputChannel    = new QueueChannel(1);
            ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "CreateMessage");

            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("456-XYZ"));
        }
        public void TestCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler()
        {
            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(), "CreateMessage");

            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("456-XYZ"));
        }
        public void TestCorrelationIdCopiedFromMessageCorrelationIdIfAvailable()
        {
            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(message.Headers.CorrelationId));
            Assert.IsTrue(message.Headers.CorrelationId.Equals(reply.Headers.CorrelationId));
        }
Пример #10
0
        private void ConfigureChain()
        {
            DirectChannel           channel  = null;
            IList <IMessageHandler> handlers = _handlers;

            for (int i = 0; i < handlers.Count; i++)
            {
                bool            first   = (i == 0);
                bool            last    = (i == handlers.Count - 1);
                IMessageHandler handler = handlers[i];
                if (!first)
                {
                    EventDrivenConsumer consumer = new EventDrivenConsumer(channel, handler);
                    consumer.Start();
                }
                if (!last)
                {
                    if (!(handler is AbstractReplyProducingMessageHandler))
                    {
                        throw new ArgumentException("All handlers except for the last one in the chain must implement " + typeof(AbstractReplyProducingMessageHandler).Name);
                    }
                    channel            = new DirectChannel();
                    channel.ObjectName = "_" + this + ".channel#" + i;
                    ((AbstractReplyProducingMessageHandler)handler).OutputChannel = channel;
                }
                else if (handler is AbstractReplyProducingMessageHandler)
                {
                    IMessageChannel replyChannel = (_outputChannel != null) ? _outputChannel : new ReplyForwardingMessageChannel(this);
                    ((AbstractReplyProducingMessageHandler)handler).OutputChannel = replyChannel;
                }
                else
                {
                    if (_outputChannel == null)
                    {
                        throw new ArgumentException("An output channel was provided, but the final handler in the chain is not an "
                                                    + "instance of [" + typeof(AbstractReplyProducingMessageHandler).Name + "]");
                    }
                }
            }
        }
        public void TestPropertyAssignment()
        {
            EventDrivenConsumer endpoint           = (EventDrivenConsumer)_ctx.GetObject("completelyDefinedAggregator");
            ICompletionStrategy completionStrategy = (ICompletionStrategy)_ctx.GetObject("completionStrategy");
            IMessageChannel     outputChannel      = (IMessageChannel)_ctx.GetObject("outputChannel");
            IMessageChannel     discardChannel     = (IMessageChannel)_ctx.GetObject("discardChannel");

            object consumer =
                endpoint.GetType().GetField("_handler", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(
                    endpoint);

            Assert.That(typeof(MethodInvokingAggregator), Is.EqualTo(consumer.GetType()));

            //DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
            MethodInfo expectedMethod = typeof(TestAggregatorObject).GetMethod("CreateSingleMessageFromGroup");

            Assert.That(TestUtils.GetFieldValue(TestUtils.GetFieldValue(consumer, "_methodInvoker"), "_method"),
                        Is.EqualTo(expectedMethod),
                        "The MethodInvokingAggregator is not injected with the appropriate aggregation method");
            Assert.That(TestUtils.GetFieldValue(consumer, "_completionStrategy"), Is.EqualTo(completionStrategy),
                        "The AggregatorEndpoint is not injected with the appropriate CompletionStrategy instance");
            Assert.That(TestUtils.GetFieldValue(consumer, "_outputChannel"), Is.EqualTo(outputChannel),
                        "The AggregatorEndpoint is not injected with the appropriate output channel");
            Assert.That(TestUtils.GetFieldValue(consumer, "_discardChannel"), Is.EqualTo(discardChannel),
                        "The AggregatorEndpoint is not injected with the appropriate discard channel");
            Assert.That(TestUtils.GetFieldValue(TestUtils.GetFieldValue(consumer, "_channelTemplate"), "_sendTimeout"),
                        Is.EqualTo(TimeSpan.FromMilliseconds(86420000l)),
                        "The AggregatorEndpoint is not set with the appropriate timeout value");
            Assert.That(TestUtils.GetFieldValue(consumer, "_sendPartialResultOnTimeout"), Is.True,
                        "The AggregatorEndpoint is not configured with the appropriate 'send partial results on timeout' flag");
            Assert.That(TestUtils.GetFieldValue(consumer, "_reaperInterval"),
                        Is.EqualTo(TimeSpan.FromMilliseconds(135l)),
                        "The AggregatorEndpoint is not configured with the appropriate reaper interval");
            Assert.That(TestUtils.GetFieldValue(consumer, "_trackedCorrelationIdCapacity"), Is.EqualTo(99),
                        "The AggregatorEndpoint is not configured with the appropriate tracked correlationId capacity");
            Assert.That(TestUtils.GetFieldValue(consumer, "_timeout"), Is.EqualTo(TimeSpan.FromMilliseconds(42l)),
                        "The AggregatorEndpoint is not configured with the appropriate timeout");
        }