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); ITemporaryQueue queue = session.CreateTemporaryQueue(); IMessageConsumer consumer = session.CreateConsumer(queue); Assert.Catch <IllegalStateException>(() => queue.Delete(), "should not be able to delete temporary queue with active consumers"); consumer.Close(); // Now it should be allowed queue.Delete(); connection.Start(); connection.Close(); } }
public void TestCantDeleteTemporaryQueueWithConsumers() { using (TestAmqpPeer testPeer = new TestAmqpPeer()) { IConnection connection = EstablishConnection(testPeer); connection.Start(); testPeer.ExpectBegin(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); string dynamicAddress = "myTempQueueAddress"; testPeer.ExpectTempQueueCreationAttach(dynamicAddress); ITemporaryQueue temporaryQueue = session.CreateTemporaryQueue(); testPeer.ExpectReceiverAttach(); testPeer.ExpectLinkFlow(); IMessageConsumer consumer = session.CreateConsumer(temporaryQueue); Assert.Catch <IllegalStateException>(() => temporaryQueue.Delete(), "should not be able to delete temporary queue with active consumers"); testPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true); consumer.Close(); // Now it should be allowed testPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true); temporaryQueue.Delete(); testPeer.ExpectClose(); connection.Close(); testPeer.WaitForAllMatchersToComplete(2000); } }
public void TestDeleteDestinationWithSubscribersFails() { Connection connection = GetNewConnection(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); ITemporaryQueue queue = session.CreateTemporaryQueue(); connection.Start(); session.CreateConsumer(queue); try { queue.Delete(); Assert.Fail("Should fail as Subscribers are active"); } catch (NMSException) { } }
public void TestPublishFailsForDestoryedTempDestination() { Connection tempConnection = CreateConnection() as Connection; connections.Add(tempConnection); ISession tempSession = tempConnection.CreateSession(AcknowledgementMode.AutoAcknowledge); ITemporaryQueue queue = tempSession.CreateTemporaryQueue(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); connection.Start(); // This message delivery should work since the temp connection is still // open. IMessageProducer producer = session.CreateProducer(queue); producer.DeliveryMode = MsgDeliveryMode.NonPersistent; ITextMessage message = session.CreateTextMessage("First"); producer.Send(message); Thread.Sleep(1000); // deleting the Queue will cause sends to fail queue.Delete(); Thread.Sleep(5000); // Wait a little bit to let the delete take effect. // This message delivery NOT should work since the temp connection is // now closed. try { message = session.CreateTextMessage("Hello"); producer.Send(message); Assert.Fail("Send should fail since temp destination should not exist anymore."); } catch (NMSException e) { Tracer.Debug("Test threw expected exception: " + e.Message); Assert.IsTrue(true, "failed to throw an exception"); } }
public void TestPublishFailsForDestroyedTempDestination() { Connection connection = GetNewConnection(); Connection tempConnection = GetNewConnection(); ISession tempSession = tempConnection.CreateSession(AcknowledgementMode.AutoAcknowledge); ITemporaryQueue queue = tempSession.CreateTemporaryQueue(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); connection.Start(); IMessageConsumer advisoryConsumer = session.CreateConsumer(AdvisorySupport.TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC); advisoryConsumer.Listener += OnAdvisoryMessage; // This message delivery should work since the temp connection is still open. IMessageProducer producer = session.CreateProducer(queue); producer.DeliveryMode = MsgDeliveryMode.NonPersistent; ITextMessage message = session.CreateTextMessage("First"); producer.Send(message); Thread.Sleep(1000); // deleting the Queue will cause sends to fail queue.Delete(); WaitForTempDestinationDelete(queue); // This message delivery should NOT work since the temp connection is now closed. try { message = session.CreateTextMessage("Hello"); producer.Send(message); Assert.Fail("Send should fail since temp destination should not exist anymore."); } catch (NMSException e) { Tracer.Debug("Test threw expected exception: " + e.Message); } }
public void TestDeleteDestinationWithSubscribersFails() { Connection connection = CreateConnection() as Connection; connections.Add(connection); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); ITemporaryQueue queue = session.CreateTemporaryQueue(); connection.Start(); session.CreateConsumer(queue); try { queue.Delete(); Assert.Fail("Should fail as Subscribers are active"); } catch (NMSException) { Assert.IsTrue(true, "failed to throw an exception"); } }