Skip to content

Commit

Permalink
Apply reformat patch
Browse files Browse the repository at this point in the history
  • Loading branch information
wkirschenmann committed Aug 10, 2023
1 parent 0ab2468 commit 75f0a51
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 98 deletions.
13 changes: 8 additions & 5 deletions Adaptors/Memory/src/SessionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public Task<TaskOptions> GetDefaultTaskOptionAsync(string sessionId,
throw new SessionNotFoundException($"Key '{sessionId}' not found");
}

return Task.FromResult(storage_[sessionId].Options);
return Task.FromResult(storage_[sessionId]
.Options);
}

/// <inheritdoc />
Expand Down Expand Up @@ -160,10 +161,12 @@ public IAsyncEnumerable<string> ListSessionsAsync(SessionFilter sessionFilte

return rawList.Where(sessionId => sessionFilter.StatusesCase switch
{
SessionFilter.StatusesOneofCase.None => true,
SessionFilter.StatusesOneofCase.Included => sessionFilter.Included.Statuses.Contains(storage_[sessionId].Status),
SessionFilter.StatusesOneofCase.Excluded => !sessionFilter.Excluded.Statuses.Contains(storage_[sessionId].Status),
_ => throw new ArgumentException("Filter is set to an unknown StatusesCase."),
SessionFilter.StatusesOneofCase.None => true,
SessionFilter.StatusesOneofCase.Included => sessionFilter.Included.Statuses.Contains(storage_[sessionId]
.Status),
SessionFilter.StatusesOneofCase.Excluded => !sessionFilter.Excluded.Statuses.Contains(storage_[sessionId]
.Status),
_ => throw new ArgumentException("Filter is set to an unknown StatusesCase."),
});
}

Expand Down
19 changes: 12 additions & 7 deletions Adaptors/Memory/src/TaskTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public async Task<IEnumerable<TaskStatusCount>> CountTasksAsync(TaskFilter
CancellationToken cancellationToken = default)
=> await ListTasksAsync(filter,
cancellationToken)
.Select(taskId => taskId2TaskData_[taskId].Status)
.Select(taskId => taskId2TaskData_[taskId]
.Status)
.GroupBy(status => status)
.SelectAwait(async grouping => new TaskStatusCount(grouping.Key,
await grouping.CountAsync(cancellationToken)
Expand Down Expand Up @@ -224,10 +225,12 @@ public IAsyncEnumerable<string> ListTasksAsync(TaskFilter filter,

return rawList.Where(taskId => filter.StatusesCase switch
{
TaskFilter.StatusesOneofCase.None => true,
TaskFilter.StatusesOneofCase.Included => filter.Included.Statuses.Contains(taskId2TaskData_[taskId].Status),
TaskFilter.StatusesOneofCase.Excluded => !filter.Excluded.Statuses.Contains(taskId2TaskData_[taskId].Status),
_ => throw new ArgumentException("Filter is set to an unknown StatusesCase."),
TaskFilter.StatusesOneofCase.None => true,
TaskFilter.StatusesOneofCase.Included => filter.Included.Statuses.Contains(taskId2TaskData_[taskId]
.Status),
TaskFilter.StatusesOneofCase.Excluded => !filter.Excluded.Statuses.Contains(taskId2TaskData_[taskId]
.Status),
_ => throw new ArgumentException("Filter is set to an unknown StatusesCase."),
})
.ToAsyncEnumerable();
}
Expand Down Expand Up @@ -356,7 +359,8 @@ public Task<Output> GetTaskOutput(string taskId,
throw new TaskNotFoundException($"Key '{taskId}' not found");
}

return Task.FromResult(taskId2TaskData_[taskId].Output);
return Task.FromResult(taskId2TaskData_[taskId]
.Output);
}

/// <inheritdoc />
Expand Down Expand Up @@ -429,7 +433,8 @@ public Task<IEnumerable<string>> GetParentTaskIds(string taskId,
throw new TaskNotFoundException($"Key '{taskId}' not found");
}

return Task.FromResult(taskId2TaskData_[taskId].ParentTaskIds as IEnumerable<string>);
return Task.FromResult(taskId2TaskData_[taskId]
.ParentTaskIds as IEnumerable<string>);
}

