public void CanReceiveFromQueue() { new Sender(ObjectMother.Logger()) { Destination = new Endpoint("localhost", 23456), Messages = new[] { new Message { Id = MessageId.GenerateRandom(), Queue = "h", Data = Encoding.Unicode.GetBytes("hello"), SentAt = DateTime.Now }, } }.Send().Wait(); using (var tx = new TransactionScope()) { var message = queueManager.Receive("h", null); "hello".ShouldEqual(Encoding.Unicode.GetString(message.Data)); tx.Complete(); } using (var tx = new TransactionScope()) { Assert.Throws <TimeoutException>(() => queueManager.Receive("h", null, TimeSpan.Zero)); tx.Complete(); } }
public void WhenSendingDuplicateMessageTwiceWillGetItOnlyOnce() { var msg = new Message { Id = MessageId.GenerateRandom(), Queue = "h", Data = Encoding.Unicode.GetBytes("hello"), SentAt = DateTime.Now }; for (int i = 0; i < 2; i++) { var sender = new Sender(ObjectMother.Logger()) { Destination = new Endpoint("localhost", 23456), Messages = new[] { msg, }, }; sender.Send().Wait(); } using (var tx = new TransactionScope()) { var message = queueManager.Receive("h", null); "hello".ShouldEqual(Encoding.Unicode.GetString(message.Data)); tx.Complete(); } using (var tx = new TransactionScope()) { Assert.Throws <TimeoutException>(() => queueManager.Receive("h", null, TimeSpan.Zero)); tx.Complete(); } }
public void CanPeekExistingMessages() { new Sender(ObjectMother.Logger()) { Destination = new Endpoint("localhost", 23456), Messages = new[] { new Message { Id = MessageId.GenerateRandom(), Queue = "h", Data = Encoding.Unicode.GetBytes("hello"), SentAt = DateTime.Now }, } }.Send().Wait(); using (new TransactionScope()) { // force a wait until we receive the message queueManager.Receive("h", null); } var messages = queueManager.GetAllMessages("h", null); 1.ShouldEqual(messages.Length); "hello".ShouldEqual(Encoding.Unicode.GetString(messages[0].Data)); }
public void CanLookupProcessedMessages() { new Sender(ObjectMother.Logger()) { Destination = new Endpoint("localhost", 23456), Messages = new[] { new Message { Id = MessageId.GenerateRandom(), Queue = "h", Data = Encoding.Unicode.GetBytes("hello"), SentAt = DateTime.Now }, } }.Send().Wait(); using (var tx = new TransactionScope()) { var message = queueManager.Receive("h", null); "hello".ShouldEqual(Encoding.Unicode.GetString(message.Data)); tx.Complete(); } var messages = queueManager.GetAllProcessedMessages("h"); 1.ShouldEqual(messages.Length); "hello".ShouldEqual(Encoding.Unicode.GetString(messages[0].Data)); }
public void WhenRevertingTransactionMessageGoesBackToQueue() { new Sender(ObjectMother.Logger()) { Destination = new Endpoint("localhost", 23456), Messages = new[] { new Message { Id = MessageId.GenerateRandom(), Queue = "h", Data = Encoding.Unicode.GetBytes("hello"), SentAt = DateTime.Now }, } }.Send().Wait(); using (new TransactionScope()) { var message = queueManager.Receive("h", null); "hello".ShouldEqual(Encoding.Unicode.GetString(message.Data)); } using (new TransactionScope()) { var message = queueManager.Receive("h", null); "hello".ShouldEqual(Encoding.Unicode.GetString(message.Data)); } }
public void MessageQueuedForReceive_EventNotRaised_IfReceiveAborts() { ManualResetEvent wait = new ManualResetEvent(false); var sender = new FakeSender(ObjectMother.Logger()) { Destination = new Endpoint("localhost", 23457), Messages = new[] { new Message { Id = new MessageId { MessageIdentifier = Guid.NewGuid(), SourceInstanceId = Guid.NewGuid() }, SentAt = DateTime.Now, Queue = "h", Data = new byte[] { 1, 2, 4, 5 } } } }; sender.SendCompleted += () => wait.Set(); var logger = new RecordingLogger(); sender.Send(); wait.WaitOne(TimeSpan.FromSeconds(1)); Wait.Until(() => logger.DebugMessages.OfType <MessageQueuedForReceive>().Any(), timeoutInMilliseconds: 1000) .ShouldBeFalse(); }
public void MessageSent_EventNotRaised_IfReceiverReverts() { using (var receiver = new RevertingQueueManager(new IPEndPoint(IPAddress.Loopback, 23457), TEST_QUEUE_2, new QueueManagerConfiguration(), ObjectMother.Logger())) { receiver.CreateQueues("h"); receiver.Start(); using (var tx = new TransactionScope()) { _sender.Send( new Uri("lq.tcp://localhost:23457/h"), new MessagePayload { Data = new byte[] { 1, 2, 4, 5 } }); tx.Complete(); } } var log = _logger.DebugMessages.OfType <MessagesSent>().FirstOrDefault(); log.ShouldBeNull(); }