public void SynchronousTestCreateQueue() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); bool created = provider.CreateQueue(queueName); Assert.IsTrue(created); bool recreated = provider.CreateQueue(queueName); Assert.IsFalse(recreated); provider.DeleteQueue(queueName); }
public void SynchronousTestListAllQueueMessages() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); for (int i = 0; i < 28; i++) { provider.PostMessages(queueName, new Message <SampleMetadata>(TimeSpan.FromSeconds(120), new SampleMetadata(i, "Some Message " + i))); } HashSet <int> locatedMessages = new HashSet <int>(); ReadOnlyCollection <QueuedMessage> messages = ListAllMessages(provider, queueName, null, true, false); foreach (QueuedMessage message in messages) { Assert.IsTrue(locatedMessages.Add(message.Body.ToObject <SampleMetadata>().ValueA), "Received the same message more than once."); } Assert.AreEqual(28, locatedMessages.Count); for (int i = 0; i < 28; i++) { 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); } provider.DeleteQueue(queueName); }
public void SynchronousTestQueueExists() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); Assert.IsTrue(provider.QueueExists(queueName)); provider.DeleteQueue(queueName); Assert.IsFalse(provider.QueueExists(queueName)); }
public void SynchronousTestListQueues() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); foreach (CloudQueue queue in ListAllQueues(provider, null, true)) { Console.WriteLine("{0}: {1}", queue.Name, queue.Href); } provider.DeleteQueue(queueName); }
public void SynchronousTestListAllQueueMessagesWithUpdates() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); for (int i = 0; i < 28; i++) { provider.PostMessages(queueName, new Message <SampleMetadata>(TimeSpan.FromSeconds(120), new SampleMetadata(i, "Some Message " + i))); } HashSet <int> locatedMessages = new HashSet <int>(); QueuedMessageList messages = provider.ListMessages(queueName, null, null, true, false); foreach (QueuedMessage message in messages) { Assert.IsTrue(locatedMessages.Add(message.Body.ToObject <SampleMetadata>().ValueA), "Received the same message more than once."); } int deletedMessage = messages[0].Body.ToObject <SampleMetadata>().ValueA; provider.DeleteMessage(queueName, messages[0].Id, null); while (messages.Count > 0) { QueuedMessageList tempList = provider.ListMessages(queueName, messages.NextPageId, null, true, false); if (tempList.Count > 0) { Assert.IsTrue(locatedMessages.Add(tempList[0].Body.ToObject <SampleMetadata>().ValueA), "Received the same message more than once."); provider.DeleteMessage(queueName, tempList[0].Id, null); } messages = provider.ListMessages(queueName, messages.NextPageId, null, true, false); foreach (QueuedMessage message in messages) { Assert.IsTrue(locatedMessages.Add(message.Body.ToObject <SampleMetadata>().ValueA), "Received the same message more than once."); } } Assert.AreEqual(28, locatedMessages.Count); for (int i = 0; i < 28; i++) { 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); } provider.DeleteQueue(queueName); }
public void SynchronousTestPostQueueMessages_Typed_0() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); MessagesEnqueued enqueued; Message <SampleMetadata> typedMessage = new Message <SampleMetadata>(TimeSpan.FromMinutes(40), new SampleMetadata(1, "Stuff!")); // // Typed messages // enqueued = provider.PostMessages <SampleMetadata>(queueName); Assert.IsNotNull(enqueued); Assert.AreEqual(false, enqueued.Partial); Assert.IsNotNull(enqueued.Ids); Assert.IsFalse(enqueued.Ids.Contains(null)); Assert.AreEqual(0, enqueued.Ids.Count()); Assert.AreSame(MessagesEnqueued.Empty, enqueued); enqueued = provider.PostMessages <SampleMetadata>(queueName, Enumerable.Empty <Message <SampleMetadata> >()); Assert.IsNotNull(enqueued); Assert.AreEqual(false, enqueued.Partial); Assert.IsNotNull(enqueued.Ids); Assert.IsFalse(enqueued.Ids.Contains(null)); Assert.AreEqual(0, enqueued.Ids.Count()); Assert.AreSame(MessagesEnqueued.Empty, enqueued); // // Validation // ReadOnlyCollection <QueuedMessage> messages = ListAllMessages(provider, queueName, null, true, true); Assert.IsNotNull(messages); Assert.AreEqual(0, messages.Count); // // Cleanup // provider.DeleteQueue(queueName); }
public void SynchronousTestPostQueueMessages_Generic_2() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); MessagesEnqueued enqueued; Message genericMessage = new Message(TimeSpan.FromMinutes(50), new JObject(new JProperty("type", "generic"))); // // Generic messages // enqueued = provider.PostMessages(queueName, genericMessage, genericMessage); Assert.IsNotNull(enqueued); Assert.AreEqual(false, enqueued.Partial); Assert.IsNotNull(enqueued.Ids); Assert.IsFalse(enqueued.Ids.Contains(null)); Assert.AreEqual(2, enqueued.Ids.Count()); Assert.AreEqual(false, enqueued.Partial); enqueued = provider.PostMessages(queueName, new[] { genericMessage, genericMessage }); Assert.IsNotNull(enqueued); Assert.AreEqual(false, enqueued.Partial); Assert.IsNotNull(enqueued.Ids); Assert.IsFalse(enqueued.Ids.Contains(null)); Assert.AreEqual(2, enqueued.Ids.Count()); Assert.AreEqual(false, enqueued.Partial); // // Validation // ReadOnlyCollection <QueuedMessage> messages = ListAllMessages(provider, queueName, null, true, true); Assert.IsNotNull(messages); Assert.AreEqual(4, messages.Count); // // Cleanup // provider.DeleteQueue(queueName); }
public void SynchronousTestPostQueueMessages_Generic_0() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); MessagesEnqueued enqueued; // // Generic messages // enqueued = provider.PostMessages(queueName); Assert.IsNotNull(enqueued); Assert.AreEqual(false, enqueued.Partial); Assert.IsNotNull(enqueued.Ids); Assert.AreEqual(0, enqueued.Ids.Count()); Assert.IsFalse(enqueued.Ids.Contains(null)); Assert.AreSame(MessagesEnqueued.Empty, enqueued); enqueued = provider.PostMessages(queueName, Enumerable.Empty <Message>()); Assert.IsNotNull(enqueued); Assert.AreEqual(false, enqueued.Partial); Assert.IsNotNull(enqueued.Ids); Assert.IsFalse(enqueued.Ids.Contains(null)); Assert.AreEqual(0, enqueued.Ids.Count()); Assert.AreSame(MessagesEnqueued.Empty, enqueued); // // Validation // ReadOnlyCollection <QueuedMessage> messages = ListAllMessages(provider, queueName, null, true, true); Assert.IsNotNull(messages); Assert.AreEqual(0, messages.Count); // // Cleanup // provider.DeleteQueue(queueName); }
public void SynchronousTestQueueStatistics() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); QueueStatistics statistics = provider.GetQueueStatistics(queueName); Assert.IsNotNull(statistics); QueueMessagesStatistics messageStatistics = statistics.MessageStatistics; Assert.IsNotNull(messageStatistics); Assert.AreEqual(messageStatistics.Free, 0); Assert.AreEqual(messageStatistics.Claimed, 0); Assert.AreEqual(messageStatistics.Total, 0); Assert.IsNull(messageStatistics.Oldest); Assert.IsNull(messageStatistics.Newest); Console.WriteLine("Statistics:"); Console.WriteLine(); Console.WriteLine(JsonConvert.SerializeObject(statistics, Formatting.Indented)); provider.PostMessages(queueName, new Message <SampleMetadata>(TimeSpan.FromSeconds(120), new SampleMetadata(3, "yes"))); statistics = provider.GetQueueStatistics(queueName); Assert.IsNotNull(statistics); messageStatistics = statistics.MessageStatistics; Assert.IsNotNull(messageStatistics); Assert.AreEqual(messageStatistics.Free, 1); Assert.AreEqual(messageStatistics.Claimed, 0); Assert.AreEqual(messageStatistics.Total, 1); Assert.IsNotNull(messageStatistics.Oldest); Assert.IsNotNull(messageStatistics.Newest); Console.WriteLine("Statistics:"); Console.WriteLine(); Console.WriteLine(JsonConvert.SerializeObject(statistics, Formatting.Indented)); provider.DeleteQueue(queueName); }
public void SynchronousTestQueueMetadataDynamic() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); JObject metadata = new JObject( new JProperty("valueA", 3), new JProperty("valueB", "yes")); provider.SetQueueMetadata(queueName, metadata); JObject result = provider.GetQueueMetadata(queueName); Assert.AreEqual(3, result["valueA"]); Assert.AreEqual("yes", result["valueB"]); provider.DeleteQueue(queueName); }
public void SynchronousTestQueueMetadataStatic() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); SampleMetadata metadata = new SampleMetadata(3, "yes"); Assert.AreEqual(3, metadata.ValueA); Assert.AreEqual("yes", metadata.ValueB); provider.SetQueueMetadata(queueName, metadata); SampleMetadata result = provider.GetQueueMetadata <SampleMetadata>(queueName); Assert.AreEqual(metadata.ValueA, result.ValueA); Assert.AreEqual(metadata.ValueB, result.ValueB); provider.DeleteQueue(queueName); }
public void SynchronousTestQueueClaims() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); provider.PostMessages(queueName, new Message <SampleMetadata>(TimeSpan.FromSeconds(120), new SampleMetadata(3, "yes"))); QueueStatistics statistics; using (Claim claim = provider.ClaimMessage(queueName, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(1))) { Assert.AreEqual(TimeSpan.FromMinutes(5), claim.TimeToLive); Assert.IsNotNull(claim.Messages); Assert.AreEqual(1, claim.Messages.Count); statistics = provider.GetQueueStatistics(queueName); Assert.AreEqual(1, statistics.MessageStatistics.Claimed); QueuedMessage message = provider.GetMessage(queueName, claim.Messages[0].Id); Assert.IsNotNull(message); TimeSpan age = claim.Age; Thread.Sleep(TimeSpan.FromSeconds(2)); claim.Refresh(); Assert.IsTrue(claim.Age >= age + TimeSpan.FromSeconds(2)); claim.Renew(TimeSpan.FromMinutes(10)); Assert.AreEqual(TimeSpan.FromMinutes(10), claim.TimeToLive); } statistics = provider.GetQueueStatistics(queueName); Assert.AreEqual(0, statistics.MessageStatistics.Claimed); provider.DeleteQueue(queueName); }
public void SynchronousTestQueueMessages() { int clientCount = 3; int serverCount = 2; QueueName requestQueueName = CreateRandomQueueName(); QueueName[] responseQueueNames = Enumerable.Range(0, clientCount).Select(i => CreateRandomQueueName()).ToArray(); IQueueingService provider = CreateProvider(); Stopwatch initializationTimer = Stopwatch.StartNew(); Console.WriteLine("Creating request queue..."); provider.CreateQueue(requestQueueName); Console.WriteLine("Creating {0} response queues...", responseQueueNames.Length); foreach (QueueName queueName in responseQueueNames) { provider.CreateQueue(queueName); } TimeSpan initializationTime = initializationTimer.Elapsed; Console.WriteLine("Initialization time: {0} sec", initializationTime.TotalSeconds); TimeSpan testDuration = TimeSpan.FromSeconds(10); int[] clientResults = new int[clientCount]; int[] serverResults = new int[serverCount]; using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(testDuration)) { Stopwatch processingTimer = Stopwatch.StartNew(); List <Exception> errors = new List <Exception>(); List <Thread> clientThreads = new List <Thread>(); for (int i = 0; i < clientCount; i++) { int clientIndex = i; Thread client = new Thread( () => { try { PublishMessages(requestQueueName, responseQueueNames[clientIndex], ref clientResults[clientIndex], cancellationTokenSource.Token); } catch (Exception ex) { errors.Add(ex); } }); client.Start(); client.Name = "Client " + i; clientThreads.Add(client); } List <Thread> serverThreads = new List <Thread>(); for (int i = 0; i < serverCount; i++) { int serverIndex = i; Thread server = new Thread( () => { try { SubscribeMessages(requestQueueName, ref serverResults[serverIndex], cancellationTokenSource.Token); } catch (Exception ex) { errors.Add(ex); } }); server.Start(); server.Name = "Server " + i; serverThreads.Add(server); } // wait for all client and server threads to finish processing foreach (Thread thread in clientThreads.Concat(serverThreads)) { thread.Join(); } if (errors.Count > 0) { throw new AggregateException(errors); } } int clientTotal = 0; int serverTotal = 0; for (int i = 0; i < clientResults.Length; i++) { Console.WriteLine("Client {0}: {1} messages", i, clientResults[i]); clientTotal += clientResults[i]; } for (int i = 0; i < serverResults.Length; i++) { Console.WriteLine("Server {0}: {1} messages", i, serverResults[i]); serverTotal += serverResults[i]; } double clientRate = clientTotal / testDuration.TotalSeconds; double serverRate = serverTotal / testDuration.TotalSeconds; Console.WriteLine("Total client messages: {0} ({1} messages/sec, {2} messages/sec/client)", clientTotal, clientRate, clientRate / clientCount); Console.WriteLine("Total server messages: {0} ({1} messages/sec, {2} messages/sec/server)", serverTotal, serverRate, serverRate / serverCount); Console.WriteLine("Deleting request queue..."); provider.DeleteQueue(requestQueueName); Console.WriteLine("Deleting {0} response queues...", responseQueueNames.Length); foreach (QueueName queueName in responseQueueNames) { provider.DeleteQueue(queueName); } if (clientTotal == 0) { Assert.Inconclusive("No messages were fully processed by the test."); } }