/// <inheritdoc />
Expand Down
18 changes: 12 additions & 6 deletions Adaptors/MongoDB/src/Table/DataModel/IndexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,26 @@ public static CreateIndexModel<T> CreateIndex<T>(bool

if (field.Length == 1)
{
if (unique && field[0].type == IndexType.Hashed)
if (unique && field[0]
.type == IndexType.Hashed)
{
throw new ArgumentOutOfRangeException(nameof(unique),
"A hashed index cannot be constrained to be unique");
}

return field[0].type switch
return field[0]
.type switch
{
IndexType.Ascending => CreateAscendingIndex(field[0].expression,
IndexType.Ascending => CreateAscendingIndex(field[0]
.expression,
unique),
IndexType.Descending => CreateAscendingIndex(field[0].expression,
IndexType.Descending => CreateAscendingIndex(field[0]
.expression,
unique),
IndexType.Hashed => CreateHashedIndex(field[0].expression),
IndexType.Text => CreateTextIndex(field[0].expression,
IndexType.Hashed => CreateHashedIndex(field[0]
.expression),
IndexType.Text => CreateTextIndex(field[0]
.expression,
unique),
_ => throw new ArgumentOutOfRangeException(nameof(field),
"Invalid IndexType"),
Expand Down
4 changes: 2 additions & 2 deletions Adaptors/MongoDB/tests/SessionTableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ namespace ArmoniK.Core.Adapters.MongoDB.Tests;

public class SessionTableTests : SessionTableTestBase
{
private MongoDatabaseProvider? tableProvider_;

public override void TearDown()
{
tableProvider_?.Dispose();
RunTests = false;
}

private MongoDatabaseProvider? tableProvider_;

public override void GetSessionTableInstance()
{
tableProvider_ = new MongoDatabaseProvider();
Expand Down
5 changes: 3 additions & 2 deletions Common/src/Auth/Authentication/Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,9 @@ public async Task<ClaimsPrincipal> GetImpersonatedIdentityAsync(ClaimsPrincipal
/// <returns>Value of the header if found and not empty, null otherwise</returns>
private string? TryGetHeader(string headerName)
{
if (!string.IsNullOrEmpty(headerName) && Request.Headers.TryGetValue(headerName,
out var values) && !string.IsNullOrWhiteSpace(values.First()))
if (!string.IsNullOrEmpty(headerName) && Request.Headers.TryGetValue(headerName,
out var values) &&
!string.IsNullOrWhiteSpace(values.First()))
{
return values.First();
}
Expand Down
8 changes: 4 additions & 4 deletions Common/src/gRPC/ExpressionBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ public static Expression<Func<TIn, bool>> MakeCallString<TIn>(Expression<Func<TI
typeof(string));

var methodInfo = typeof(string).GetMethods()
.First(m => m.Name == method && m.GetParameters()
.Length == 1 && m.GetParameters()
.First()
.ParameterType == typeof(string));
.First(m => m.Name == method && m.GetParameters()
.Length == 1 && m.GetParameters()
.First()
.ParameterType == typeof(string));

var call = Expression.Call(member,
methodInfo,
Expand Down
15 changes: 10 additions & 5 deletions Common/tests/Auth/AuthenticationIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,16 @@ public static Metadata GetHeaders(IdentityIndex index,
headers.Add(AuthenticatorOptions.DefaultAuth.ImpersonationIdHeader,
(int)impersonate < 0
? "DoesntExist"
: Identities[(int)impersonate].UserId);
: Identities[(int)impersonate]
.UserId);
}
else if (impersonationType == ImpersonationType.ImpersonateUsername)
{
headers.Add(AuthenticatorOptions.DefaultAuth.ImpersonationUsernameHeader,
(int)impersonate < 0
? "DoesntExist"
: Identities[(int)impersonate].UserName);
: Identities[(int)impersonate]
.UserName);
}

return headers;
Expand Down Expand Up @@ -842,13 +844,15 @@ public static IEnumerable GetTestReflectionCases(bool isAsync,
? "Async"
: ""),
// - The parameter of the method
GetParameters(m.GetParameters()[0].ParameterType,
GetParameters(m.GetParameters()[0]
.ParameterType,
clientStream),
// - The Request type
clientStream
? m.GetParameters()[0]
.ParameterType.GetGenericArguments()[0]
: m.GetParameters()[0].ParameterType,
: m.GetParameters()[0]
.ParameterType,
// - The Response type
serverStream
? m.GetParameters()[1]
Expand Down Expand Up @@ -1353,7 +1357,8 @@ public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters,
var castedResponse = (GetCurrentUserResponse)response!;
// Check if the returned username is correct
Assert.AreEqual(options_!.RequireAuthentication
? Identities[finalUserIndex].UserName
? Identities[finalUserIndex]
.UserName
: "Anonymous",
castedResponse.User.Username);
// Check if the role list is empty when there is no authorization, otherwise returns the roles
Expand Down
15 changes: 10 additions & 5 deletions Common/tests/Pollster/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ await holder.Agent.FinalizeTaskCreation(CancellationToken.None)
Assert.Contains(holder.TaskWithDependencies2,
holder.QueueStorage.Messages[Partition]);
Assert.AreEqual(2,
holder.QueueStorage.Messages[Partition].Count);
holder.QueueStorage.Messages[Partition]
.Count);

var taskData1 = await holder.TaskTable.ReadTaskAsync(holder.TaskWithDependencies1,
CancellationToken.None)
Expand Down Expand Up @@ -719,7 +720,8 @@ await holder.Agent.FinalizeTaskCreation(CancellationToken.None)
.ConfigureAwait(false);

Assert.AreEqual(3,
holder.QueueStorage.Messages[Partition].Count);
holder.QueueStorage.Messages[Partition]
.Count);

taskData3 = await holder.TaskTable.ReadTaskAsync(taskId3,
CancellationToken.None)
Expand Down Expand Up @@ -810,10 +812,13 @@ await holder.Agent.GetResourceData(new DataRequest
Assert.AreEqual(3,
resourceData.Messages.Count);
Assert.AreEqual("Data1",
resourceData.Messages[0].Data.Data);
resourceData.Messages[0]
.Data.Data);
Assert.AreEqual("Data2",
resourceData.Messages[1].Data.Data);
Assert.IsTrue(resourceData.Messages[2].Data.DataComplete);
resourceData.Messages[1]
.Data.Data);
Assert.IsTrue(resourceData.Messages[2]
.Data.DataComplete);
}

[Test]
Expand Down
84 changes: 56 additions & 28 deletions Common/tests/Pollster/DataPrefetcherTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,73 +122,101 @@ public async Task EmptyPayloadAndOneDependency()
Console.WriteLine(request);
}

Assert.AreEqual(computeRequests[0].TypeCase,
Assert.AreEqual(computeRequests[0]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.InitRequest);
Assert.AreEqual(computeRequests[0].InitRequest.SessionId,
Assert.AreEqual(computeRequests[0]
.InitRequest.SessionId,
sessionId);
Assert.AreEqual(computeRequests[0].InitRequest.TaskId,
Assert.AreEqual(computeRequests[0]
.InitRequest.TaskId,
taskId);
Assert.AreEqual(computeRequests[0]
.InitRequest.ExpectedOutputKeys.First(),
output1);

Assert.AreEqual(computeRequests[1].TypeCase,
Assert.AreEqual(computeRequests[1]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload);
Assert.AreEqual(computeRequests[1].Payload.TypeCase,
Assert.AreEqual(computeRequests[1]
.Payload.TypeCase,
DataChunk.TypeOneofCase.Data);

Assert.AreEqual(computeRequests[2].TypeCase,
Assert.AreEqual(computeRequests[2]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload);
Assert.AreEqual(computeRequests[2].Payload.TypeCase,
Assert.AreEqual(computeRequests[2]
.Payload.TypeCase,
DataChunk.TypeOneofCase.Data);

Assert.AreEqual(computeRequests[3].TypeCase,
Assert.AreEqual(computeRequests[3]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload);
Assert.AreEqual(computeRequests[3].Payload.TypeCase,
Assert.AreEqual(computeRequests[3]
.Payload.TypeCase,
DataChunk.TypeOneofCase.Data);

Assert.AreEqual(computeRequests[4].TypeCase,
Assert.AreEqual(computeRequests[4]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload);
Assert.AreEqual(computeRequests[4].Payload.TypeCase,
Assert.AreEqual(computeRequests[4]
.Payload.TypeCase,
DataChunk.TypeOneofCase.DataComplete);
Assert.IsTrue(computeRequests[4].Payload.DataComplete);
Assert.IsTrue(computeRequests[4]
.Payload.DataComplete);

Assert.AreEqual(computeRequests[5].TypeCase,
Assert.AreEqual(computeRequests[5]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.InitData);
Assert.AreEqual(computeRequests[5].InitData.Key,
Assert.AreEqual(computeRequests[5]
.InitData.Key,
dependency1);

Assert.AreEqual(computeRequests[6].TypeCase,
Assert.AreEqual(computeRequests[6]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data);
Assert.AreEqual(computeRequests[6].Data.TypeCase,
Assert.AreEqual(computeRequests[6]
.Data.TypeCase,
DataChunk.TypeOneofCase.Data);

Assert.AreEqual(computeRequests[7].TypeCase,
Assert.AreEqual(computeRequests[7]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data);
Assert.AreEqual(computeRequests[7].Data.TypeCase,
Assert.AreEqual(computeRequests[7]
.Data.TypeCase,
DataChunk.TypeOneofCase.Data);

Assert.AreEqual(computeRequests[8].TypeCase,
Assert.AreEqual(computeRequests[8]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data);
Assert.AreEqual(computeRequests[8].Data.TypeCase,
Assert.AreEqual(computeRequests[8]
.Data.TypeCase,
DataChunk.TypeOneofCase.Data);

Assert.AreEqual(computeRequests[9].TypeCase,
Assert.AreEqual(computeRequests[9]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data);
Assert.AreEqual(computeRequests[9].Data.TypeCase,
Assert.AreEqual(computeRequests[9]
.Data.TypeCase,
DataChunk.TypeOneofCase.Data);

Assert.AreEqual(computeRequests[10].TypeCase,
Assert.AreEqual(computeRequests[10]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data);
Assert.AreEqual(computeRequests[10].Data.TypeCase,
Assert.AreEqual(computeRequests[10]
.Data.TypeCase,
DataChunk.TypeOneofCase.DataComplete);
Assert.IsTrue(computeRequests[10].Data.DataComplete);
Assert.IsTrue(computeRequests[10]
.Data.DataComplete);

Assert.AreEqual(computeRequests[11].TypeCase,
Assert.AreEqual(computeRequests[11]
.TypeCase,
ProcessRequest.Types.ComputeRequest.TypeOneofCase.InitData);
Assert.AreEqual(computeRequests[11].InitData.TypeCase,
Assert.AreEqual(computeRequests[11]
.InitData.TypeCase,
ProcessRequest.Types.ComputeRequest.Types.InitData.TypeOneofCase.LastData);
Assert.IsTrue(computeRequests[11].InitData.LastData);
Assert.IsTrue(computeRequests[11]
.InitData.LastData);
}

[Test]
Expand Down
Loading

0 comments on commit 75f0a51

Please sign in to comment.