public async Task TestCantDeleteTemporaryQueueWithConsumers()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = await EstablishConnectionAsync(testPeer);

                await connection.StartAsync();

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

                string dynamicAddress = "myTempTopicAddress";
                testPeer.ExpectTempTopicCreationAttach(dynamicAddress);

                ITemporaryTopic topic = await session.CreateTemporaryTopicAsync();

                testPeer.ExpectReceiverAttach();
                testPeer.ExpectLinkFlow();
                IMessageConsumer consumer = await session.CreateConsumerAsync(topic);

                Assert.CatchAsync <IllegalStateException>(async() => await topic.DeleteAsync(), "should not be able to delete temporary topic with active consumers");

                testPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true);
                await consumer.CloseAsync();

                // Now it should be allowed
                testPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true);
                await topic.DeleteAsync();

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

                testPeer.WaitForAllMatchersToComplete(2000);
            }
        }
        public void TestCantDeleteTemporaryQueueWithConsumers()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.RegisterLinkProcessor(new TestLinkProcessor());

                testAmqpPeer.Open();
                IConnection connection = EstablishConnection();
                connection.Start();

                ISession        session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                ITemporaryTopic topic   = session.CreateTemporaryTopic();

                IMessageConsumer consumer = session.CreateConsumer(topic);

                Assert.Catch <IllegalStateException>(() => topic.Delete(), "should not be able to delete temporary queue with active consumers");

                consumer.Close();

                // Now it should be allowed
                topic.Delete();

                connection.Start();
                connection.Close();
            }
        }
示例#3
0
 public void TestCannotSendOnDeletedTemporaryTopic()
 {
     try
     {
         using (IConnection connection = GetConnection("c1"))
             using (IDestination destination = GetDestination("temp1"))
                 using (IMessageProducer producer = GetProducer("sender"))
                 {
                     ITemporaryTopic tempTopic = destination as ITemporaryTopic;
                     Assert.NotNull(tempTopic, "Failed to Create Temporary Topic.");
                     IMessage msg = producer.CreateMessage();
                     tempTopic.Delete();
                     try
                     {
                         producer.Send(msg);
                         Assert.Fail("Expected Exception for sending message on deleted temporary topic.");
                     }
                     catch (NMSException nex)
                     {
                         Assert.IsTrue(nex is InvalidDestinationException, "Received Unexpected exception {0}", nex);
                     }
                 }
     }
     catch (Exception ex)
     {
         this.PrintTestFailureAndAssert(GetTestMethodName(), "Unexpected exception.", ex);
     }
 }
示例#4
0
        public void TestAddRemoveAsnycMessageListener()
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
            {
                connection.Start();

                ISession         session  = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
                ITemporaryTopic  topic    = session.CreateTemporaryTopic();
                IMessageConsumer consumer = session.CreateConsumer(topic);

                consumer.Listener += OnMessage;
                consumer.Listener -= OnMessage;
                consumer.Listener += OnMessage;

                consumer.Close();
            }
        }
