|
6 | 6 | using System.Diagnostics; |
7 | 7 | using System.Linq; |
8 | 8 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 9 | + using net.openstack.Core.Collections; |
9 | 10 | using net.openstack.Core.Domain; |
10 | 11 | using net.openstack.Core.Domain.Queues; |
11 | 12 | using net.openstack.Core.Providers; |
@@ -234,7 +235,7 @@ public void SynchronousTestQueueStatistics() |
234 | 235 | [TestMethod] |
235 | 236 | [TestCategory(TestCategories.User)] |
236 | 237 | [TestCategory(TestCategories.QueuesSynchronous)] |
237 | | - public void SynchronousTestListAllQueueMessages() |
| 238 | + public void SynchronousTestListAllQueueMessagesWithUpdates() |
238 | 239 | { |
239 | 240 | IQueueingService provider = CreateProvider(); |
240 | 241 | QueueName queueName = CreateRandomQueueName(); |
@@ -280,6 +281,36 @@ public void SynchronousTestListAllQueueMessages() |
280 | 281 | provider.DeleteQueue(queueName); |
281 | 282 | } |
282 | 283 |
|
| 284 | + [TestMethod] |
| 285 | + [TestCategory(TestCategories.User)] |
| 286 | + [TestCategory(TestCategories.QueuesSynchronous)] |
| 287 | + public void SynchronousTestListAllQueueMessages() |
| 288 | + { |
| 289 | + IQueueingService provider = CreateProvider(); |
| 290 | + QueueName queueName = CreateRandomQueueName(); |
| 291 | + |
| 292 | + provider.CreateQueue(queueName); |
| 293 | + |
| 294 | + for (int i = 0; i < 28; i++) |
| 295 | + { |
| 296 | + provider.PostMessages(queueName, new Message<SampleMetadata>(TimeSpan.FromSeconds(120), new SampleMetadata(i, "Some Message " + i))); |
| 297 | + } |
| 298 | + |
| 299 | + HashSet<int> locatedMessages = new HashSet<int>(); |
| 300 | + |
| 301 | + ReadOnlyCollection<QueuedMessage> messages = ListAllMessages(provider, queueName, null, true, false); |
| 302 | + foreach (QueuedMessage message in messages) |
| 303 | + Assert.IsTrue(locatedMessages.Add(message.Body.ToObject<SampleMetadata>().ValueA), "Received the same message more than once."); |
| 304 | + |
| 305 | + Assert.AreEqual(28, locatedMessages.Count); |
| 306 | + for (int i = 0; i < 28; i++) |
| 307 | + { |
| 308 | + Assert.IsTrue(locatedMessages.Contains(i), "The message listing did not include message '{0}', which was in the queue when the listing started and still in it afterwards.", i); |
| 309 | + } |
| 310 | + |
| 311 | + provider.DeleteQueue(queueName); |
| 312 | + } |
| 313 | + |
283 | 314 | /// <summary> |
284 | 315 | /// Tests the queueing service message functionality by creating two queues |
285 | 316 | /// and two sub-processes and using them for two-way communication. |
@@ -614,14 +645,49 @@ public void SynchronousTestQueueClaims() |
614 | 645 | /// <param name="limit">The maximum number of <see cref="CloudQueue"/> to return from a single call to <see cref="QueueingServiceExtensions.ListQueues"/>. If this value is <see langword="null"/>, a provider-specific default is used.</param> |
615 | 646 | /// <param name="detailed"><see langword="true"/> to return detailed information for each queue; otherwise, <see langword="false"/>.</param> |
616 | 647 | /// <returns>A collection of <see cref="CloudQueue"/> objects describing the available queues.</returns> |
| 648 | + /// <exception cref="ArgumentNullException">If <paramref name="provider"/> is <see langword="null"/>.</exception> |
| 649 | + /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception> |
| 650 | + /// <exception cref="WebException">If the REST request does not return successfully.</exception> |
617 | 651 | private static ReadOnlyCollection<CloudQueue> ListAllQueues(IQueueingService provider, int? limit, bool detailed) |
618 | 652 | { |
| 653 | + if (provider == null) |
| 654 | + throw new ArgumentNullException("provider"); |
619 | 655 | if (limit <= 0) |
620 | 656 | throw new ArgumentOutOfRangeException("limit"); |
621 | 657 |
|
622 | 658 | return provider.ListQueues(null, limit, detailed).GetAllPages(); |
623 | 659 | } |
624 | 660 |
|
| 661 | + /// <summary> |
| 662 | + /// Gets all existing messages in a queue through a series of synchronous operations, |
| 663 | + /// each of which requests a subset of the available messages. |
| 664 | + /// </summary> |
| 665 | + /// <param name="provider">The queueing service.</param> |
| 666 | + /// <param name="queueName">The queue name.</param> |
| 667 | + /// <param name="limit">The maximum number of <see cref="QueuedMessage"/> objects to return from a single task. If this value is <see langword="null"/>, a provider-specific default is used.</param> |
| 668 | + /// <param name="echo"><see langword="true"/> to include messages created by the current client; otherwise, <see langword="false"/>.</param> |
| 669 | + /// <param name="includeClaimed"><see langword="true"/> to include claimed messages; otherwise <see langword="false"/> to return only unclaimed messages.</param> |
| 670 | + /// <param name="progress">An optional callback object to receive progress notifications. If this is <see langword="null"/>, no progress notifications are sent.</param> |
| 671 | + /// <returns>A collection of <see cref="CloudQueue"/> objects describing the available queues.</returns> |
| 672 | + /// <exception cref="ArgumentNullException"> |
| 673 | + /// If <paramref name="provider"/> is <see langword="null"/>. |
| 674 | + /// <para>-or-</para> |
| 675 | + /// <para>If <paramref name="queueName"/> is <see langword="null"/>.</para> |
| 676 | + /// </exception> |
| 677 | + /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception> |
| 678 | + /// <exception cref="WebException">If the REST request does not return successfully.</exception> |
| 679 | + private static ReadOnlyCollection<QueuedMessage> ListAllMessages(IQueueingService provider, QueueName queueName, int? limit, bool echo, bool includeClaimed) |
| 680 | + { |
| 681 | + if (provider == null) |
| 682 | + throw new ArgumentNullException("provider"); |
| 683 | + if (queueName == null) |
| 684 | + throw new ArgumentNullException("queueName"); |
| 685 | + if (limit <= 0) |
| 686 | + throw new ArgumentOutOfRangeException("limit"); |
| 687 | + |
| 688 | + return provider.ListMessages(queueName, null, limit, echo, includeClaimed).GetAllPages(); |
| 689 | + } |
| 690 | + |
625 | 691 | /// <summary> |
626 | 692 | /// Creates a random queue name with the proper prefix for integration testing. |
627 | 693 | /// </summary> |
|
0 commit comments