Ejemplo n.º 1
0
        public void TestCloseDurableTopicSubscriberDetachesWithCloseFalse()
        {
            using (var testListener = new TestListener(IPEndPoint))
            {
                testListener.Open();
                Amqp.Types.List  result           = null;
                ManualResetEvent manualResetEvent = new ManualResetEvent(false);

                testListener.RegisterTarget(TestPoint.Detach, (stream, channel, fields) =>
                {
                    TestListener.FRM(stream, 0x16UL, 0, channel, fields[0], false);
                    result = fields;
                    manualResetEvent.Set();
                    return(TestOutcome.Stop);
                });

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

                string           topicName        = "myTopic";
                string           subscriptionName = "mySubscription";
                ITopic           topic            = session.GetTopic(topicName);
                IMessageConsumer durableConsumer  = session.CreateDurableConsumer(topic, subscriptionName, null, false);
                durableConsumer.Close();

                manualResetEvent.WaitOne(TimeSpan.FromMilliseconds(100));

                // Assert that closed field is set to false
                Assert.IsFalse((bool)result[1]);
            }
        }
Ejemplo n.º 2
0
        public void TestUnsubscribeDurableSubWhileActiveThenInactive()
        {
            using (var testListener = new TestListener(IPEndPoint))
            {
                testListener.Open();
                List result = null;
                testListener.RegisterTarget(TestPoint.Detach, (stream, channel, fields) =>
                {
                    TestListener.FRM(stream, 0x16UL, 0, channel, fields[0], false);
                    result = fields;
                    return(TestOutcome.Stop);
                });

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

                ITopic dest             = session.GetTopic("myTopic");
                String subscriptionName = "mySubscription";

                IMessageConsumer consumer = session.CreateDurableConsumer(dest, subscriptionName, null, false);
                Assert.NotNull(consumer);

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

                consumer.Close();

                // Try to unsubscribe again, should work now
                session.DeleteDurableConsumer(subscriptionName);

                session.Close();
                connection.Close();

                // Assert that closed field is set to true
                Assert.IsTrue((bool)result[1]);
            }
        }