示例#5
0
        public void TestTempDestinationRecreatedAfterConnectionFailsOver()
        {
            using (TestAmqpPeer originalPeer = new TestAmqpPeer(Address1, User, Password))
                using (TestAmqpPeer finalPeer = new TestAmqpPeer(Address2, User, Password))
                {
                    originalPeer.RegisterLinkProcessor(new TestLinkProcessor());
                    finalPeer.RegisterLinkProcessor(new TestLinkProcessor());

                    ManualResetEvent originalConnected = new ManualResetEvent(false);
                    ManualResetEvent finalConnected    = new ManualResetEvent(false);

                    // Create a peer to connect to, then one to reconnect to
                    originalPeer.Open();
                    finalPeer.Open();

                    NmsConnection connection = EstablishConnection(originalPeer, finalPeer);

                    Mock <INmsConnectionListener> connectionListener = new Mock <INmsConnectionListener>();

                    connectionListener
                    .Setup(listener => listener.OnConnectionEstablished(It.Is <Uri>(uri => originalPeer.Address == uri)))
                    .Callback(() => { originalConnected.Set(); });

                    connectionListener
                    .Setup(listener => listener.OnConnectionRestored(It.Is <Uri>(uri => finalPeer.Address == uri)))
                    .Callback(() => { finalConnected.Set(); });

                    connection.AddConnectionListener(connectionListener.Object);

                    connection.Start();

                    Assert.True(originalConnected.WaitOne(TimeSpan.FromSeconds(5)), "Should connect to original peer");

                    ISession        session        = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                    ITemporaryTopic temporaryTopic = session.CreateTemporaryTopic();

                    originalPeer.Close();

                    Assert.True(finalConnected.WaitOne(TimeSpan.FromSeconds(5)), "Should connect to final peer");

                    temporaryTopic.Delete();

                    connection.Close();
                }
        }
        public void TestCreateTemporaryTopic()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.RegisterLinkProcessor(new TestLinkProcessor());

                testAmqpPeer.Open();
                IConnection connection = EstablishConnection();
                connection.Start();

                ISession        session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                ITemporaryTopic topic   = session.CreateTemporaryTopic();

                session.CreateConsumer(topic);

                connection.Close();
            }
        }
示例#7
0
        public void TestCantConsumeFromTemporaryTopicCreatedOnAnotherConnection()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = EstablishConnection(testPeer);

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

                string dynamicAddress = "myTempTopicAddress";
                testPeer.ExpectTempTopicCreationAttach(dynamicAddress);

                ITemporaryTopic topic = session.CreateTemporaryTopic();

                IConnection connection2 = EstablishConnection(testPeer);
                testPeer.ExpectBegin();

                ISession session2 = connection2.CreateSession(AcknowledgementMode.AutoAcknowledge);

                Assert.Catch <InvalidDestinationException>(() => session2.CreateConsumer(topic), "Should not be able to create consumer from temporary topic from another connection");
            }
        }
示例#8
0
        public void TestConnectionCanPurgeTempDestinations()
        {
            Connection       connection       = GetNewConnection();
            ISession         session          = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            IMessageConsumer advisoryConsumer = session.CreateConsumer(AdvisorySupport.TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC);

            advisoryConsumer.Listener += OnAdvisoryMessage;

            connection.Start();

            List <ITemporaryTopic> tempTopics = new List <ITemporaryTopic>();

            for (int i = 0; i < 10; ++i)
            {
                ITemporaryTopic tempTopic = session.CreateTemporaryTopic();
                tempTopics.Add(tempTopic);
                WaitForTempDestinationAdd(tempTopic);
                Tracer.Debug("Created TempDestination: " + tempTopic);
            }

            // Create one from an alternate connection, it shouldn't get purged
            // so we should have one less removed than added entries.
            Connection      connection2 = GetNewConnection();
            ISession        session2    = connection2.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ITemporaryTopic tempTopic2  = session2.CreateTemporaryTopic();

            WaitForTempDestinationAdd(tempTopic2);
            Assert.AreEqual(11, tempDestsAdded.Count);

            connection.PurgeTempDestinations();

            foreach (ITemporaryTopic tempTopic in tempTopics)
            {
                WaitForTempDestinationDelete(tempTopic);
            }

            Assert.AreEqual(10, tempDestsRemoved.Count);
        }
