public void TestDequeueNoWait3()
 {
     SharedQueue q = new SharedQueue();
     Assert.AreEqual(null, q.DequeueNoWait(null));
 }
 public void TestDequeueNoWait2()
 {
     SharedQueue q = new SharedQueue();
     q.Enqueue(1);
     Assert.AreEqual(1, q.Dequeue());
     Assert.AreEqual(0, q.DequeueNoWait(0));
 }
 public void TestDelayedEnqueue()
 {
     SharedQueue q = new SharedQueue();
     ResetTimer();
     EnqueueAfter(TimingInterval, q, 1);
     Assert.AreEqual(0, q.DequeueNoWait(0));
     Assert.Greater(TimingInterval - SafetyMargin, ElapsedMs());
     Assert.AreEqual(1, q.Dequeue());
     Assert.Less(TimingInterval - SafetyMargin, ElapsedMs());
 }
 public void TestCloseWhenFull()
 {
     SharedQueue q = new SharedQueue();
     object v;
     q.Enqueue(1);
     q.Enqueue(2);
     q.Enqueue(3);
     q.Close();
     DelayedEnqueuer de = new DelayedEnqueuer(q, 0, 4);
     ExpectEof(new Thunk(de.EnqueueValue));
     Assert.AreEqual(1, q.Dequeue());
     Assert.AreEqual(2, q.DequeueNoWait(0));
     bool r = q.Dequeue(1, out v);
     Assert.IsTrue(r);
     Assert.AreEqual(3, v);
     ExpectEof(new Thunk(de.Dequeue));
 }
        private bool TryGetRequest(SharedQueue<BasicDeliverEventArgs> queue, out HttpRequestPacket request, out IBasicProperties properties)
        {
            object obj;
            BasicDeliverEventArgs evt;
            request = null;
            properties = null;

            obj = queue.DequeueNoWait(null);
            if (obj != null)
            {
                 evt = (BasicDeliverEventArgs)obj;
            }
            else
            {
                return false;
            }

            //Get message properties
            properties = evt.BasicProperties;

            //Deserialize message
            bool wasDeserialized = true;

            try
            {
                request = HttpRequestPacket.Deserialize(evt.Body);

                //Add/Update Content-Length Header
                request.Headers["Content-Length"] = new string[] { (request.Content == null ? 0 : request.Content.Length).ToString() };

                //Add/Update Subscriber-Id header
                request.Headers[Common.Shared.SUBSCRIBER_ID_HEADER] = new string[] { this.subscriberId };

            }
            catch
            {

                wasDeserialized = false;
            }

            //Ack or reject message
            if (evt.ConsumerTag == workConsumer.ConsumerTag)
            {
                if (wasDeserialized)
                {
                    workConsumer.Model.BasicAck(evt.DeliveryTag, false);
                    return true;
                }
                else
                {
                    workConsumer.Model.BasicReject(evt.DeliveryTag, false);
                    return false;
                }
            }
            else if (evt.ConsumerTag == subscriberConsumer.ConsumerTag)
            {
                if (wasDeserialized)
                {
                    subscriberConsumer.Model.BasicAck(evt.DeliveryTag, false);
                    return true;
                }
                else
                {
                    subscriberConsumer.Model.BasicReject(evt.DeliveryTag, false);
                    return false;
                }
            }
            else
            {
                throw new InvalidOperationException("Message was dequeued by an unexpected/unknown consumer");
            }
        }
 public void TestDequeueNoWait1()
 {
     var queue = new SharedQueue();
     queue.Enqueue(1);
     Assert.AreEqual(1, queue.DequeueNoWait(0));
     Assert.AreEqual(0, queue.DequeueNoWait(0));
 }