From f542c93a010c5954c1408a973b315f9019f52109 Mon Sep 17 00:00:00 2001 From: Sebastian Burckhardt Date: Mon, 3 Jan 2022 12:57:00 -0800 Subject: [PATCH] fix warnings (#100) --- test/LoadGeneratorApp/BaseParameters.cs | 2 +- test/LoadGeneratorApp/Client.cs | 35 ++++++----- test/LoadGeneratorApp/Dispatcher.cs | 62 ++++++++++---------- test/LoadGeneratorApp/FixedRateParameters.cs | 2 +- test/LoadGeneratorApp/Results.cs | 4 +- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/test/LoadGeneratorApp/BaseParameters.cs b/test/LoadGeneratorApp/BaseParameters.cs index 591a4338..95b75c09 100644 --- a/test/LoadGeneratorApp/BaseParameters.cs +++ b/test/LoadGeneratorApp/BaseParameters.cs @@ -57,7 +57,7 @@ public class BaseParameters public override string ToString() { - return string.Format($"{Prefix}-{Operation}-{RandomSeed}seed"); + return string.Format($"{this.Prefix}-{this.Operation}-{this.RandomSeed}seed"); } } } diff --git a/test/LoadGeneratorApp/Client.cs b/test/LoadGeneratorApp/Client.cs index 62b945dc..a2893b25 100644 --- a/test/LoadGeneratorApp/Client.cs +++ b/test/LoadGeneratorApp/Client.cs @@ -21,16 +21,15 @@ namespace LoadGeneratorApp /// /// A static client object, to be shared by all robots on the same node /// - internal class Client + class Client { - private readonly Random random = new Random(); - private readonly BaseParameters parameters; + readonly Random random = new Random(); + readonly BaseParameters parameters; - private static readonly SemaphoreSlim asyncLock = new SemaphoreSlim(1, 1); - private static Client client; - private static int referenceCount; - - private ConcurrentDictionary> continuations; + static readonly SemaphoreSlim asyncLock = new SemaphoreSlim(1, 1); + static Client client; + static int referenceCount; + readonly ConcurrentDictionary> continuations; public HttpClient HttpClient { get; private set; } @@ -83,11 +82,11 @@ public static void DeliverCallback(Guid reqId, string content) public string BaseUrl() { - string[] urls = parameters.ServiceUrls.Split(new char[] { ' ' }); - return urls[random.Next(urls.Length)]; + string[] urls = this.parameters.ServiceUrls.Split(new char[] { ' ' }); + return urls[this.random.Next(urls.Length)]; } - private Client(BaseParameters parameters) + Client(BaseParameters parameters) { this.parameters = parameters; this.HttpClient = new HttpClient(); @@ -95,12 +94,12 @@ private Client(BaseParameters parameters) this.continuations = new ConcurrentDictionary>(); } - private Task StartAsync() + Task StartAsync() { return Task.FromResult(this); } - private Task StopAsync() + Task StopAsync() { return Task.CompletedTask; } @@ -114,7 +113,7 @@ public async Task RunOrchestrationAsync(ILogger logger, string name, Name = name, InstanceId = instanceId, Input = input, - Timeout = parameters.TimeoutSeconds, + Timeout = this.parameters.TimeoutSeconds, UseReportedLatency = useReportedLatency, }; @@ -164,7 +163,7 @@ public async Task RunRemoteRequestWithCallback(Func(); var c = new CancellationTokenSource(); - var timeout = TimeSpan.FromSeconds(parameters.TimeoutSeconds); + var timeout = TimeSpan.FromSeconds(this.parameters.TimeoutSeconds); Task timeoutTask = Timeout(); async Task Timeout() { @@ -178,13 +177,13 @@ async Task Timeout() } } - continuations[wReqId] = tcs; + this.continuations[wReqId] = tcs; try { var inputObject = input(callbackUri(wReqId)); var content = inputObject.ToString(Formatting.Indented); - HttpResponseMessage response = await HttpClient.PostAsync(requestUri, new StringContent(content)).ConfigureAwait(false); + HttpResponseMessage response = await this.HttpClient.PostAsync(requestUri, new StringContent(content)).ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.OK) { throw new HttpRequestException(response.ReasonPhrase); @@ -196,7 +195,7 @@ async Task Timeout() } finally { - continuations.TryRemove(wReqId, out _); + this.continuations.TryRemove(wReqId, out _); c.Cancel(); await timeoutTask.ConfigureAwait(false); } diff --git a/test/LoadGeneratorApp/Dispatcher.cs b/test/LoadGeneratorApp/Dispatcher.cs index ea6c867b..4c509315 100644 --- a/test/LoadGeneratorApp/Dispatcher.cs +++ b/test/LoadGeneratorApp/Dispatcher.cs @@ -17,14 +17,14 @@ namespace LoadGeneratorApp public class Dispatcher { - BaseParameters parameters; - Random random; - Client client; + readonly BaseParameters parameters; + readonly Random random; + readonly Client client; int iteration; - int numRobots; - int robotNumber; - int privateIndex; - Func callbackUri; + readonly int numRobots; + readonly int robotNumber; + readonly int privateIndex; + readonly Func callbackUri; internal Dispatcher(BaseParameters parameters, Random random, int numRobots, Client client, int robotNumber, int privateIndex, Func callbackUri) { @@ -58,9 +58,9 @@ public async Task Execute(Operations operation, ILogger logger) case Operations.Ping: { - string url = client.BaseUrl() + "/ping"; + string url = this.client.BaseUrl() + "/ping"; - string result = await client.HttpClient.GetStringAsync(url); + string result = await this.client.HttpClient.GetStringAsync(url); logger?.LogTrace(result); @@ -69,9 +69,9 @@ public async Task Execute(Operations operation, ILogger logger) case Operations.Get: { - string url = client.BaseUrl(); + string url = this.client.BaseUrl(); - string result = await client.HttpClient.GetStringAsync(url); + string result = await this.client.HttpClient.GetStringAsync(url); logger?.LogTrace(result); @@ -80,9 +80,9 @@ public async Task Execute(Operations operation, ILogger logger) case Operations.Post: { - string url = client.BaseUrl(); + string url = this.client.BaseUrl(); - HttpResponseMessage response = await client.HttpClient.PostAsync(url, new StringContent("")); + HttpResponseMessage response = await this.client.HttpClient.PostAsync(url, new StringContent("")); string result = await response.Content.ReadAsStringAsync(); @@ -93,9 +93,9 @@ public async Task Execute(Operations operation, ILogger logger) case Operations.Hello100: { - string url = client.BaseUrl() + "/hellocities"; + string url = this.client.BaseUrl() + "/hellocities"; - HttpResponseMessage response = await client.HttpClient.PostAsync(url, new StringContent("100")); + HttpResponseMessage response = await this.client.HttpClient.PostAsync(url, new StringContent("100")); string result = await response.Content.ReadAsStringAsync(); @@ -117,7 +117,7 @@ public async Task Execute(Operations operation, ILogger logger) case Operations.HelloHttp: case Operations.HelloClient: { - bool useReportedLatency = (operation == Operations.Hello) && string.IsNullOrEmpty(parameters.EventHubsConnection); + bool useReportedLatency = (operation == Operations.Hello) && string.IsNullOrEmpty(this.parameters.EventHubsConnection); bool measureClientLatency = (operation == Operations.HelloClient); string orchestrationName = "HelloSequence3"; @@ -129,7 +129,7 @@ public async Task Execute(Operations operation, ILogger logger) Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); - var tuple = await client.RunOrchestrationAsync(logger, orchestrationName, instanceId, input, useReportedLatency).ConfigureAwait(false); + var tuple = await this.client.RunOrchestrationAsync(logger, orchestrationName, instanceId, input, useReportedLatency).ConfigureAwait(false); stopwatch.Stop(); @@ -174,16 +174,16 @@ public async Task Execute(Operations operation, ILogger logger) object input = new { - Length = opname.Contains("Long") ? parameters.NumberObjects : defaultLength, - WorkExponent = opname.Contains("Work") ? parameters.NumberObjects : defaultWorkExponent, - DataExponent = opname.Contains("Data") ? parameters.NumberObjects : defaultDataExponent, + Length = opname.Contains("Long") ? this.parameters.NumberObjects : defaultLength, + WorkExponent = opname.Contains("Work") ? this.parameters.NumberObjects : defaultWorkExponent, + DataExponent = opname.Contains("Data") ? this.parameters.NumberObjects : defaultDataExponent, }; if (!opname.Contains("Aws")) { logger?.LogTrace($"issued orchestration name={orchestrationName} instanceId={instanceId} input={JsonConvert.SerializeObject(input, Formatting.None)}"); - var tuple = await client.RunOrchestrationAsync(logger, orchestrationName, instanceId, input, useReportedLatency).ConfigureAwait(false); + var tuple = await this.client.RunOrchestrationAsync(logger, orchestrationName, instanceId, input, useReportedLatency).ConfigureAwait(false); logger?.LogTrace($"orchestration completed id={instanceId} result={tuple.Result}"); @@ -193,7 +193,7 @@ public async Task Execute(Operations operation, ILogger logger) { string stateMachineArn = AwsParameters.TriggeredSequence_Arn; JObject jinput = JObject.FromObject(new { input = input }); - Client.CallbackResponse response = await client.RunWrappedStepFunctionAsync(callbackUri, stateMachineArn, jinput); + Client.CallbackResponse response = await this.client.RunWrappedStepFunctionAsync(this.callbackUri, stateMachineArn, jinput); return new StatTuple() { Time = response.EndTime, Duration = response.CompletionTime }; } } @@ -205,22 +205,22 @@ public async Task Execute(Operations operation, ILogger logger) int target; if (operation == Operations.BankNoConflicts || operation == Operations.BankNoConflictsHttp) { - target = privateIndex; + target = this.privateIndex; } else { // pair of accounts is chosen randomly from available - target = random.Next(parameters.NumberObjects); + target = this.random.Next(this.parameters.NumberObjects); } string name = "BankTransaction"; var instanceId = $"Bank-{Guid.NewGuid():n}-!{target % 32:D2}"; - bool useReportedLatency = string.IsNullOrEmpty(parameters.EventHubsConnection) && operation != Operations.BankNoConflictsHttp; + bool useReportedLatency = string.IsNullOrEmpty(this.parameters.EventHubsConnection) && operation != Operations.BankNoConflictsHttp; logger?.LogTrace($"issued id={instanceId} target={target}"); - var tuple = await client.RunOrchestrationAsync(logger, name, instanceId, target, useReportedLatency).ConfigureAwait(false); + var tuple = await this.client.RunOrchestrationAsync(logger, name, instanceId, target, useReportedLatency).ConfigureAwait(false); logger?.LogTrace($"received id={instanceId} result={tuple.Result}"); @@ -229,9 +229,9 @@ public async Task Execute(Operations operation, ILogger logger) case Operations.CallbackTest: { - string requestUri = client.BaseUrl() + "/callbackTest"; + string requestUri = this.client.BaseUrl() + "/callbackTest"; JObject input(string callbackUri) => new JObject(new JProperty("CallbackUri", callbackUri)); - Client.CallbackResponse response = await client.RunRemoteRequestWithCallback(callbackUri, requestUri, input); + Client.CallbackResponse response = await this.client.RunRemoteRequestWithCallback(this.callbackUri, requestUri, input); return new StatTuple() { Time = response.EndTime, Duration = response.CompletionTime }; } @@ -240,7 +240,7 @@ public async Task Execute(Operations operation, ILogger logger) string stateMachineArn = AwsParameters.Hello_Arn; //JObject input = JObject.Parse("{ \"array\": [ {}, {}, {} ] }"); JObject input = JObject.Parse("{ \"array\": [ {} ] }"); - Client.CallbackResponse response = await client.RunWrappedStepFunctionAsync(callbackUri, stateMachineArn, input); + Client.CallbackResponse response = await this.client.RunWrappedStepFunctionAsync(this.callbackUri, stateMachineArn, input); return new StatTuple() { Time = response.EndTime, Duration = response.CompletionTime }; } @@ -251,7 +251,7 @@ public async Task Execute(Operations operation, ILogger logger) new JProperty("s3Bucket", AwsParameters.Image_s3Bucket), new JProperty("s3Key", AwsParameters.Image_s3Key), new JProperty("objectID", AwsParameters.Image_objectID)); - Client.CallbackResponse response = await client.RunWrappedStepFunctionAsync(callbackUri, stateMachineArn, input); + Client.CallbackResponse response = await this.client.RunWrappedStepFunctionAsync(this.callbackUri, stateMachineArn, input); return new StatTuple() { Time = response.EndTime, Duration = response.CompletionTime }; } @@ -275,7 +275,7 @@ public async Task Execute(Operations operation, ILogger logger) logger?.LogTrace($"issued id={instanceId} "); - var tuple = await client.RunOrchestrationAsync(logger, name, instanceId, input, true).ConfigureAwait(false); + var tuple = await this.client.RunOrchestrationAsync(logger, name, instanceId, input, true).ConfigureAwait(false); logger?.LogTrace($"received id={instanceId} result={tuple.Result}"); diff --git a/test/LoadGeneratorApp/FixedRateParameters.cs b/test/LoadGeneratorApp/FixedRateParameters.cs index 5e04dfe5..9b8d2764 100644 --- a/test/LoadGeneratorApp/FixedRateParameters.cs +++ b/test/LoadGeneratorApp/FixedRateParameters.cs @@ -40,7 +40,7 @@ public class FixedRateParameters : BaseParameters // a short human-readable string describing the test, used for filenames and in display public override string ToString() { - return string.Format($"{base.ToString()}-{Rate}rate-{Robots}robots-{Duration}sec"); + return string.Format($"{base.ToString()}-{this.Rate}rate-{this.Robots}robots-{this.Duration}sec"); } } } diff --git a/test/LoadGeneratorApp/Results.cs b/test/LoadGeneratorApp/Results.cs index b2666d9d..bfab5468 100644 --- a/test/LoadGeneratorApp/Results.cs +++ b/test/LoadGeneratorApp/Results.cs @@ -44,8 +44,8 @@ public static void SaveResults([ActivityTrigger] Results results) resultblob.UploadText(JsonConvert.SerializeObject(results, Formatting.Indented)); } - private static string RESULTS_CONNECTION = "ResultsConnection"; - private static string RESULTFILE_CONTAINER = "results"; + static readonly string RESULTS_CONNECTION = "ResultsConnection"; + static readonly string RESULTFILE_CONTAINER = "results"; public static string MakeTestName(string benchmarkname) {