示例#9
0
        public void TestCreateTemporaryTopic()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = EstablishConnection(testPeer);

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

                string dynamicAddress = "myTempTopicAddress";
                testPeer.ExpectTempTopicCreationAttach(dynamicAddress);

                ITemporaryTopic temporaryTopic = session.CreateTemporaryTopic();
                Assert.NotNull(temporaryTopic, "TemporaryTopic object was null");
                Assert.NotNull(temporaryTopic.TopicName, "TemporaryTopic name was null");
                Assert.AreEqual(dynamicAddress, temporaryTopic.TopicName, "TemporaryTopic name not as expected");

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

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }
        public void TestCantConsumeFromTemporaryTopicCreatedOnAnotherConnection()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.RegisterLinkProcessor(new TestLinkProcessor());

                testAmqpPeer.Open();
                IConnection connection = EstablishConnection();
                connection.Start();

                ISession        session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                ITemporaryTopic topic   = session.CreateTemporaryTopic();

                IConnection connection2 = EstablishConnection();
                ISession    session2    = connection2.CreateSession(AcknowledgementMode.AutoAcknowledge);

                Assert.Catch <InvalidDestinationException>(() => session2.CreateConsumer(topic), "Should not be able to consumer from temporary topic from another connection");

                session.CreateConsumer(topic);

                connection.Close();
            }
        }
        public void TestCreateTemporaryTopic()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                var context = EstablishNMSContext(testPeer);

                testPeer.ExpectBegin();

                string dynamicAddress = "myTempTopicAddress";
                testPeer.ExpectTempTopicCreationAttach(dynamicAddress);

                ITemporaryTopic temporaryTopic = context.CreateTemporaryTopic();
                Assert.NotNull(temporaryTopic, "TemporaryTopic object was null");
                Assert.NotNull(temporaryTopic.TopicName, "TemporaryTopic name was null");
                Assert.AreEqual(dynamicAddress, temporaryTopic.TopicName, "TemporaryTopic name not as expected");

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

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }
示例#12
0
        public void TestTempDestinationRecreatedAfterConnectionFailsOver()
        {
            using (TestAmqpPeer originalPeer = new TestAmqpPeer())
                using (TestAmqpPeer finalPeer = new TestAmqpPeer())
                {
                    ManualResetEvent originalConnected = new ManualResetEvent(false);
                    ManualResetEvent finalConnected    = new ManualResetEvent(false);

                    // Create a peer to connect to, then one to reconnect to
                    var originalUri = CreatePeerUri(originalPeer);
                    var finalUri    = CreatePeerUri(finalPeer);

                    originalPeer.ExpectSaslAnonymous();
                    originalPeer.ExpectOpen();
                    originalPeer.ExpectBegin();
                    originalPeer.ExpectBegin();
                    string dynamicAddress1 = "myTempTopicAddress";
                    originalPeer.ExpectTempTopicCreationAttach(dynamicAddress1);
                    originalPeer.DropAfterLastMatcher();

                    NmsConnection connection = EstablishAnonymousConnection(originalPeer, finalPeer);

                    Mock <INmsConnectionListener> connectionListener = new Mock <INmsConnectionListener>();

                    connectionListener
                    .Setup(listener => listener.OnConnectionEstablished(It.Is <Uri>(uri => originalUri == uri.ToString())))
                    .Callback(() => { originalConnected.Set(); });

                    connectionListener
                    .Setup(listener => listener.OnConnectionRestored(It.Is <Uri>(uri => finalUri == uri.ToString())))
                    .Callback(() => { finalConnected.Set(); });

                    connection.AddConnectionListener(connectionListener.Object);

                    connection.Start();

                    Assert.True(originalConnected.WaitOne(TimeSpan.FromSeconds(5)), "Should connect to original peer");

                    // Post Failover Expectations of FinalPeer
                    finalPeer.ExpectSaslAnonymous();
                    finalPeer.ExpectOpen();
                    finalPeer.ExpectBegin();
                    String dynamicAddress2 = "myTempTopicAddress2";
                    finalPeer.ExpectTempTopicCreationAttach(dynamicAddress2);

                    // Session is recreated after previous temporary destinations are recreated on failover.
                    finalPeer.ExpectBegin();

                    ISession        session        = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                    ITemporaryTopic temporaryTopic = session.CreateTemporaryTopic();

                    Assert.True(finalConnected.WaitOne(TimeSpan.FromSeconds(5)), "Should connect to final peer");

                    // Delete the temporary Topic and close the session.
                    finalPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true);
                    finalPeer.ExpectEnd();

                    temporaryTopic.Delete();

                    session.Close();

                    // Shut it down
                    finalPeer.ExpectClose();
                    connection.Close();

                    originalPeer.WaitForAllMatchersToComplete(2000);
                    finalPeer.WaitForAllMatchersToComplete(1000);
                }
        }