Beispiel #1
0
        public void SendHeader()
        {
            var o = new GlobalOptionsFactory().Load();

            var consumerOptions = new ConsumerOptions();

            consumerOptions.QueueName        = "TEST.HeaderPreservationTest_Read1";
            consumerOptions.AutoAck          = false;
            consumerOptions.QoSPrefetchCount = 1;

            TestConsumer consumer;

            using (var tester = new MicroserviceTester(o.RabbitOptions, consumerOptions))
            {
                var header = new MessageHeader();
                header.MessageGuid = Guid.Parse("5afce68f-c270-4bf3-b327-756f6038bb76");
                header.Parents     = new[] { Guid.Parse("12345678-c270-4bf3-b327-756f6038bb76"), Guid.Parse("87654321-c270-4bf3-b327-756f6038bb76") };

                tester.SendMessage(consumerOptions, header, new TestMessage()
                {
                    Message = "hi"
                });

                consumer = new TestConsumer();
                var a = new RabbitMqAdapter(o.RabbitOptions.CreateConnectionFactory(), "TestHost");
                a.StartConsumer(consumerOptions, consumer);

                TestTimelineAwaiter awaiter = new TestTimelineAwaiter();
                awaiter.Await(() => consumer.Failed || consumer.Passed, "timed out", 5000);
                a.Shutdown(RabbitMqAdapter.DefaultOperationTimeout);
            }

            Assert.IsTrue(consumer.Passed);
        }
Beispiel #2
0
        public void Test_Shutdown(Type consumerType)
        {
            MemoryTarget target = new MemoryTarget();

            target.Layout = "${message}";

            NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

            var o = new GlobalOptionsFactory().Load();

            var consumer = (IConsumer)Activator.CreateInstance(consumerType);

            //connect to rabbit with a new consumer
            using (var tester = new MicroserviceTester(o.RabbitOptions, new [] { _testConsumerOptions }))
            {
                _testAdapter.StartConsumer(_testConsumerOptions, consumer, true);

                //send a message to trigger consumer behaviour
                tester.SendMessage(_testConsumerOptions, new TestMessage());

                //give the message time to get picked up
                Thread.Sleep(3000);

                //now attempt to shut down adapter
                _testAdapter.Shutdown(RabbitMqAdapter.DefaultOperationTimeout);

                string expectedErrorMessage = "nothing to see here";

                if (consumer is SelfClosingConsumer)
                {
                    expectedErrorMessage = "exiting (channel is closed)";
                }
                if (consumer is DoNothingConsumer)
                {
                    expectedErrorMessage = "exiting (cancellation was requested)";
                }

                Assert.IsTrue(target.Logs.Any(s => s.Contains(expectedErrorMessage)), "Expected message was not found, messages were:" + string.Join(Environment.NewLine, target.Logs));
            }
        }
Beispiel #3
0
        public void SetUp()
        {
            _testOptions = new GlobalOptionsFactory().Load();

            _testProducerOptions = new ProducerOptions
            {
                ExchangeName = "TEST.TestExchange"
            };

            _testConsumerOptions = new ConsumerOptions
            {
                QueueName        = "TEST.TestQueue",
                QoSPrefetchCount = 1,
                AutoAck          = false
            };

            _mockConsumer = Mock.Of <Consumer <IMessage> >();

            _testAdapter = new RabbitMqAdapter(_testOptions.RabbitOptions.CreateConnectionFactory(), "RabbitMqAdapterTests");

            _tester = new MicroserviceTester(_testOptions.RabbitOptions, _testConsumerOptions);
        }
Beispiel #4
0
 public TestTimeline(MicroserviceTester tester)
 {
     _tester = tester;
 }