Пример #1
0
        public async Task AddMessageAsync_Success(string messageText, string label)
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue");

            await client.DeleteIfExists();

            try
            {
                await client.CrateIfNotExists();

                MqCreateMessage sendMessage    = new MqCreateMessage(messageText, label);
                MqMessage       createdMessage = await client.AddMessage(sendMessage);

                Assert.IsNotNull(createdMessage);
                Assert.AreEqual(messageText, createdMessage.AsString);
                Assert.AreEqual(label, createdMessage.Label);

                Assert.AreNotEqual(Guid.Empty, createdMessage.Id);
                Assert.AreNotEqual(default(DateTime), createdMessage.InsertionTime);
            }
            finally
            {
                await client.DeleteIfExists();
            }
        }
Пример #2
0
        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();
            }
        }
Пример #3
0
        public async Task GetCountAsync_More()
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue");

            await client.DeleteIfExists();

            try
            {
                await client.CrateIfNotExists();

                await client.AddMessage(new MqCreateMessage("any message"));

                Assert.AreEqual(1, await client.GetCount());
                await client.AddMessage(new MqCreateMessage("any message"));

                Assert.AreEqual(2, await client.GetCount());
                await client.AddMessage(new MqCreateMessage("any message"));

                Assert.AreEqual(3, await client.GetCount());
            }
            finally
            {
                await client.DeleteIfExists();
            }
        }
Пример #4
0
        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();
            }
        }
Пример #5
0
        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();
            }
        }
Пример #6
0
        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();
            }
        }
Пример #7
0
        public async Task SetNotificationAdressAsync_Updated(string qeueuName, string naBase, string na1, string na2)
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient(qeueuName);

            try
            {
                await client.CrateIfNotExists(null, naBase);

                Queu info = await client.GetDefinition();

                Assert.AreEqual(naBase, info.NotificationAdress);

                await client.SetNotificationAdress(na1);

                Queu info1 = await client.GetDefinition();

                Assert.AreEqual(na1, info1.NotificationAdress);

                await client.SetNotificationAdress(na2);

                Queu info2 = await client.GetDefinition();

                Assert.AreEqual(na2, info2.NotificationAdress);
            }
            finally
            {
                await client.DeleteIfExists();
            }
        }
Пример #8
0
        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();
            }
        }
Пример #9
0
        public async Task DeleteIfExistsAsync_Multiple()
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue");

            await client.CrateIfNotExists();

            await client.DeleteIfExists();

            await client.DeleteIfExists();
        }
Пример #10
0
        public async Task CrateIfNotExistsAsync_Single()
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue");

            await client.DeleteIfExists();

            try
            {
                await client.CrateIfNotExists();
            }
            finally
            {
                await client.DeleteIfExists();
            }
        }
Пример #11
0
        public async Task PeekMessageAsync_Empty()
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue");

            await client.DeleteIfExists();

            try
            {
                await client.CrateIfNotExists();

                MqMessage nullMessage = await client.PeekMessage();

                Assert.IsNull(nullMessage);
            }
            finally
            {
                await client.DeleteIfExists();
            }
        }
Пример #12
0
        public async Task GetCountAsync_Zero()
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue");

            await client.DeleteIfExists();

            try
            {
                await client.CrateIfNotExists();

                int messagesCount = await client.GetCount();

                Assert.AreEqual(0, messagesCount);
            }
            finally
            {
                await client.DeleteIfExists();
            }
        }
Пример #13
0
        public async Task DeleteMessageAsync_FromCreated()
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue");
            await client.DeleteIfExists();

            try
            {
                await client.CrateIfNotExists();

                MqMessage message = await client.AddMessage(new MqCreateMessage("some messagefor MOM"));

                await client.DeleteMessage(message);

                MqMessage newMessage = await client.PeekMessage();

                Assert.IsNull(newMessage);
            }
            finally
            {
                await client.DeleteIfExists();
            }
        }
Пример #14
0
        public async Task GetDefinitionAsync_Get(string qeueuName, string topic, string notificationAdress)
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient(qeueuName);

            try
            {
                await client.CrateIfNotExists(topic, notificationAdress);

                Queu info = await client.GetDefinition();

                Assert.AreEqual(qeueuName, info.Name);
                Assert.AreEqual(topic, info.TopicPattern);
                Assert.AreEqual(notificationAdress, info.NotificationAdress);

                Assert.AreNotEqual(Guid.Empty, info.Id);
                Assert.AreNotEqual(default(DateTime), info.Created);
            }
            finally
            {
                await client.DeleteIfExists();
            }
        }
Пример #15
0
        public async Task ExistsQueueAsync_Get()
        {
            PassiveMqQueuClient client = this.Account.CreateQueueClient("myTestQueue");

            try
            {
                await client.CrateIfNotExists();

                bool exists1 = await client.ExistsQueue();

                Assert.IsTrue(exists1);
                await client.DeleteIfExists();

                bool exists2 = await client.ExistsQueue();

                Assert.IsFalse(exists2);
            }
            finally
            {
                await client.DeleteIfExists();
            }
        }