public async Task GetMessageAsync_VisibilityTime() { PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue"); await client.DeleteIfExists(); try { await client.CrateIfNotExists(); await client.AddMessage(new MqCreateMessage("some messagefor MOM")); MqMessage realMessage = await client.GetMessage(TimeSpan.FromSeconds(5)); Assert.IsNotNull(realMessage); Assert.AreEqual(1, realMessage.RetryCount); MqMessage realNextMessage = await client.GetMessage(); Assert.IsNull(realNextMessage); await Task.Delay(10000); MqMessage realRentrantMessage = await client.GetMessage(); Assert.IsNotNull(realRentrantMessage); Assert.AreEqual(2, realRentrantMessage.RetryCount); } finally { await client.DeleteIfExists(); } }
public async Task GetMessageAsync_CheckValues(string message, string label) { PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue"); await client.DeleteIfExists(); try { await client.CrateIfNotExists(); await client.AddMessage(new MqCreateMessage(message, label)); MqMessage realMessage = await client.GetMessage(); Assert.AreEqual(message, realMessage.AsString); Assert.AreEqual(label, realMessage.Label); Assert.AreNotEqual(Guid.Empty, realMessage.Id); Assert.AreNotEqual(default(DateTime), realMessage.InsertionTime); Assert.AreNotEqual(null, realMessage.NextVisibleTime); } finally { await client.DeleteIfExists(); } }
public async Task Publisher_PublishAsync_CheckMatch(string topicClient, string publishTopic, bool match) { string message = "my test message"; string label = "myLabel"; PassiveMqQueuClient clientConsumer = this.Account.CreateQueueClient("myTestQueue"); PassiveMqPublishClient publisher = this.Account.CreatePublishClient(); try { await clientConsumer.DeleteIfExists(); await clientConsumer.CrateIfNotExists(topicClient); await publisher.Publish(publishTopic, new MqCreateMessage(message, label)); MqMessage resultMessage = await clientConsumer.GetMessage(); Assert.AreEqual(match, resultMessage != null, $"Inconsistent topic client '{topicClient}', topic publish '{publishTopic}', excepted match {match}."); if (match == true) { Assert.AreEqual(message, resultMessage.AsString); Assert.AreEqual(label, resultMessage.Label); } } finally { await clientConsumer.DeleteIfExists(); } }
public async Task GetMessageAsync_BatchWithDelete() { PassiveMqQueuClient client = this.Account.CreateQueueClient($"myTestQueue-{Guid.NewGuid()}"); await client.DeleteIfExists(); try { await client.CrateIfNotExists(); for (int i = 1; i < 10; i++) { await client.AddMessage(new MqCreateMessage(i.ToString())); } await Task.Delay(50); List <int> results = new List <int>(); for (int i = 1; i < 10; i++) { MqMessage message = await client.GetMessage(); results.Add(int.Parse(message.AsString)); await Task.Delay(3); await client.DeleteMessage(message.Id); } CollectionAssert.AllItemsAreUnique(results, "GetMessageAsync rerurns multiple same result."); } finally { await client.DeleteIfExists(); } }
public async Task GetMessageAsync_Batch() { string message = "my test message"; string label = "myLabel"; PassiveMqQueuClient clientConsumer1 = this.Account.CreateQueueClient("myTestQueue1"); PassiveMqQueuClient clientConsumer2 = this.Account.CreateQueueClient("myTestQueue2"); PassiveMqQueuClient clientConsumer3 = this.Account.CreateQueueClient("myTestQueue3"); PassiveMqQueuClient clientConsumer4 = this.Account.CreateQueueClient("myTestQueue4"); PassiveMqQueuClient clientConsumerNull = this.Account.CreateQueueClient("myTestQueueNull"); PassiveMqPublishClient publisher = this.Account.CreatePublishClient(); try { await clientConsumer1.DeleteIfExists(); await clientConsumer1.CrateIfNotExists("/myTestConsumer/aa"); await clientConsumer2.DeleteIfExists(); await clientConsumer2.CrateIfNotExists("/myTestConsumer/aa/bb"); await clientConsumer3.DeleteIfExists(); await clientConsumer3.CrateIfNotExists("/myTestConsumer/aa/bb/cc"); await clientConsumer4.DeleteIfExists(); await clientConsumer4.CrateIfNotExists("/myTestConsumer/bb/4"); await publisher.Publish("/myTestConsumer/aa/bb/cc/75", new MqCreateMessage(message, label)); MqMessage message1 = await clientConsumer1.GetMessage(); MqMessage message2 = await clientConsumer2.GetMessage(); MqMessage message3 = await clientConsumer3.GetMessage(); MqMessage message4 = await clientConsumer4.GetMessage(); Assert.IsNotNull(message1); Assert.IsNotNull(message2); Assert.IsNotNull(message3); Assert.IsNull(message4); } finally { await clientConsumer1.DeleteIfExists(); await clientConsumer2.DeleteIfExists(); await clientConsumer3.DeleteIfExists(); await clientConsumer4.DeleteIfExists(); } }
public async Task DeleteMessageAsync_FromGetMessage() { PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue"); await client.DeleteIfExists(); try { await client.CrateIfNotExists(); await client.AddMessage(new MqCreateMessage("some messagefor MOM")); MqMessage message = await client.GetMessage(); await client.DeleteMessage(message); MqMessage newMessage = await client.PeekMessage(); Assert.IsNull(newMessage); } finally { await client.DeleteIfExists(); } }