Ejemplo n.º 1
0
        public void Enqueue_GetsFirstInsertedItem()
        {
            var delivery1 = new Delivery(new Message());
            var delivery2 = new Delivery(new Message());
            var queue     = new DeliveryQueue();

            queue.Enqueue(delivery1);
            queue.Enqueue(delivery2);

            queue.Dequeue(CancellationToken.None).ShouldBeSameAs(delivery1.Message);
        }
Ejemplo n.º 2
0
        public void Enqueue_SetsMessageSequenceInOrder()
        {
            var message1 = new Message();
            var message2 = new Message();
            var queue    = new DeliveryQueue();

            queue.Enqueue(new Delivery(message1));
            queue.Enqueue(new Delivery(message2));

            message1.MessageAnnotations[(Symbol)"x-opt-sequence-number"].ShouldBe(1L);
            message2.MessageAnnotations[(Symbol)"x-opt-sequence-number"].ShouldBe(2L);
        }
Ejemplo n.º 3
0
        public async Task Process_CompleteSuccessfully_WhenOutgoingLinkQueueFound()
        {
            const string     linkName        = "abcd";
            const string     entity          = "entity";
            ISecurityContext securityContext = Substitute.For <ISecurityContext>();
            IEntityLookup    entityLookup    = Substitute.For <IEntityLookup>();
            ILoggerProvider  loggerProvider  = Substitute.For <ILoggerProvider>();

            Entities.IEntity fakeEntity = Substitute.For <Entities.IEntity>();
            var deliveryQueue           = new DeliveryQueue();
            var linkProcessor           = new LinkProcessor(securityContext, entityLookup, loggerProvider);

            entityLookup.Find(Arg.Any <string>()).Returns(fakeEntity);
            securityContext.IsAuthorized(Arg.Any <Connection>()).Returns(true);
            fakeEntity.DeliveryQueue.Returns(deliveryQueue);
            Session session = await TestAmqpHost.OpenAndLinkProcessorAsync(linkProcessor);

            try
            {
                var receiver = new ReceiverLink(session, linkName, entity);
                deliveryQueue.Enqueue(new Delivery(new Message {
                    Properties = new Properties {
                        MessageId = "msgid6746"
                    }
                }));

                Message message = await receiver.ReceiveAsync();

                message.Properties.MessageId.ShouldBe("msgid6746");
            }
            finally
            {
                await session.Connection.CloseAsync();
            }
        }
Ejemplo n.º 4
0
        public void Enqueue_AddsDeliveryToQueue()
        {
            var cts      = new CancellationTokenSource(TimeSpan.FromMilliseconds(50));
            var delivery = new Delivery(new Message());
            var queue    = new DeliveryQueue();

            queue.Enqueue(delivery);

            queue.Dequeue(cts.Token).ShouldBeSameAs(delivery.Message);
        }
Ejemplo n.º 5
0
        public void Dispose_DisposesQueue()
        {
            var delivery = new Delivery(new Message());
            var queue    = new DeliveryQueue();

            queue.Dispose();

            Should.Throw <ObjectDisposedException>(() => queue.Enqueue(delivery));
            Should.Throw <ObjectDisposedException>(() => queue.Dequeue(CancellationToken.None));
            Should.Throw <ObjectDisposedException>(() => queue.Process(null));
        }
Ejemplo n.º 6
0
        public async Task Enqueue_SetsUniqueMessageForSimultaniousDeliveries()
        {
            var queue = new DeliveryQueue();

            Message[]          messages     = Enumerable.Range(1, 16).Select(_ => new Message()).ToArray();
            IEnumerable <Task> enqueueTasks = messages
                                              .Select(message => Task.Run(() => queue.Enqueue(new Delivery(message))));

            await Task.WhenAll(enqueueTasks);

            var sequenceIds = messages
                              .Select(message => (long)message.MessageAnnotations[(Symbol)"x-opt-sequence-number"])
                              .ToArray();

            sequenceIds.ShouldBeUnique();
        }
Ejemplo n.º 7
0
        public IDelivery Post(Message message)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(typeof(QueueEntity).Name);
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            var delivery = new Delivery(message);

            _deliveryQueue.Enqueue(delivery);
            _deliveries.Add(delivery);
            return(delivery);
        }
Ejemplo n.º 8
0
        public void Process_ProcessesDelivery()
        {
            var message = new Message();

            message.InitializePrivateProperty("Delivery");
            ListenerLink   link           = Construct.Uninitialized <ListenerLink>();
            MessageContext messageContext = Construct.ForPrivate <MessageContext>(link, message);
            var            delivery       = new Delivery(message);
            var            queue          = new DeliveryQueue();

            queue.Enqueue(delivery);
            queue.Dequeue(CancellationToken.None);

            queue.Process(messageContext);

            delivery.Processed.ShouldNotBeNull();
        }
Ejemplo n.º 9
0
        public void HandleClosingMessage()
        {
            // Create a delivery policy specifying a maximum queue size of 1
            var deliveryPolicy = new DeliveryPolicy <int>(
                1,
                1,
                null,
                null,
                false,
                guaranteeDelivery: value => value == 2, // only guarantee message value is 2
                "TestDeliveryPolicy");

            var deliveryQueue = new DeliveryQueue <int>(deliveryPolicy, RecyclingPool.Create <int>());

            // Enqueue a closing message - message should be queued
            deliveryQueue.Enqueue(
                Message.Create(0, DateTime.UtcNow, DateTime.UtcNow, 0, int.MaxValue), // closing message
                null,