Beispiel #1
0
        public void TestExceptionInOnMessageReleasesInAutoAckMode()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = EstablishConnection(testPeer);
                connection.Start();

                testPeer.ExpectBegin();

                ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue   queue   = session.GetQueue("myQueue");

                testPeer.ExpectReceiverAttach();
                testPeer.ExpectLinkFlowRespondWithTransfer(message: new Amqp.Message()
                {
                    BodySection = new AmqpValue()
                    {
                        Value = null
                    }
                }, count: 1);
                testPeer.ExpectDispositionThatIsReleasedAndSettled();

                IMessageConsumer consumer = session.CreateConsumer(queue);
                consumer.Listener += message => throw new Exception();

                testPeer.WaitForAllMatchersToComplete(2000);

                testPeer.ExpectClose();
                connection.Close();

                testPeer.WaitForAllMatchersToComplete(10000);
            }
        }
        public void TestSendTimesOutWhenNoDispositionArrives()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = EstablishConnection(testPeer, optionsString: "nms.sendTimeout=500");
                testPeer.ExpectBegin();

                ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue   queue   = session.GetQueue("myQueue");

                ITextMessage message = session.CreateTextMessage("text");

                // Expect the producer to attach and grant it some credit, it should send
                // a transfer which we will not send any response for which should cause the
                // send operation to time out.
                testPeer.ExpectSenderAttach();
                testPeer.ExpectTransferButDoNotRespond(messageMatcher: Assert.NotNull);

                // When send operation timed out, released and settled disposition is issued by the provider
                testPeer.ExpectDispositionThatIsReleasedAndSettled();
                testPeer.ExpectClose();

                IMessageProducer producer = session.CreateProducer(queue);

                Assert.Catch <Exception>(() => producer.Send(message), "Send should time out.");

                connection.Close();

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }
Beispiel #3
0
        public async Task TestExceptionInOnMessageReleasesInAutoAckMode()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                var context = await EstablishNMSContextAsync(testPeer);

                await context.StartAsync();

                testPeer.ExpectBegin();

                IQueue queue = await context.GetQueueAsync("myQueue");

                testPeer.ExpectReceiverAttach();
                testPeer.ExpectLinkFlowRespondWithTransfer(message: new Amqp.Message()
                {
                    BodySection = new AmqpValue()
                    {
                        Value = null
                    }
                }, count: 1);
                testPeer.ExpectDispositionThatIsReleasedAndSettled();

                var consumer = await context.CreateConsumerAsync(queue);

                consumer.Listener += message => throw new Exception();

                testPeer.WaitForAllMatchersToComplete(2000);

                testPeer.ExpectEnd();
                testPeer.ExpectClose();
                await context.CloseAsync();

                testPeer.WaitForAllMatchersToComplete(10000);
            }
        }
Beispiel #4
0
        public void TestCloseDurableSubscriberWithUnackedAndUnconsumedPrefetchedMessages()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = EstablishConnection(testPeer);
                connection.Start();

                testPeer.ExpectBegin();

                ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);

                string topicName        = "myTopic";
                string subscriptionName = "mySubscription";
                ITopic topic            = session.GetTopic(topicName);

                int messageCount = 5;
                // Create a consumer and fill the prefetch with some messages,
                // which we will consume some of but ack none of.
                testPeer.ExpectDurableSubscriberAttach(topicName, subscriptionName);
                testPeer.ExpectLinkFlowRespondWithTransfer(message: CreateMessageWithContent(), count: messageCount);

                IMessageConsumer durableConsumer = session.CreateDurableConsumer(topic, subscriptionName, null, false);

                int      consumeCount    = 2;
                IMessage receivedMessage = null;
                for (int i = 1; i <= consumeCount; i++)
                {
                    receivedMessage = durableConsumer.Receive();
                    Assert.NotNull(receivedMessage);
                    Assert.IsInstanceOf <NmsTextMessage>(receivedMessage);
                }

                // Expect the messages that were not delivered to be released.
                for (int i = 1; i <= consumeCount; i++)
                {
                    testPeer.ExpectDispositionThatIsAcceptedAndSettled();
                }

                receivedMessage.Acknowledge();

                testPeer.ExpectDetach(expectClosed: false, sendResponse: true, replyClosed: false);

                for (int i = consumeCount + 1; i <= messageCount; i++)
                {
                    testPeer.ExpectDispositionThatIsReleasedAndSettled();
                }

                testPeer.ExpectEnd();

                durableConsumer.Close();
                session.Close();

                testPeer.ExpectClose();
                connection.Close();

                testPeer.WaitForAllMatchersToComplete(3000);
            }
        }