public override void Init()
        {
            var connFactory = new ConnectionFactory()
            {
                AutomaticRecoveryEnabled = false
            };

            Conn  = connFactory.CreateConnection();
            Model = Conn.CreateModel();
        }
        public override void Init()
        {
            var connFactory = new ConnectionFactory()
            {
                RequestedHeartbeat       = TimeSpan.FromSeconds(60),
                AutomaticRecoveryEnabled = false
            };

            Conn  = connFactory.CreateConnection();
            Model = Conn.CreateModel();
        }
Exemple #3
0
 protected void TestConcurrentChannelOpenAndPublishingWithBody(byte[] body, int iterations)
 {
     TestConcurrentChannelOperations((conn) => {
         // publishing on a shared channel is not supported
         // and would missing the point of this test anyway
         var ch = Conn.CreateModel();
         ch.ConfirmSelect();
         foreach (var j in Enumerable.Range(0, 200))
         {
             ch.BasicPublish(exchange: "", routingKey: "_______", basicProperties: ch.CreateBasicProperties(), body: body);
         }
         ch.WaitForConfirms(TimeSpan.FromSeconds(40));
     }, iterations);
 }
        public void TestDeliveryOrderingWithSingleChannel()
        {
            var Ch = Conn.CreateModel();

            Ch.ExchangeDeclare(x, "fanout", durable: false);

            for (int i = 0; i < y; i++)
            {
                var ch = Conn.CreateModel();
                var q  = ch.QueueDeclare("", durable: false, exclusive: true, autoDelete: true, arguments: null);
                ch.QueueBind(queue: q, exchange: x, routingKey: "");
                channels.Add(ch);
                queues.Add(q);
                var cons = new CollectingConsumer(ch);
                consumers.Add(cons);
                ch.BasicConsume(queue: q, noAck: false, consumer: cons);
            }

            for (int i = 0; i < n; i++)
            {
                Ch.BasicPublish(exchange: x, routingKey: "",
                                basicProperties: new BasicProperties(),
                                body: encoding.GetBytes("msg"));
            }
            counter.Wait(TimeSpan.FromSeconds(30));

            foreach (var cons in consumers)
            {
                Assert.That(cons.DeliveryTags, Has.Count.EqualTo(n));
                var ary = cons.DeliveryTags.ToArray();
                Assert.AreEqual(ary[0], 1);
                Assert.AreEqual(ary[n - 1], n);
                for (int i = 0; i < (n - 1); i++)
                {
                    var a = ary[i];
                    var b = ary[i + 1];

                    Assert.IsTrue(a < b);
                }
            }
        }
Exemple #5
0
        protected void TestWaitForConfirms(int numberOfMessagesToPublish, Action <IModel> fn)
        {
            var ch = Conn.CreateModel();

            ch.ConfirmSelect();

            var q = ch.QueueDeclare().QueueName;

            for (int i = 0; i < numberOfMessagesToPublish; i++)
            {
                ch.BasicPublish("", q, null, encoding.GetBytes("msg"));
            }
            try
            {
                fn(ch);
            } finally
            {
                ch.QueueDelete(q);
                ch.Close();
            }
        }
Exemple #6
0
        public void TestClientNamedTransientAutoDeleteQueueAndBindingRecovery()
        {
            var q  = Guid.NewGuid().ToString();
            var x  = "tmp-fanout";
            var ch = Conn.CreateModel();

            ch.QueueDelete(q);
            ch.ExchangeDelete(x);
            ch.ExchangeDeclare(exchange: x, type: "fanout");
            ch.QueueDeclare(queue: q, durable: false, exclusive: false, autoDelete: true, arguments: null);
            ch.QueueBind(queue: q, exchange: x, routingKey: "");
            RestartServerAndWaitForRecovery();
            Assert.IsTrue(ch.IsOpen);
            ch.ConfirmSelect();
            ch.QueuePurge(q);
            ch.ExchangeDeclare(exchange: x, type: "fanout");
            ch.BasicPublish(exchange: x, routingKey: "", basicProperties: null, body: encoding.GetBytes("msg"));
            WaitForConfirms(ch);
            var ok = ch.QueueDeclare(queue: q, durable: false, exclusive: false, autoDelete: true, arguments: null);

            Assert.AreEqual(1, ok.MessageCount);
            ch.QueueDelete(q);
            ch.ExchangeDelete(x);
        }
Exemple #7
0
        public void TestWaitForConfirmsWithEvents()
        {
            IModel ch = Conn.CreateModel();

            ch.ConfirmSelect();

            ch.QueueDeclare(QueueName);
            int n = 200;
            // number of event handler invocations
            int c = 0;

            ch.BasicAcks += (_, args) =>
            {
                Interlocked.Increment(ref c);
            };
            try
            {
                for (int i = 0; i < n; i++)
                {
                    ch.BasicPublish("", QueueName, null, encoding.GetBytes("msg"));
                }
                Thread.Sleep(TimeSpan.FromSeconds(1));
                ch.WaitForConfirms(TimeSpan.FromSeconds(5));

                // Note: number of event invocations is not guaranteed
                // to be equal to N because acks can be batched,
                // so we primarily care about event handlers being invoked
                // in this test
                Assert.IsTrue(c > 20);
            }
            finally
            {
                ch.QueueDelete(QueueName);
                ch.Close();
            }
        }
 public override void Init()
 {
     Conn  = CreateAutorecoveringConnection();
     Model = Conn.CreateModel();
 }
Exemple #9
0
        public void TestNullRoutingKeyIsRejected()
        {
            IModel ch = Conn.CreateModel();

            Assert.Throws(typeof(ArgumentNullException), () => ch.BasicPublish("", null, null, encoding.GetBytes("msg")));
        }