Beispiel #1
0
        public void TestCloseDurableTopicSubscriberDetachesWithCloseFalse()
        {
            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);

                testPeer.ExpectDurableSubscriberAttach(topicName, subscriptionName);
                testPeer.ExpectLinkFlow();

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

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

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

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }
Beispiel #2
0
        public async Task TestCreateDurableConsumer()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = await EstablishConnectionAsync(testPeer);

                await connection.StartAsync();

                testPeer.ExpectBegin();
                ISession session = await connection.CreateSessionAsync(AcknowledgementMode.AutoAcknowledge);

                string topicName = "myTopic";
                ITopic topic     = await session.GetTopicAsync(topicName);

                string subscriptionName = "mySubscription";

                testPeer.ExpectDurableSubscriberAttach(topicName, subscriptionName);
                testPeer.ExpectLinkFlow();

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

                Assert.NotNull(durableConsumer, "MessageConsumer object was null");

                testPeer.ExpectClose();
                await connection.CloseAsync();

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }
        public async Task TestCreateDurableConsumer()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                var context = await EstablishNMSContextAsync(testPeer);

                await context.StartAsync();

                testPeer.ExpectBegin();

                string topicName = "myTopic";
                ITopic topic     = await context.GetTopicAsync(topicName);

                string subscriptionName = "mySubscription";

                testPeer.ExpectDurableSubscriberAttach(topicName, subscriptionName);
                testPeer.ExpectLinkFlow();

                var durableConsumer = await context.CreateDurableConsumerAsync(topic, subscriptionName, null, false);

                Assert.NotNull(durableConsumer, "MessageConsumer object was null");

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

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }
        public void TestCloseDurableTopicSubscriberDetachesWithCloseFalse()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                var context = EstablishNMSContext(testPeer);
                context.Start();

                testPeer.ExpectBegin();

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

                testPeer.ExpectDurableSubscriberAttach(topicName, subscriptionName);
                testPeer.ExpectLinkFlow();

                var durableConsumer = context.CreateDurableConsumer(topic, subscriptionName, null, false);

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

                testPeer.ExpectEnd();
                testPeer.ExpectClose();
                context.Close();

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }
Beispiel #5
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);
            }
        }
        public async Task TestUnsubscribeExclusiveDurableSubWhileActiveThenInactive()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = await EstablishConnectionAsync(testPeer);

                await connection.StartAsync();

                testPeer.ExpectBegin();
                ISession session = await connection.CreateSessionAsync(AcknowledgementMode.AutoAcknowledge);

                String topicName = "myTopic";
                ITopic dest      = await session.GetTopicAsync("myTopic");

                String subscriptionName = "mySubscription";

                // Attach the durable exclusive receiver
                testPeer.ExpectDurableSubscriberAttach(topicName: topicName, subscriptionName: subscriptionName);
                testPeer.ExpectLinkFlow();

                IMessageConsumer consumer = await session.CreateDurableConsumerAsync(dest, subscriptionName, null, false);

                Assert.NotNull(consumer, "TopicSubscriber object was null");

                // Now try to unsubscribe, should fail
                Assert.CatchAsync <NMSException>(async() => session.DeleteDurableConsumer(subscriptionName));

                // Now close the subscriber
                testPeer.ExpectDetach(expectClosed: false, sendResponse: true, replyClosed: false);

                await consumer.CloseAsync();

                // Try to unsubscribe again, should work now
                testPeer.ExpectDurableSubUnsubscribeNullSourceLookup(failLookup: false, shared: false, subscriptionName: subscriptionName, topicName: topicName, hasClientId: true);
                testPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true);

                session.DeleteDurableConsumer(subscriptionName);

                testPeer.WaitForAllMatchersToComplete(1000);

                testPeer.ExpectClose();
                await connection.CloseAsync();

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }