public void TestCreateDurableConsumer() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); TestLinkProcessor testLinkProcessor = new TestLinkProcessor(); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); NmsConnection connection = (NmsConnection)EstablishConnection(); connection.Start(); 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); Assert.NotNull(durableConsumer); // Expect That Durable Subscriber Attach Assert.That(() => testLinkProcessor.Consumer, Is.Not.Null.After(200)); Assert.AreEqual(subscriptionName, testLinkProcessor.Consumer.Link.Name);; Source source = (Source)testLinkProcessor.Consumer.Attach.Source; Assert.AreEqual((uint)TerminusDurability.UNSETTLED_STATE, source.Durable); Assert.AreEqual(new Symbol("never"), source.ExpiryPolicy); Assert.AreEqual(topicName, source.Address); Assert.IsFalse(source.Dynamic); connection.Close(); } }
public void TestSendTimesOutWhenNoDispositionArrives() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); testAmqpPeer.RegisterLinkProcessor(new MockLinkProcessor(context => { context.Complete(new MockLinkEndpoint(onDispositionHandler: dispositionContext => { dispositionContext.Complete(); }, onMessageHandler: messageContext => { // do nothing }), 1); })); IConnection connection = EstablishConnection("nms.sendTimeout=500"); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); string text = "myMessage"; ITextMessage message = session.CreateTextMessage(text); Assert.Catch <Exception>(() => producer.Send(message)); producer.Close(); session.Close(); connection.Close(); } }
public void TestSentTextMessageCanBeModified() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); TestLinkProcessor testLinkProcessor = new TestLinkProcessor(); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); IConnection connection = EstablishConnection(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); string text = "myMessage"; ITextMessage textMessage = session.CreateTextMessage(text); producer.Send(textMessage); Assert.AreEqual(text, textMessage.Text); textMessage.Text = text + text; Assert.AreEqual(text + text, textMessage.Text); producer.Close(); session.Close(); connection.Close(); } }
public void TestSendingMessageSetsNMSExpirationRelatedAbsoluteExpiryAndTtlFields() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); List <Amqp.Message> receivedMessages = new List <Amqp.Message>(); TestLinkProcessor testLinkProcessor = new TestLinkProcessor(receivedMessages); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); IConnection connection = EstablishConnection(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); TimeSpan ttl = TimeSpan.FromMilliseconds(100_000); DateTime expiration = DateTime.UtcNow + ttl; string text = "myMessage"; ITextMessage message = session.CreateTextMessage(text); producer.Send(message, NMSConstants.defaultDeliveryMode, NMSConstants.defaultPriority, ttl); Assert.IsTrue(receivedMessages.Any()); Assert.That(receivedMessages.First().Properties.AbsoluteExpiryTime, Is.EqualTo(expiration).Within(TimeSpan.FromMilliseconds(100))); producer.Close(); session.Close(); connection.Close(); } }
public void TestRemotelyCloseProducer() { ManualResetEvent producentClosed = new ManualResetEvent(false); Mock <INmsConnectionListener> mockConnectionListener = new Mock <INmsConnectionListener>(); mockConnectionListener .Setup(listener => listener.OnProducerClosed(It.IsAny <NmsMessageProducer>(), It.IsAny <Exception>())) .Callback(() => { producentClosed.Set(); }); using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); TestLinkProcessor testLinkProcessor = new TestLinkProcessor(); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); NmsConnection connection = (NmsConnection)EstablishConnection(); connection.AddConnectionListener(mockConnectionListener.Object); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); testLinkProcessor.Producer.Link.Close(); Assert.True(producentClosed.WaitOne(TimeSpan.FromMilliseconds(1000))); Assert.That(() => producer.DisableMessageID, Throws.Exception.InstanceOf <IllegalStateException>()); producer.Close(); session.Close(); connection.Close(); } }
public void TestSyncReceiveFailsWhenListenerSet() { using (TestAmqpPeer testPeer = new TestAmqpPeer()) { IConnection connection = EstablishConnection(testPeer); testPeer.ExpectBegin(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); testPeer.ExpectReceiverAttach(); testPeer.ExpectLinkFlow(); IMessageConsumer consumer = session.CreateConsumer(destination); consumer.Listener += message => { }; Assert.Catch <NMSException>(() => consumer.Receive(), "Should have thrown an exception."); Assert.Catch <NMSException>(() => consumer.Receive(TimeSpan.FromMilliseconds(1000)), "Should have thrown an exception."); Assert.Catch <NMSException>(() => consumer.ReceiveNoWait(), "Should have thrown an exception."); testPeer.ExpectClose(); connection.Close(); testPeer.WaitForAllMatchersToComplete(2000); } }
public void TestSendingMessageSetsNMSDestination() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); List <Amqp.Message> receivedMessages = new List <Amqp.Message>(); TestLinkProcessor testLinkProcessor = new TestLinkProcessor(receivedMessages); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); IConnection connection = EstablishConnection(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); string text = "myMessage"; ITextMessage message = session.CreateTextMessage(text); Assert.IsNull(message.NMSDestination); producer.Send(message); Assert.AreEqual(destination, message.NMSDestination); Assert.IsTrue(receivedMessages.Any()); Assert.That(receivedMessages.First().Properties.To, Is.EqualTo(destination.QueueName)); producer.Close(); session.Close(); connection.Close(); } }
public void TestRemotelyCloseConsumer() { Mock <INmsConnectionListener> mockConnectionListener = new Mock <INmsConnectionListener>(); bool exceptionFired = false; using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { TestLinkProcessor testLinkProcessor = new TestLinkProcessor(); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); testAmqpPeer.Open(); NmsConnection connection = (NmsConnection)EstablishConnection(); connection.Start(); connection.AddConnectionListener(mockConnectionListener.Object); connection.ExceptionListener += exception => { exceptionFired = true; }; ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue queue = session.GetQueue("myQueue"); // Create a consumer, then remotely end it afterwards. IMessageConsumer consumer = session.CreateConsumer(queue); testLinkProcessor.CloseConsumer(); Assert.That(() => exceptionFired, Is.False.After(200), "Exception listener shouldn't fire with no MessageListener"); // Verify the consumer gets marked closed mockConnectionListener.Verify(listener => listener.OnConsumerClosed(It.Is <IMessageConsumer>(x => x == consumer), It.IsAny <Exception>()), Times.Once, "consumer never closed."); session.Close(); connection.Close(); } }
public void TestRecoveredMessageShouldNotBeMutated() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { string originalPayload = "testMessage"; testAmqpPeer.Open(); testAmqpPeer.RegisterLinkProcessor(new TestLinkProcessor()); testAmqpPeer.SendMessage("myQueue", originalPayload); NmsConnection connection = (NmsConnection)EstablishConnection(); connection.Start(); ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageConsumer consumer = session.CreateConsumer(destination); NmsTextMessage message = consumer.Receive() as NmsTextMessage; Assert.NotNull(message); message.IsReadOnlyBody = false; message.Text = message.Text + "Received"; session.Recover(); ITextMessage recoveredMessage = consumer.Receive() as ITextMessage; Assert.IsNotNull(recoveredMessage); Assert.AreNotEqual(message.Text, recoveredMessage.Text); Assert.AreEqual(originalPayload, recoveredMessage.Text); Assert.AreNotSame(message, recoveredMessage); consumer.Close(); session.Close(); connection.Close(); } }
public void TestCreateProducerInOnMessage() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.RegisterLinkProcessor(new TestLinkProcessor()); testAmqpPeer.Open(); NmsConnection connection = (NmsConnection)EstablishConnection(); connection.Start(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IQueue outbound = session.GetQueue("ForwardDest"); IMessageConsumer consumer = session.CreateConsumer(destination); consumer.Listener += message => { IMessageProducer producer = session.CreateProducer(outbound); producer.Send(message); producer.Close(); }; consumer.Close(); session.Close(); connection.Close(); } }
public void TestMessageListenerCallsSessionCloseThrowsIllegalStateException() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); testAmqpPeer.SendMessage("myQueue", "test"); NmsConnection connection = (NmsConnection)EstablishConnection(); connection.Start(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageConsumer consumer = session.CreateConsumer(destination); Exception exception = null; consumer.Listener += message => { try { session.Close(); } catch (Exception e) { exception = e; } }; Assert.That(() => exception, Is.Not.Null.After(5000, 100)); consumer.Close(); session.Close(); connection.Close(); } }
public void TestSetMessageListenerAfterStartAndSend() { int messageCount = 4; using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); for (int i = 0; i < messageCount; i++) { testAmqpPeer.SendMessage("myQueue", "test" + i); } NmsConnection connection = (NmsConnection)EstablishConnection(); connection.Start(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue queue = session.GetQueue("myQueue"); IMessageConsumer consumer = session.CreateConsumer(queue); consumer.Listener += message => { }; Assert.That(() => testAmqpPeer.AcceptedMessages.Count(), Is.EqualTo(messageCount).After(2000, 100)); consumer.Close(); session.Close(); connection.Close(); } }
public async Task TestSentAsync() { using (TestAmqpPeer testPeer = new TestAmqpPeer()) { IConnection connection = await base.EstablishConnectionAsync(testPeer); testPeer.ExpectBegin(); testPeer.ExpectSenderAttach(); ISession session = await connection.CreateSessionAsync(AcknowledgementMode.AutoAcknowledge); IQueue queue = await session.GetQueueAsync("myQueue"); IMessageProducer producer = await session.CreateProducerAsync(queue); // Create and transfer a new message String text = "myMessage"; testPeer.ExpectTransfer(messageMatcher: m => Assert.AreEqual(text, (m.BodySection as AmqpValue).Value), settled: false, sendResponseDisposition: true, responseState: new Accepted(), responseSettled: true, stateMatcher: Assert.IsNull, dispositionDelay: 10); // 10ms should be enough testPeer.ExpectClose(); ITextMessage message = await session.CreateTextMessageAsync(text); await producer.SendAsync(message); await connection.CloseAsync(); testPeer.WaitForAllMatchersToComplete(1000); } }
public async Task TestProducerWorkWithAsyncAwait() { using (TestAmqpPeer testPeer = new TestAmqpPeer()) { IConnection connection = await base.EstablishConnectionAsync(testPeer); testPeer.ExpectBegin(); testPeer.ExpectSenderAttach(); ISession session = await connection.CreateSessionAsync(AcknowledgementMode.AutoAcknowledge); IQueue queue = await session.GetQueueAsync("myQueue"); IMessageProducer producer = await session.CreateProducerAsync(queue); // Create and transfer a new message, explicitly setting the deliveryMode on the // message (which applications shouldn't) to NON_PERSISTENT and sending it to check // that the producer ignores this value and sends the message as PERSISTENT(/durable) testPeer.ExpectTransfer(message => Assert.IsTrue(message.Header.Durable)); testPeer.ExpectClose(); ITextMessage textMessage = await session.CreateTextMessageAsync(); textMessage.NMSDeliveryMode = MsgDeliveryMode.NonPersistent; Assert.AreEqual(MsgDeliveryMode.NonPersistent, textMessage.NMSDeliveryMode); await producer.SendAsync(textMessage); Assert.AreEqual(MsgDeliveryMode.Persistent, textMessage.NMSDeliveryMode); await connection.CloseAsync(); testPeer.WaitForAllMatchersToComplete(1000); } }
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); } }
public async Task TestCreateSharedDurableConsumer() { 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.ExpectSharedDurableSubscriberAttach(topicName, subscriptionName); testPeer.ExpectLinkFlow(); IMessageConsumer durableConsumer = await session.CreateSharedDurableConsumerAsync(topic, subscriptionName, null); //, false); Assert.NotNull(durableConsumer, "MessageConsumer object was null"); testPeer.ExpectClose(); await connection.CloseAsync(); testPeer.WaitForAllMatchersToComplete(1000); } }
public void TestNoReceivedNoWaitMessagesWhenConnectionNotStarted() { using (TestAmqpPeer testPeer = new TestAmqpPeer()) { IConnection connection = EstablishConnection(testPeer); testPeer.ExpectBegin(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); testPeer.ExpectReceiverAttach(); testPeer.ExpectLinkFlowRespondWithTransfer(message: CreateMessageWithContent(), count: 3); IMessageConsumer consumer = session.CreateConsumer(destination); // Wait for a message to arrive then try and receive it, which should not happen // since the connection is not started. Assert.Null(consumer.ReceiveNoWait()); testPeer.ExpectClose(); connection.Close(); testPeer.WaitForAllMatchersToComplete(2000); } }
public async Task TestCreateConsumer() { using (TestAmqpPeer testPeer = new TestAmqpPeer()) { IConnection connection = await EstablishConnectionAsync(testPeer); await connection.StartAsync(); testPeer.ExpectBegin(); ISession session = await connection.CreateSessionAsync(AcknowledgementMode.AutoAcknowledge); testPeer.ExpectReceiverAttach(); testPeer.ExpectLinkFlow(); testPeer.ExpectClose(); IQueue queue = await session.GetQueueAsync("myQueue"); await session.CreateConsumerAsync(queue); await connection.CloseAsync(); testPeer.WaitForAllMatchersToComplete(1000); } }
public void TestProducerOverridesMessageDeliveryMode() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); TestLinkProcessor testLinkProcessor = new TestLinkProcessor(); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); IConnection connection = EstablishConnection(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); string text = "myMessage"; ITextMessage textMessage = session.CreateTextMessage(text); textMessage.NMSDeliveryMode = MsgDeliveryMode.NonPersistent; producer.Send(textMessage); Assert.AreEqual(MsgDeliveryMode.Persistent, textMessage.NMSDeliveryMode); producer.Close(); session.Close(); connection.Close(); } }
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 TestSendingMessageSetsNMSTimestamp() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); List <Amqp.Message> receivedMessages = new List <Amqp.Message>(); TestLinkProcessor testLinkProcessor = new TestLinkProcessor(receivedMessages); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); IConnection connection = EstablishConnection(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); DateTime timeStamp = DateTime.UtcNow; string text = "myMessage"; ITextMessage message = session.CreateTextMessage(text); producer.Send(message); Assert.IsTrue(receivedMessages.Any()); Assert.That(receivedMessages.First().Properties.CreationTime, Is.EqualTo(timeStamp).Within(TimeSpan.FromMilliseconds(100))); producer.Close(); session.Close(); connection.Close(); } }
public void TestFailoverInitialReconnectDelayDoesNotApplyToInitialConnect() { using (TestAmqpPeer originalPeer = new TestAmqpPeer()) { // Connect to the first peer originalPeer.ExpectSaslAnonymous(); originalPeer.ExpectOpen(); originalPeer.ExpectBegin(); int delay = 20000; Stopwatch watch = new Stopwatch(); watch.Start(); NmsConnection connection = EstablishAnonymousConnection("failover.initialReconnectDelay=" + delay + "&failover.maxReconnectAttempts=1", originalPeer); connection.Start(); watch.Stop(); Assert.True(watch.ElapsedMilliseconds < delay, "Initial connect should not have delayed for the specified initialReconnectDelay." + "Elapsed=" + watch.ElapsedMilliseconds + ", delay=" + delay); Assert.True(watch.ElapsedMilliseconds < 5000, $"Connection took longer than reasonable: {watch.ElapsedMilliseconds}"); // Shut it down originalPeer.ExpectClose(); connection.Close(); originalPeer.WaitForAllMatchersToComplete(2000); } }
public void TestNonDefaultPriorityProducesMessagesWithPriorityFieldAndSetsNMSPriority() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); List <Amqp.Message> receivedMessages = new List <Amqp.Message>(); TestLinkProcessor testLinkProcessor = new TestLinkProcessor(receivedMessages); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); IConnection connection = EstablishConnection(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); string text = "myMessage"; ITextMessage message = session.CreateTextMessage(text); Assert.AreEqual(MsgPriority.BelowNormal, message.NMSPriority); producer.Send(message, MsgDeliveryMode.Persistent, MsgPriority.Highest, NMSConstants.defaultTimeToLive); Assert.AreEqual(MsgPriority.Highest, message.NMSPriority); Assert.IsTrue(receivedMessages.Any()); Assert.AreEqual(9, receivedMessages.First().Header.Priority); producer.Close(); session.Close(); connection.Close(); } }
public void TestFailoverHandlesDropAfterSessionCloseRequested() { using (TestAmqpPeer originalPeer = new TestAmqpPeer()) { ManualResetEvent originalConnected = new ManualResetEvent(false); // Create a peer to connect to var originalUri = CreatePeerUri(originalPeer); // Connect to the first peer originalPeer.ExpectSaslAnonymous(); originalPeer.ExpectOpen(); originalPeer.ExpectBegin(); Mock <INmsConnectionListener> connectionListener = new Mock <INmsConnectionListener>(); connectionListener .Setup(listener => listener.OnConnectionEstablished(It.Is <Uri>(uri => originalUri == uri.ToString()))) .Callback(() => { originalConnected.Set(); }); NmsConnection connection = EstablishAnonymousConnection(originalPeer); connection.AddConnectionListener(connectionListener.Object); connection.Start(); Assert.True(originalConnected.WaitOne(TimeSpan.FromSeconds(5)), "Should connect to peer"); originalPeer.ExpectBegin(); originalPeer.ExpectEnd(sendResponse: false); originalPeer.DropAfterLastMatcher(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); ManualResetEvent sessionCloseCompleted = new ManualResetEvent(false); Exception sessionClosedThrew = null; Task.Run(() => { try { session.Close(); } catch (Exception e) { sessionClosedThrew = e; } finally { sessionCloseCompleted.Set(); } }); originalPeer.WaitForAllMatchersToComplete(2000); Assert.IsTrue(sessionCloseCompleted.WaitOne(TimeSpan.FromSeconds(3)), "Session close should have completed by now"); Assert.IsNull(sessionClosedThrew, "Session close should have completed normally"); connection.Close(); } }
public void TestSendWhenLinkCreditIsZeroAndTimeout() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); testAmqpPeer.RegisterLinkProcessor(new MockLinkProcessor(context => { context.Complete(new TestLinkEndpoint(new List <Amqp.Message>()), 0); })); IConnection connection = EstablishConnection("nms.sendTimeout=500"); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); string text = "myMessage"; ITextMessage message = session.CreateTextMessage(text); Assert.Catch <Exception>(() => producer.Send(message)); producer.Close(); session.Close(); connection.Close(); } }
public void TestReceiveMessageWithReceiveZeroTimeout() { 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.ExpectDispositionThatIsAcceptedAndSettled(); IMessageConsumer consumer = session.CreateConsumer(queue); IMessage message = consumer.Receive(); Assert.NotNull(message, "A message should have been received"); testPeer.ExpectClose(); connection.Close(); testPeer.WaitForAllMatchersToComplete(10000); } }
public void TestSendWorksAfterConnectionStopped() { using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password)) { testAmqpPeer.Open(); List <Amqp.Message> receivedMessages = new List <Amqp.Message>(); TestLinkProcessor testLinkProcessor = new TestLinkProcessor(receivedMessages); testAmqpPeer.RegisterLinkProcessor(testLinkProcessor); IConnection connection = EstablishConnection(); connection.Start(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue destination = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(destination); string text = "myMessage"; ITextMessage message = session.CreateTextMessage(text); Assert.IsNull(message.NMSMessageId); connection.Stop(); producer.Send(message); Assert.IsTrue(receivedMessages.Any()); producer.Close(); session.Close(); connection.Close(); } }
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 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 async Task TestSendWorksAfterConnectionStopped() { using (TestAmqpPeer testPeer = new TestAmqpPeer()) { IConnection connection = await EstablishConnectionAsync(testPeer); await connection.StartAsync(); testPeer.ExpectBegin(); testPeer.ExpectSenderAttach(); ISession session = await connection.CreateSessionAsync(AcknowledgementMode.AutoAcknowledge); IQueue destination = await session.GetQueueAsync("myQueue"); IMessageProducer producer = await session.CreateProducerAsync(destination); testPeer.ExpectTransfer(Assert.IsNotNull); await connection.StopAsync(); await producer.SendAsync(await session.CreateMessageAsync()); testPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true); testPeer.ExpectClose(); await producer.CloseAsync(); await connection.CloseAsync(); testPeer.WaitForAllMatchersToComplete(1000); } }