Skip to content

Commit

Permalink
fix warnings (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianburckhardt authored Jan 3, 2022
1 parent beaeeb7 commit f542c93
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 53 deletions.
2 changes: 1 addition & 1 deletion test/LoadGeneratorApp/BaseParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
35 changes: 17 additions & 18 deletions test/LoadGeneratorApp/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ namespace LoadGeneratorApp
/// <summary>
/// A static client object, to be shared by all robots on the same node
/// </summary>
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<Guid, TaskCompletionSource<string>> continuations;
static readonly SemaphoreSlim asyncLock = new SemaphoreSlim(1, 1);
static Client client;
static int referenceCount;
readonly ConcurrentDictionary<Guid, TaskCompletionSource<string>> continuations;

public HttpClient HttpClient { get; private set; }

Expand Down Expand Up @@ -83,24 +82,24 @@ 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();
this.HttpClient.Timeout = TimeSpan.FromSeconds(parameters.TimeoutSeconds + 20); // prefer reported timeout to http timeout
this.continuations = new ConcurrentDictionary<Guid, TaskCompletionSource<string>>();
}

private Task<Client> StartAsync()
Task<Client> StartAsync()
{
return Task.FromResult(this);
}

private Task StopAsync()
Task StopAsync()
{
return Task.CompletedTask;
}
Expand All @@ -114,7 +113,7 @@ public async Task<StatTuple> RunOrchestrationAsync(ILogger logger, string name,
Name = name,
InstanceId = instanceId,
Input = input,
Timeout = parameters.TimeoutSeconds,
Timeout = this.parameters.TimeoutSeconds,
UseReportedLatency = useReportedLatency,
};

Expand Down Expand Up @@ -164,7 +163,7 @@ public async Task<CallbackResponse> RunRemoteRequestWithCallback(Func<Guid,strin
var tcs = new TaskCompletionSource<string>();
var c = new CancellationTokenSource();

var timeout = TimeSpan.FromSeconds(parameters.TimeoutSeconds);
var timeout = TimeSpan.FromSeconds(this.parameters.TimeoutSeconds);
Task timeoutTask = Timeout();
async Task Timeout()
{
Expand All @@ -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);
Expand All @@ -196,7 +195,7 @@ async Task Timeout()
}
finally
{
continuations.TryRemove(wReqId, out _);
this.continuations.TryRemove(wReqId, out _);
c.Cancel();
await timeoutTask.ConfigureAwait(false);
}
Expand Down
62 changes: 31 additions & 31 deletions test/LoadGeneratorApp/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Guid, string> callbackUri;
readonly int numRobots;
readonly int robotNumber;
readonly int privateIndex;
readonly Func<Guid, string> callbackUri;

internal Dispatcher(BaseParameters parameters, Random random, int numRobots, Client client, int robotNumber, int privateIndex, Func<Guid, string> callbackUri)
{
Expand Down Expand Up @@ -58,9 +58,9 @@ public async Task<StatTuple> 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);

Expand All @@ -69,9 +69,9 @@ public async Task<StatTuple> 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);

Expand All @@ -80,9 +80,9 @@ public async Task<StatTuple> 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();

Expand All @@ -93,9 +93,9 @@ public async Task<StatTuple> 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();

Expand All @@ -117,7 +117,7 @@ public async Task<StatTuple> 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";
Expand All @@ -129,7 +129,7 @@ public async Task<StatTuple> 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();

Expand Down Expand Up @@ -174,16 +174,16 @@ public async Task<StatTuple> 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}");

Expand All @@ -193,7 +193,7 @@ public async Task<StatTuple> 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 };
}
}
Expand All @@ -205,22 +205,22 @@ public async Task<StatTuple> 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}");

Expand All @@ -229,9 +229,9 @@ public async Task<StatTuple> 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 };
}

Expand All @@ -240,7 +240,7 @@ public async Task<StatTuple> 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 };
}

Expand All @@ -251,7 +251,7 @@ public async Task<StatTuple> 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 };
}

Expand All @@ -275,7 +275,7 @@ public async Task<StatTuple> 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}");

Expand Down
2 changes: 1 addition & 1 deletion test/LoadGeneratorApp/FixedRateParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
4 changes: 2 additions & 2 deletions test/LoadGeneratorApp/Results.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit f542c93

Please sign in to comment.