/// <summary> /// Gets the number of items in the cache. /// </summary> private static async Task GetItemCountAsync() { HttpQueueClient <Item> qc = new HttpQueueClient <Item>(_serviceUri, c_ListenerName); long priorityCount = await qc.PriorityCountAsync().ConfigureAwait(false); Stopwatch sw = Stopwatch.StartNew(); Task[] tasks = new Task[priorityCount + 4]; long itemCount = 0, allQueueCount = 0, leasedCount = 0, expiredCount = 0; long itemTimes = 0, allQueueTimes = 0, leasedTimes = 0, expiredTimes = 0; tasks[0] = qc.CountAsync(QueueType.ItemQueue).ContinueWith((t) => { itemCount = t.Result; itemTimes = sw.ElapsedMilliseconds; }); tasks[1] = qc.CountAsync(QueueType.AllQueues).ContinueWith((t) => { allQueueCount = t.Result; allQueueTimes = sw.ElapsedMilliseconds; }); tasks[2] = qc.CountAsync(QueueType.LeaseQueue).ContinueWith((t) => { leasedCount = t.Result; leasedTimes = sw.ElapsedMilliseconds; }); tasks[3] = qc.CountAsync(QueueType.ExpiredQueue).ContinueWith((t) => { expiredCount = t.Result; expiredTimes = sw.ElapsedMilliseconds; }); long[] queues = new long[priorityCount]; for (int i = 0; i < priorityCount; i++) { var index = i; tasks[i + 4] = qc.CountAsync(i).ContinueWith((t) => { queues[index] = t.Result; }); } // Wait for all queue calls to complete. Task.WaitAll(tasks); Console.WriteLine($" Item count: {itemCount:N0} in {itemTimes:N0}ms"); Console.WriteLine($" Leased item count: {leasedCount:N0} in {allQueueTimes:N0}ms"); Console.WriteLine($"Expired item count: {expiredCount:N0} in {leasedTimes:N0}ms"); Console.WriteLine($" All queues count: {allQueueCount:N0} in {expiredTimes:N0}ms"); for (int i = 0; i < queues.Length; i++) { Console.WriteLine($" Queue {i,2:N0}: {queues[i]:N0}"); } }
/// <summary> /// Gets the number of priorities. /// </summary> private static void GetPriorityCount() { HttpQueueClient <Item> qc = new HttpQueueClient <Item>(_serviceUri, c_ListenerName); long totalCount = qc.PriorityCountAsync().GetAwaiter().GetResult(); Console.WriteLine($"There are {totalCount} priorities."); }
public async Task GetPriorityCount_Test() { HttpQueueClient <string> qc = new HttpQueueClient <string>(new Uri(serviceUri), c_ListenerName); Assert.IsNotNull(qc); int count = await qc.PriorityCountAsync().ConfigureAwait(false); Assert.AreEqual(5, count); }
/// <summary> /// ReadTest Constructor. /// </summary> /// <param name="batchSize">Size of the batch to process.</param> /// <param name="threads">Number of threads to run concurrently.</param> /// <param name="requests">Number of requests to process.</param> /// <param name="outputFileName">Name of the file to output the results to.</param> /// <param name="cancellationToken">CanellationToken instance.</param> public WriteTest(int batchSize, int threads, long requests, string outputFileName, Func <T> create, CancellationToken cancellationToken) : base(threads, requests, outputFileName) { Guard.ArgumentNotNull(create, nameof(create)); _batchSize = batchSize; _createInstance = create; // Create a queue client and retrieve the number of priorities. HttpQueueClient <T> qc = new HttpQueueClient <T>(new Uri(serviceUri), c_ListenerName); _priorityCount = qc.PriorityCountAsync().GetAwaiter().GetResult(); }