diff --git a/Adaptors/Amqp/src/ConnectionAmqp.cs b/Adaptors/Amqp/src/ConnectionAmqp.cs index 56277742a..17a501174 100644 --- a/Adaptors/Amqp/src/ConnectionAmqp.cs +++ b/Adaptors/Amqp/src/ConnectionAmqp.cs @@ -53,24 +53,18 @@ public ConnectionAmqp(QueueCommon.Amqp options, public Connection? Connection { get; private set; } public Task Check(HealthCheckTag tag) - { - switch (tag) - { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} is not yet initialized.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && Connection is not null && Connection.ConnectionState == ConnectionState.Opened - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} not initialized or connection dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + => tag switch + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} is not yet initialized.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Connection is not null && Connection.ConnectionState == ConnectionState.Opened + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; public async Task Init(CancellationToken cancellationToken = default) => await connectionTask_; @@ -113,9 +107,8 @@ private static async Task InitTask(ConnectionAmqp conn, { conn.Connection = await connectionFactory.CreateAsync(address) .ConfigureAwait(false); - conn.Connection.AddClosedCallback((x, - e) => OnCloseConnection(x, - e, + conn.Connection.AddClosedCallback((_, + e) => OnCloseConnection(e, conn.logger_)); break; } @@ -137,9 +130,8 @@ await Task.Delay(1000 * retry, conn.isInitialized_ = true; } - private static void OnCloseConnection(IAmqpObject sender, - Error? error, - ILogger logger) + private static void OnCloseConnection(Error? error, + ILogger logger) { if (error == null) { @@ -147,7 +139,7 @@ private static void OnCloseConnection(IAmqpObject sender, } else { - logger.LogWarning("AMQP Connection closed with error: {0}", + logger.LogWarning("AMQP Connection closed with error: {error}", error.ToString()); } } diff --git a/Adaptors/Amqp/src/PullQueueStorage.cs b/Adaptors/Amqp/src/PullQueueStorage.cs index 22b0cd1cd..bc2165b05 100644 --- a/Adaptors/Amqp/src/PullQueueStorage.cs +++ b/Adaptors/Amqp/src/PullQueueStorage.cs @@ -79,10 +79,10 @@ await ConnectionAmqp.Init(cancellationToken) $"{Options.PartitionId}###q{i}"); /* linkCredit_: the maximum number of messages the - * remote peer can send to the receiver. - * With the goal of minimizing/deactivating - * prefetching, a value of 1 gave us the desired - * behavior. We pick a default value of 2 to have "some cache". */ + * remote peer can send to the receiver. + * With the goal of minimizing/deactivating + * prefetching, a value of 1 gave us the desired + * behavior. We pick a default value of 2 to have "some cache". */ rl.SetCredit(Options.LinkCredit); return rl; })) @@ -141,7 +141,6 @@ public async IAsyncEnumerable PullMessagesAsync(int sender, receiver, Encoding.UTF8.GetString(message.Body as byte[] ?? throw new InvalidOperationException("Error while deserializing message")), - logger_, cancellationToken); break; diff --git a/Adaptors/Amqp/src/QueueMessageHandler.cs b/Adaptors/Amqp/src/QueueMessageHandler.cs index 16d74d12e..869e73176 100644 --- a/Adaptors/Amqp/src/QueueMessageHandler.cs +++ b/Adaptors/Amqp/src/QueueMessageHandler.cs @@ -24,13 +24,10 @@ using ArmoniK.Core.Base; -using Microsoft.Extensions.Logging; - namespace ArmoniK.Core.Adapters.Amqp; public class QueueMessageHandler : IQueueMessageHandler { - private readonly ILogger logger_; private readonly Message message_; private readonly IReceiverLink receiver_; private readonly ISenderLink sender_; @@ -39,13 +36,11 @@ public QueueMessageHandler(Message message, ISenderLink sender, IReceiverLink receiver, string taskId, - ILogger logger, CancellationToken cancellationToken) { message_ = message; sender_ = sender; receiver_ = receiver; - logger_ = logger; TaskId = taskId; CancellationToken = cancellationToken; ReceptionDateTime = DateTime.UtcNow; diff --git a/Adaptors/Amqp/tests/ArmoniK.Core.Adapters.Amqp.Tests.csproj b/Adaptors/Amqp/tests/ArmoniK.Core.Adapters.Amqp.Tests.csproj index 7b7fab604..087dc53af 100644 --- a/Adaptors/Amqp/tests/ArmoniK.Core.Adapters.Amqp.Tests.csproj +++ b/Adaptors/Amqp/tests/ArmoniK.Core.Adapters.Amqp.Tests.csproj @@ -1,30 +1,30 @@ - - net6.0 - false + + net6.0 + false enable - + - - Embedded - true - DEBUG;TRACE - + + Embedded + true + DEBUG;TRACE + - - - - - + + + + + - - - + + + - - - - + + + + diff --git a/Adaptors/LocalStorage/src/ArmoniK.Core.Adapters.LocalStorage.csproj b/Adaptors/LocalStorage/src/ArmoniK.Core.Adapters.LocalStorage.csproj index 1f0a19a16..47e67bc85 100644 --- a/Adaptors/LocalStorage/src/ArmoniK.Core.Adapters.LocalStorage.csproj +++ b/Adaptors/LocalStorage/src/ArmoniK.Core.Adapters.LocalStorage.csproj @@ -14,7 +14,7 @@ - + diff --git a/Adaptors/LocalStorage/src/ObjectStorage.cs b/Adaptors/LocalStorage/src/ObjectStorage.cs index 0d540bd84..d1e7cbfc3 100644 --- a/Adaptors/LocalStorage/src/ObjectStorage.cs +++ b/Adaptors/LocalStorage/src/ObjectStorage.cs @@ -80,24 +80,18 @@ public Task Init(CancellationToken cancellationToken) /// public Task Check(HealthCheckTag tag) - { - switch (tag) - { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Local storage not initialized yet.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && Directory.Exists(path_) - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Local storage not initialized or folder has been deleted.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + => tag switch + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Local storage not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Directory.Exists(path_) + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Local storage not initialized or folder has been deleted.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; /// public async Task AddOrUpdateAsync(string key, diff --git a/Adaptors/LocalStorage/tests/ObjectStorageTests.cs b/Adaptors/LocalStorage/tests/ObjectStorageTests.cs index e4eca5759..48fefd88b 100644 --- a/Adaptors/LocalStorage/tests/ObjectStorageTests.cs +++ b/Adaptors/LocalStorage/tests/ObjectStorageTests.cs @@ -35,7 +35,7 @@ public override void TearDown() RunTests = false; } - public override void GetObjectStorageInstance() + protected override void GetObjectStorageInstance() { var rootPath = Path.Combine(Path.GetTempPath(), $"ArmoniK.{Environment.ProcessId}"); diff --git a/Adaptors/Memory/src/PushQueueStorage.cs b/Adaptors/Memory/src/PushQueueStorage.cs index 8fe6addb0..05152fa4f 100644 --- a/Adaptors/Memory/src/PushQueueStorage.cs +++ b/Adaptors/Memory/src/PushQueueStorage.cs @@ -54,16 +54,12 @@ public async Task PushMessagesAsync(IEnumerable messages, { var priorityGroups = messages.GroupBy(msgData => msgData.Options.Priority); await Task.WhenAll(priorityGroups.Select(group => PushMessagesAsync(group, - partitionId, - group.Key, - cancellationToken))) + group.Key))) .ConfigureAwait(false); } private Task PushMessagesAsync(IEnumerable messages, - string partitionId, - int priority = 1, - CancellationToken cancellationToken = default) + int priority = 1) { var messageHandlers = messages.Select(message => new MessageHandler { diff --git a/Adaptors/Memory/src/QueueStorage.cs b/Adaptors/Memory/src/QueueStorage.cs index 909e94622..ba4644c0a 100644 --- a/Adaptors/Memory/src/QueueStorage.cs +++ b/Adaptors/Memory/src/QueueStorage.cs @@ -30,7 +30,7 @@ namespace ArmoniK.Core.Adapters.Memory; -public class QueueStorage : IQueueStorage +public class QueueStorage : IPullQueueStorage, IPushQueueStorage { private static readonly MessageHandler DefaultMessage = new(); @@ -41,10 +41,6 @@ public class QueueStorage : IQueueStorage private readonly SortedList queues_ = new(MessageComparer.Instance); - /// - public string PartitionId - => ""; - /// public Task Check(HealthCheckTag tag) => Task.FromResult(HealthCheckResult.Healthy()); @@ -57,6 +53,7 @@ public Task Init(CancellationToken cancellationToken) public int MaxPriority => 100; + /// public async IAsyncEnumerable PullMessagesAsync(int nbMessages, [EnumeratorCancellation] CancellationToken cancellationToken = default) @@ -96,16 +93,17 @@ await message.Semaphore.WaitAsync(CancellationToken.None) } /// - public Task PushMessagesAsync(IEnumerable messages, - string partitionId, - int priority = 1, - CancellationToken cancellationToken = default) + public Task PushMessagesAsync(IEnumerable messages, + string _, + CancellationToken cancellationToken = default) { + cancellationToken.ThrowIfCancellationRequested(); + var messageHandlers = messages.Select(message => new MessageHandler { IsVisible = true, - Priority = priority, - TaskId = message, + Priority = message.Options.Priority, + TaskId = message.TaskId, CancellationToken = CancellationToken.None, Status = QueueMessageStatus.Waiting, Queues = queues_, diff --git a/Adaptors/Memory/src/ResultTable.cs b/Adaptors/Memory/src/ResultTable.cs index 807d6945c..76c736ee1 100644 --- a/Adaptors/Memory/src/ResultTable.cs +++ b/Adaptors/Memory/src/ResultTable.cs @@ -302,18 +302,18 @@ public Task SetTaskOwnership(string sessi throw new SessionNotFoundException($"Session '{session}' not found"); } - foreach (var req in requests) + foreach (var (resultId, taskId) in requests) { - if (!session.TryGetValue(req.resultId, + if (!session.TryGetValue(resultId, out var result)) { - throw new ResultNotFoundException($"Key '{req.resultId}' not found"); + throw new ResultNotFoundException($"Key '{resultId}' not found"); } - session.TryUpdate(req.resultId, + session.TryUpdate(resultId, result with { - OwnerTaskId = req.taskId, + OwnerTaskId = taskId, }, result); } diff --git a/Adaptors/Memory/src/TaskTable.cs b/Adaptors/Memory/src/TaskTable.cs index 43755017f..e3f1facef 100644 --- a/Adaptors/Memory/src/TaskTable.cs +++ b/Adaptors/Memory/src/TaskTable.cs @@ -81,9 +81,10 @@ public Task CreateTasks(IEnumerable tasks, public Task ReadTaskAsync(string taskId, CancellationToken cancellationToken = default) { - if (taskId2TaskData_.ContainsKey(taskId)) + if (taskId2TaskData_.TryGetValue(taskId, + out var value)) { - return Task.FromResult(taskId2TaskData_[taskId]); + return Task.FromResult(value); } throw new TaskNotFoundException($"Key '{taskId}' not found"); @@ -93,26 +94,21 @@ public Task ReadTaskAsync(string taskId, public Task IsTaskCancelledAsync(string taskId, CancellationToken cancellationToken = default) { - if (!taskId2TaskData_.ContainsKey(taskId)) + if (!taskId2TaskData_.TryGetValue(taskId, + out var value)) { throw new TaskNotFoundException($"Key '{taskId}' not found"); } - return Task.FromResult(taskId2TaskData_[taskId] - .Status is TaskStatus.Cancelling or TaskStatus.Cancelled); + return Task.FromResult(value.Status is TaskStatus.Cancelling or TaskStatus.Cancelled); } /// public Task StartTask(TaskData taskData, CancellationToken cancellationToken = default) { - if (!taskId2TaskData_.ContainsKey(taskData.TaskId)) - { - throw new TaskNotFoundException($"Key '{taskData.TaskId}' not found"); - } - taskId2TaskData_.AddOrUpdate(taskData.TaskId, - _ => throw new InvalidOperationException("The task does not exist."), + _ => throw new TaskNotFoundException($"Key '{taskData.TaskId}' not found"), (_, data) => data with { @@ -504,27 +500,4 @@ public Task Check(HealthCheckTag tag) => Task.FromResult(isInitialized_ ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy()); - - private bool UpdateTaskToSubmitted(string id) - { - var updated = false; - taskId2TaskData_.AddOrUpdate(id, - _ => throw new InvalidOperationException("The task does not exist."), - (_, - data) => - { - if (data.Status != TaskStatus.Creating) - { - return data; - } - - updated = true; - return data with - { - Status = TaskStatus.Submitted, - SubmittedDate = DateTime.UtcNow, - }; - }); - return updated; - } } diff --git a/Adaptors/Memory/tests/ArmoniK.Core.Adapters.Memory.Tests.csproj b/Adaptors/Memory/tests/ArmoniK.Core.Adapters.Memory.Tests.csproj index cb83986cc..1b20277cc 100644 --- a/Adaptors/Memory/tests/ArmoniK.Core.Adapters.Memory.Tests.csproj +++ b/Adaptors/Memory/tests/ArmoniK.Core.Adapters.Memory.Tests.csproj @@ -17,11 +17,11 @@ - + - + diff --git a/Adaptors/MongoDB/src/AuthenticationTable.cs b/Adaptors/MongoDB/src/AuthenticationTable.cs index 4898ce779..e5e791b05 100644 --- a/Adaptors/MongoDB/src/AuthenticationTable.cs +++ b/Adaptors/MongoDB/src/AuthenticationTable.cs @@ -168,7 +168,7 @@ await sessionProvider_.Init(cancellationToken) return (await GetIdentityFromPipelineAsync(sessionHandle, authCollection, GetAuthToIdentityPipeline(), - auth => auth.CN == cn && (auth.Fingerprint == fingerprint || auth.Fingerprint == null), + auth => auth.Cn == cn && (auth.Fingerprint == fingerprint || auth.Fingerprint == null), cancellationToken) .ConfigureAwait(false))?.ToUserAuthenticationResult(); } diff --git a/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs b/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs index c7dfc1b96..4519689e2 100644 --- a/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs +++ b/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs @@ -36,9 +36,8 @@ namespace ArmoniK.Core.Adapters.MongoDB.Common; public class MongoCollectionProvider : IInitializable, IAsyncInitialization> where TModelMapping : IMongoDataModelMapping, new() { - private bool isInitialized_; - private ILogger> logger_; - private IMongoCollection? mongoCollection_; + private bool isInitialized_; + private IMongoCollection? mongoCollection_; public MongoCollectionProvider(Options.MongoDB options, SessionProvider sessionProvider, @@ -52,8 +51,6 @@ public MongoCollectionProvider(Options.MongoDB options, $"{nameof(Options.MongoDB.DataRetention)} is not defined."); } - logger_ = logger; - Initialization = InitializeAsync(options, sessionProvider, mongoDatabase, @@ -66,24 +63,18 @@ public MongoCollectionProvider(Options.MongoDB options, /// public Task Check(HealthCheckTag tag) - { - switch (tag) - { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && mongoCollection_ is null - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + => tag switch + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && mongoCollection_ is null + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; /// public async Task Init(CancellationToken cancellationToken) diff --git a/Adaptors/MongoDB/src/Common/SessionProvider.cs b/Adaptors/MongoDB/src/Common/SessionProvider.cs index e3b0e937b..fbbc41599 100644 --- a/Adaptors/MongoDB/src/Common/SessionProvider.cs +++ b/Adaptors/MongoDB/src/Common/SessionProvider.cs @@ -42,24 +42,18 @@ public SessionProvider(IMongoClient client) => client_ = client; public Task Check(HealthCheckTag tag) - { - switch (tag) - { - case HealthCheckTag.Readiness: - case HealthCheckTag.Startup: - return Task.FromResult(clientSessionHandle_ is not null - ? HealthCheckResult.Healthy() - : HealthCheckResult.Degraded($"{nameof(clientSessionHandle_)} is still null")); - case HealthCheckTag.Liveness: - return Task.FromResult(clientSessionHandle_ is not null && client_.Cluster.Description.State == ClusterState.Connected - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Connection to MongoDB cluster dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + => tag switch + { + HealthCheckTag.Readiness or HealthCheckTag.Startup => Task.FromResult(clientSessionHandle_ is not null + ? HealthCheckResult.Healthy() + : HealthCheckResult.Degraded($"{nameof(clientSessionHandle_)} is still null")), + HealthCheckTag.Liveness => Task.FromResult(clientSessionHandle_ is not null && client_.Cluster.Description.State == ClusterState.Connected + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Connection to MongoDB cluster dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; public Task Init(CancellationToken cancellationToken) { diff --git a/Adaptors/MongoDB/src/IMongoQueryableExt.cs b/Adaptors/MongoDB/src/IMongoQueryableExt.cs index b877fde2d..1c28b046f 100644 --- a/Adaptors/MongoDB/src/IMongoQueryableExt.cs +++ b/Adaptors/MongoDB/src/IMongoQueryableExt.cs @@ -46,8 +46,8 @@ public static async IAsyncEnumerable ToAsyncEnumerable(this } - public static async IAsyncEnumerable ToAsyncEnumerable(this IFindFluent findFluent, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + public static async IAsyncEnumerable ToAsyncEnumerable(this IFindFluent findFluent, + [EnumeratorCancellation] CancellationToken cancellationToken = default) { var cursor = await findFluent.ToCursorAsync(cancellationToken) .ConfigureAwait(false); diff --git a/Adaptors/MongoDB/src/ObjectStorage.cs b/Adaptors/MongoDB/src/ObjectStorage.cs index 8abaa50a5..906561614 100644 --- a/Adaptors/MongoDB/src/ObjectStorage.cs +++ b/Adaptors/MongoDB/src/ObjectStorage.cs @@ -145,8 +145,7 @@ async IAsyncEnumerable IObjectStorage.GetValuesAsync(string .Where(odm => odm.Key == objectStorageName_ + key) .OrderBy(odm => odm.ChunkIdx) .Select(odm => odm.Chunk) - .ToAsyncEnumerable() - .WithCancellation(cancellationToken) + .ToAsyncEnumerable(cancellationToken) .ConfigureAwait(false)) { throwException = false; @@ -182,8 +181,7 @@ public async IAsyncEnumerable ListKeysAsync([EnumeratorCancellation] Can await foreach (var key in objectCollection.AsQueryable(sessionHandle) .Where(odm => odm.ChunkIdx == 0) .Select(odm => odm.Key) - .ToAsyncEnumerable() - .WithCancellation(cancellationToken) + .ToAsyncEnumerable(cancellationToken) .ConfigureAwait(false)) { yield return key; diff --git a/Adaptors/MongoDB/src/PartitionTable.cs b/Adaptors/MongoDB/src/PartitionTable.cs index 592b6374b..853450ebf 100644 --- a/Adaptors/MongoDB/src/PartitionTable.cs +++ b/Adaptors/MongoDB/src/PartitionTable.cs @@ -126,7 +126,7 @@ public IAsyncEnumerable GetPartitionWithAllocationAsync(Cancellat return taskCollection.AsQueryable(sessionHandle) .Where(tdm => tdm.PodMax > 0) - .ToAsyncEnumerable(); + .ToAsyncEnumerable(cancellationToken); } /// diff --git a/Adaptors/MongoDB/src/ResultTable.cs b/Adaptors/MongoDB/src/ResultTable.cs index e89de729f..3b0b64c32 100644 --- a/Adaptors/MongoDB/src/ResultTable.cs +++ b/Adaptors/MongoDB/src/ResultTable.cs @@ -355,7 +355,7 @@ public async Task SetTaskOwnership(string cancellationToken: cancellationToken) .ConfigureAwait(false); - if (res.ModifiedCount != requests.Count()) + if (res.ModifiedCount != requests.Count) { throw new ResultNotFoundException("One of the requested result was not found"); } @@ -450,7 +450,6 @@ public async IAsyncEnumerable ListResultsAsync(string await foreach (var result in resultCollection.Find(model => model.SessionId == sessionId) .Project(model => model.ResultId) .ToAsyncEnumerable(cancellationToken) - .WithCancellation(cancellationToken) .ConfigureAwait(false)) { yield return result; diff --git a/Adaptors/MongoDB/src/ServiceCollectionExt.cs b/Adaptors/MongoDB/src/ServiceCollectionExt.cs index f0f8c50fd..5d19dea50 100644 --- a/Adaptors/MongoDB/src/ServiceCollectionExt.cs +++ b/Adaptors/MongoDB/src/ServiceCollectionExt.cs @@ -221,12 +221,10 @@ public static IServiceCollection AddMongoClient(this IServiceCollection services /// /// Services /// Configuration - /// Logger /// Services [PublicAPI] public static IServiceCollection AddClientSubmitterAuthenticationStorage(this IServiceCollection services, - ConfigurationManager configuration, - ILogger logger) + ConfigurationManager configuration) { var components = configuration.GetSection(Components.SettingSection); if (components[nameof(Components.AuthenticationStorage)] == "ArmoniK.Adapters.MongoDB.AuthenticationTable") @@ -243,13 +241,11 @@ public static IServiceCollection AddClientSubmitterAuthenticationStorage(this IS /// /// Services /// Configuration - /// Logger /// Created authentication cache /// Services [PublicAPI] public static IServiceCollection AddClientSubmitterAuthServices(this IServiceCollection services, ConfigurationManager configuration, - ILogger logger, out AuthenticationCache authCache) { authCache = new AuthenticationCache(); diff --git a/Adaptors/MongoDB/src/SessionTable.cs b/Adaptors/MongoDB/src/SessionTable.cs index ec138edc6..7b24fda44 100644 --- a/Adaptors/MongoDB/src/SessionTable.cs +++ b/Adaptors/MongoDB/src/SessionTable.cs @@ -179,7 +179,9 @@ public async Task CancelSessionAsync(string sessionId, cancellationToken) .ConfigureAwait(false); +#pragma warning disable IDE0270 // null check can be simplified with a less readable approach if (resSession is null) +#pragma warning restore IDE0270 { throw new SessionNotFoundException($"No open session with key '{sessionId}' was found"); } diff --git a/Adaptors/MongoDB/src/Table/DataModel/Auth/AuthDataModelMapping.cs b/Adaptors/MongoDB/src/Table/DataModel/Auth/AuthDataModelMapping.cs index b870d7a35..0a659feb7 100644 --- a/Adaptors/MongoDB/src/Table/DataModel/Auth/AuthDataModelMapping.cs +++ b/Adaptors/MongoDB/src/Table/DataModel/Auth/AuthDataModelMapping.cs @@ -43,14 +43,14 @@ static AuthDataModelMapping() cm.MapProperty(nameof(AuthData.UserId)) .SetIsRequired(true) .SetSerializer(IdSerializer.Instance); - cm.MapProperty(nameof(AuthData.CN)) + cm.MapProperty(nameof(AuthData.Cn)) .SetIsRequired(true); cm.MapProperty(nameof(AuthData.Fingerprint)) .SetDefaultValue(BsonNull.Value); cm.SetIgnoreExtraElements(true); cm.MapCreator(model => new AuthData(model.AuthId, model.UserId, - model.CN, + model.Cn, model.Fingerprint)); }); } @@ -68,7 +68,7 @@ public async Task InitializeIndexesAsync(IClientSessionHandle sessionHandl var indexModels = new[] { IndexHelper.CreateUniqueIndex((IndexType.Descending, model => model.Fingerprint), - (IndexType.Ascending, model => model.CN)), + (IndexType.Ascending, model => model.Cn)), IndexHelper.CreateHashedIndex(model => model.Fingerprint), IndexHelper.CreateHashedIndex(model => model.UserId), }; diff --git a/Adaptors/MongoDB/src/Table/DataModel/Auth/PipelineIntermediates.cs b/Adaptors/MongoDB/src/Table/DataModel/Auth/PipelineIntermediates.cs index 814507c86..1459f0532 100644 --- a/Adaptors/MongoDB/src/Table/DataModel/Auth/PipelineIntermediates.cs +++ b/Adaptors/MongoDB/src/Table/DataModel/Auth/PipelineIntermediates.cs @@ -29,14 +29,14 @@ namespace ArmoniK.Core.Adapters.MongoDB.Table.DataModel.Auth; /// /// Certificate ID /// User ID -/// Common Name +/// Common Name /// Certificate Fingerprint /// List of users that have the id UserId [BsonIgnoreExtraElements] public record AuthDataAfterLookup([property: BsonId] ObjectId AuthId, ObjectId UserId, - string CN, + string Cn, string Fingerprint, UserData[] UserData); diff --git a/Adaptors/MongoDB/src/TaskTable.cs b/Adaptors/MongoDB/src/TaskTable.cs index 172d2a031..8de871b35 100644 --- a/Adaptors/MongoDB/src/TaskTable.cs +++ b/Adaptors/MongoDB/src/TaskTable.cs @@ -287,8 +287,7 @@ public async IAsyncEnumerable ListTasksAsync(TaskFilter await foreach (var taskId in taskCollection.AsQueryable(sessionHandle) .FilterQuery(filter) .Select(model => model.TaskId) - .ToAsyncEnumerable() - .WithCancellation(cancellationToken) + .ToAsyncEnumerable(cancellationToken) .ConfigureAwait(false)) { yield return taskId; diff --git a/Adaptors/MongoDB/tests/AuthenticationTableTest.cs b/Adaptors/MongoDB/tests/AuthenticationTableTest.cs index bd7328242..da3dea53e 100644 --- a/Adaptors/MongoDB/tests/AuthenticationTableTest.cs +++ b/Adaptors/MongoDB/tests/AuthenticationTableTest.cs @@ -29,12 +29,6 @@ namespace ArmoniK.Core.Adapters.MongoDB.Tests; public class AuthenticationTableTest : AuthenticationTableTestBase { - public override void TearDown() - { - tableProvider_?.Dispose(); - RunTests = false; - } - private MongoDatabaseProvider? tableProvider_; static AuthenticationTableTest() @@ -63,6 +57,12 @@ static AuthenticationTableTest() } } + public override void TearDown() + { + tableProvider_?.Dispose(); + RunTests = false; + } + public override void GetAuthSource() { tableProvider_ = new MongoDatabaseProvider(); diff --git a/Adaptors/MongoDB/tests/BsonSerializerTest.cs b/Adaptors/MongoDB/tests/BsonSerializerTest.cs index ab24cb656..31e4bd0fe 100644 --- a/Adaptors/MongoDB/tests/BsonSerializerTest.cs +++ b/Adaptors/MongoDB/tests/BsonSerializerTest.cs @@ -307,8 +307,8 @@ public void SerializeAuthDataModel() deserialized.AuthId); Assert.AreEqual(adm.UserId, deserialized.UserId); - Assert.AreEqual(adm.CN, - deserialized.CN); + Assert.AreEqual(adm.Cn, + deserialized.Cn); Assert.AreEqual(adm.Fingerprint, deserialized.Fingerprint); } diff --git a/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs b/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs index dd8693921..7c790156e 100644 --- a/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs +++ b/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs @@ -32,16 +32,16 @@ namespace ArmoniK.Core.Adapters.MongoDB.Tests; [TestFixture(TestOf = typeof(ExpressionsBuilders))] internal class ExpressionsBuildersFieldFilterExpressionTests { - private static readonly TaskOptions _taskOptions = new(new Dictionary(), - TimeSpan.Zero, - 0, - 0, - "part1", - "ApplicationName", - "ApplicationVersion", - "applicationNamespace", - "applicationService", - "engineType"); + private static readonly TaskOptions TaskOptions = new(new Dictionary(), + TimeSpan.Zero, + 0, + 0, + "part1", + "ApplicationName", + "ApplicationVersion", + "applicationNamespace", + "applicationService", + "engineType"); [Test] public void ShouldRecognizeSession() @@ -73,7 +73,7 @@ public void ShouldRecognizeSession() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -109,7 +109,7 @@ public void ShouldRejectOtherSession() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -146,7 +146,7 @@ public void ShouldExcludeSession() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -183,7 +183,7 @@ public void ShouldIncludeOtherSession() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -220,7 +220,7 @@ public void ShouldRecognizeStatus() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -257,7 +257,7 @@ public void ShouldExcludeStatus() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -294,7 +294,7 @@ public void ShouldRecognizeMultipleStatus() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -332,7 +332,7 @@ public void ShouldExcludeMultipleStatus() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -368,7 +368,7 @@ public void ShouldRejectOtherStatus() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -405,7 +405,7 @@ public void ShouldIncludeOtherStatus() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -442,7 +442,7 @@ public void ShouldRejectOtherMultipleStatus() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -480,7 +480,7 @@ public void ShouldIncludeOtherMultipleStatus() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -516,7 +516,7 @@ public void ShouldRecognizeTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -553,7 +553,7 @@ public void ShouldExcludeTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -590,7 +590,7 @@ public void ShouldRecognizeMultipleTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -628,7 +628,7 @@ public void ShouldExcludeMultipleTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -664,7 +664,7 @@ public void ShouldRejectOtherTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -701,7 +701,7 @@ public void ShouldIncludeOtherTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -738,7 +738,7 @@ public void ShouldRejectOtherMultipleTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -776,7 +776,7 @@ public void ShouldIncludeOtherMultipleTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); diff --git a/Adaptors/MongoDB/tests/IndexTest.cs b/Adaptors/MongoDB/tests/IndexTest.cs index e8206fa8d..6646fa143 100644 --- a/Adaptors/MongoDB/tests/IndexTest.cs +++ b/Adaptors/MongoDB/tests/IndexTest.cs @@ -46,8 +46,10 @@ public void StartUp() var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 }; runner_ = MongoRunner.Run(options); @@ -237,10 +239,10 @@ public void GenericIndexCreationShouldSucceed() { IndexHelper.CreateIndex(IndexType.Hashed, model => model.Fingerprint), - IndexHelper.CreateUniqueIndex((IndexType.Ascending, model => model.CN), + IndexHelper.CreateUniqueIndex((IndexType.Ascending, model => model.Cn), (IndexType.Descending, model => model.Fingerprint)), IndexHelper.CreateIndex((IndexType.Hashed, model => model.UserId)), - IndexHelper.CreateUniqueIndex((IndexType.Text, model => model.CN)), + IndexHelper.CreateUniqueIndex((IndexType.Text, model => model.Cn)), }; collection.Indexes.CreateMany(indexModels); diff --git a/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs b/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs index 93d7e121a..cdc85b977 100644 --- a/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs +++ b/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs @@ -55,9 +55,11 @@ public MongoDatabaseProvider(bool useSingleNodeReplicaSet var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = useSingleNodeReplicaSet, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), - ReplicaSetSetupTimeout = TimeSpan.FromSeconds(30), +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 + ReplicaSetSetupTimeout = TimeSpan.FromSeconds(30), }; runner_ = MongoRunner.Run(options); @@ -101,8 +103,7 @@ public MongoDatabaseProvider(bool useSingleNodeReplicaSet var serviceCollection = new ServiceCollection(); serviceCollection.AddMongoStorages(configuration, logger); - serviceCollection.AddClientSubmitterAuthenticationStorage(configuration, - logger); + serviceCollection.AddClientSubmitterAuthenticationStorage(configuration); serviceCollection.AddSingleton(ActivitySource); serviceCollection.AddTransient(_ => client); diff --git a/Adaptors/MongoDB/tests/ObjectStorageTests.cs b/Adaptors/MongoDB/tests/ObjectStorageTests.cs index 848c671ec..bb1ca1a83 100644 --- a/Adaptors/MongoDB/tests/ObjectStorageTests.cs +++ b/Adaptors/MongoDB/tests/ObjectStorageTests.cs @@ -36,7 +36,7 @@ public override void TearDown() private MongoDatabaseProvider? tableProvider_; - public override void GetObjectStorageInstance() + protected override void GetObjectStorageInstance() { tableProvider_ = new MongoDatabaseProvider(serviceConfigurator: collection => collection.AddSingleton()); var provider = tableProvider_.GetServiceProvider(); diff --git a/Adaptors/MongoDB/tests/SessionProviderTests.cs b/Adaptors/MongoDB/tests/SessionProviderTests.cs index 4e9501022..7069a188c 100644 --- a/Adaptors/MongoDB/tests/SessionProviderTests.cs +++ b/Adaptors/MongoDB/tests/SessionProviderTests.cs @@ -57,8 +57,10 @@ public void SetUp() var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 }; runner_ = MongoRunner.Run(options); diff --git a/Adaptors/RabbitMQ/src/ConnectionRabbit.cs b/Adaptors/RabbitMQ/src/ConnectionRabbit.cs index c4c5b11f7..ec24043c3 100644 --- a/Adaptors/RabbitMQ/src/ConnectionRabbit.cs +++ b/Adaptors/RabbitMQ/src/ConnectionRabbit.cs @@ -60,24 +60,18 @@ public async Task Init(CancellationToken cancellationToken = default) => await connectionTask_; public Task Check(HealthCheckTag tag) - { - switch (tag) - { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} is not yet initialized.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && Connection is not null && Connection.IsOpen && Channel is not null && Channel.IsOpen - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} not initialized or connection dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + => tag switch + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} is not yet initialized.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Connection is not null && Connection.IsOpen && Channel is not null && Channel.IsOpen + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; public void Dispose() { @@ -134,16 +128,14 @@ private async Task InitTask(ConnectionRabbit conn, try { conn.Connection = factory.CreateConnection(); - conn.Connection.ConnectionShutdown += (obj, - ea) => OnShutDown(obj, - ea, + conn.Connection.ConnectionShutdown += (_, + ea) => OnShutDown(ea, "Connection", logger_); Channel = conn.Connection.CreateModel(); - Channel.ModelShutdown += (obj, - ea) => OnShutDown(obj, - ea, + Channel.ModelShutdown += (_, + ea) => OnShutDown(ea, "Channel", logger_); break; @@ -166,18 +158,19 @@ await Task.Delay(1000 * retry, conn.isInitialized_ = true; } - private static void OnShutDown(object? obj, - ShutdownEventArgs ea, + private static void OnShutDown(ShutdownEventArgs ea, string model, ILogger logger) { if (ea.Cause is null) { - logger.LogInformation($"RabbitMQ {model} closed with no error"); + logger.LogInformation("RabbitMQ {model} closed with no error", + model); } else { - logger.LogWarning($"RabbitMQ {model} closed with error: {0}", + logger.LogWarning("RabbitMQ {model} closed with error: {error}", + model, ea.Cause); } } diff --git a/Adaptors/RabbitMQ/src/PullQueueStorage.cs b/Adaptors/RabbitMQ/src/PullQueueStorage.cs index c3e82e712..183876da5 100644 --- a/Adaptors/RabbitMQ/src/PullQueueStorage.cs +++ b/Adaptors/RabbitMQ/src/PullQueueStorage.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Runtime.CompilerServices; +using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -149,13 +149,13 @@ Task Subscriber(object? model, queueMessageHandlers_.Enqueue(new QueueMessageHandler(ConnectionRabbit.Channel!, eventArgs, message, - logger_, cancellationToken)); return Task.CompletedTask; } consumer.Received += Subscriber; + ConnectionRabbit.Channel!.BasicConsume(pullQueue.QueueName, false, consumer); @@ -163,31 +163,29 @@ Task Subscriber(object? model, } } -#pragma warning disable CS1998 - public async IAsyncEnumerable PullMessagesAsync(int nbMessages, - [EnumeratorCancellation] CancellationToken cancellationToken = default) -#pragma warning restore CS1998 + public IAsyncEnumerable PullMessagesAsync(int nbMessages, + CancellationToken cancellationToken = default) { - var nbPulledMessage = 0; - if (!IsInitialized) { throw new InvalidOperationException($"{nameof(PullQueueStorage)} should be initialized before calling this method."); } cancellationToken.ThrowIfCancellationRequested(); - while (nbPulledMessage < nbMessages) - { - if (!queueMessageHandlers_!.TryDequeue(out var qmh)) - { - continue; - } - - nbPulledMessage++; - // Pass the cancellation token to the pulled handler - qmh!.CancellationToken = cancellationToken; - yield return qmh; - } + // using ToAsyncEnumerable avoids using a needless async operator + return Enumerable.Repeat(0, + nbMessages) + .Select(_ => + { + IQueueMessageHandler? qmh; + do + { + cancellationToken.ThrowIfCancellationRequested(); + } while (!queueMessageHandlers_!.TryDequeue(out qmh)); + + return qmh; + }) + .ToAsyncEnumerable(); } } diff --git a/Adaptors/RabbitMQ/src/QueueMessageHandler.cs b/Adaptors/RabbitMQ/src/QueueMessageHandler.cs index 12cc574e1..111f6eee1 100644 --- a/Adaptors/RabbitMQ/src/QueueMessageHandler.cs +++ b/Adaptors/RabbitMQ/src/QueueMessageHandler.cs @@ -21,8 +21,6 @@ using ArmoniK.Core.Base; -using Microsoft.Extensions.Logging; - using RabbitMQ.Client; using RabbitMQ.Client.Events; @@ -32,15 +30,12 @@ public class QueueMessageHandler : IQueueMessageHandler { private readonly IModel channel_; private readonly BasicDeliverEventArgs deliverEvent_; - private readonly ILogger logger_; public QueueMessageHandler(IModel channel, BasicDeliverEventArgs deliverEvent, string taskId, - ILogger logger, CancellationToken cancellationToken) { - logger_ = logger; TaskId = taskId; deliverEvent_ = deliverEvent; CancellationToken = cancellationToken; diff --git a/Adaptors/Redis/src/ObjectStorage.cs b/Adaptors/Redis/src/ObjectStorage.cs index acaa6f628..c9db37674 100644 --- a/Adaptors/Redis/src/ObjectStorage.cs +++ b/Adaptors/Redis/src/ObjectStorage.cs @@ -73,24 +73,18 @@ await redis_.PingAsync() /// public Task Check(HealthCheckTag tag) - { - switch (tag) - { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Redis not initialized yet.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && redis_.Multiplexer.IsConnected - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Redis not initialized or connection dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + => tag switch + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Redis not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && redis_.Multiplexer.IsConnected + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Redis not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; /// public async Task AddOrUpdateAsync(string key, diff --git a/Adaptors/Redis/tests/ArmoniK.Core.Adapters.Redis.Tests.csproj b/Adaptors/Redis/tests/ArmoniK.Core.Adapters.Redis.Tests.csproj index 782c01c19..663af2339 100644 --- a/Adaptors/Redis/tests/ArmoniK.Core.Adapters.Redis.Tests.csproj +++ b/Adaptors/Redis/tests/ArmoniK.Core.Adapters.Redis.Tests.csproj @@ -11,11 +11,11 @@ - + - + diff --git a/Adaptors/Redis/tests/ObjectStorageTests.cs b/Adaptors/Redis/tests/ObjectStorageTests.cs index cf3099547..928fa45f7 100644 --- a/Adaptors/Redis/tests/ObjectStorageTests.cs +++ b/Adaptors/Redis/tests/ObjectStorageTests.cs @@ -45,7 +45,7 @@ public override void TearDown() private RedisInside.Redis? redis_; - public override void GetObjectStorageInstance() + protected override void GetObjectStorageInstance() { redis_ = new RedisInside.Redis(configuration => configuration.Port(Random.Shared.Next(1000, 2000))); diff --git a/Adaptors/S3/src/ObjectStorage.cs b/Adaptors/S3/src/ObjectStorage.cs index 09ab4a18d..23ace2a3b 100644 --- a/Adaptors/S3/src/ObjectStorage.cs +++ b/Adaptors/S3/src/ObjectStorage.cs @@ -76,24 +76,18 @@ await AmazonS3Util.DoesS3BucketExistV2Async(s3Client_, /// public Task Check(HealthCheckTag tag) - { - switch (tag) - { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("S3 not initialized yet.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("S3 not initialized or connection dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + => tag switch + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("S3 not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("S3 not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; /// public async Task AddOrUpdateAsync(string key, @@ -154,8 +148,7 @@ public async IAsyncEnumerable GetValuesAsync(string foreach (var chunkTask in Enumerable.Range(0, valuesCount) .Select(index => s3Client_.StringByteGetAsync(bucketName_, - $"{objectStorageName_}{key}_{index}", - logger_)) + $"{objectStorageName_}{key}_{index}")) .ToList()) { yield return (await chunkTask.ConfigureAwait(false))!; @@ -169,10 +162,12 @@ public async Task TryDeleteAsync(string key, using var _ = logger_.LogFunction(objectStorageName_ + key); var value = await s3Client_.StringGetValueAsync(bucketName_, $"{objectStorageName_}{key}_count", - logger_) + cancellationToken) .ConfigureAwait(false); +#pragma warning disable IDE0270 // null check can be simplifier but with a less readable approach if (value == null) +#pragma warning restore IDE0270 { throw new ObjectDataNotFoundException("Key not found"); } @@ -256,10 +251,9 @@ internal static Task WriteStringAsync(this AmazonS3Client s3C return s3Client.PutObjectAsync(requestCount); } - internal static async Task StringByteGetAsync(this AmazonS3Client s3Client, - string bucketName, - string key, - ILogger logger) + internal static async Task StringByteGetAsync(this AmazonS3Client s3Client, + string bucketName, + string key) { var request = new GetObjectRequest { @@ -274,21 +268,21 @@ internal static async Task StringByteGetAsync(this AmazonS3Client s3C return fileContent; } - internal static async Task StringGetValueAsync(this AmazonS3Client s3Client, - string bucketName, - string key, - ILogger logger) + internal static async Task StringGetValueAsync(this AmazonS3Client s3Client, + string bucketName, + string key, + CancellationToken cancellationToken = default) { var response = await s3Client.GetObjectAsync(bucketName, - key); + key, + cancellationToken); // Get the data from the response stream await using var responseStream = response.ResponseStream; var retrievedData = new byte[responseStream.Length]; _ = await responseStream.ReadAsync(retrievedData, - 0, - retrievedData.Length); + cancellationToken); return Encoding.UTF8.GetString(retrievedData); } } diff --git a/Adaptors/S3/tests/ObjectStorageTests.cs b/Adaptors/S3/tests/ObjectStorageTests.cs index d2aa7376a..261a53643 100644 --- a/Adaptors/S3/tests/ObjectStorageTests.cs +++ b/Adaptors/S3/tests/ObjectStorageTests.cs @@ -35,7 +35,7 @@ public override void TearDown() RunTests = false; } - public override void GetObjectStorageInstance() + protected override void GetObjectStorageInstance() { Dictionary minimalConfig = new() { diff --git a/Base/src/IQueueMessageHandler.cs b/Base/src/IQueueMessageHandler.cs index 5c81bdbfe..387b97f11 100644 --- a/Base/src/IQueueMessageHandler.cs +++ b/Base/src/IQueueMessageHandler.cs @@ -20,26 +20,34 @@ namespace ArmoniK.Core.Base; -public enum QueueMessageStatus -{ - Waiting, - Failed, - Running, - Postponed, - Processed, - Cancelled, - Poisonous, -} - +/// +/// Interface to handle queue messages lifecycle. +/// public interface IQueueMessageHandler : IAsyncDisposable { + /// + /// Used to signal that the message ownership has been lost + /// + [Obsolete("ArmoniK now manages loss of link with the queue")] CancellationToken CancellationToken { get; set; } + /// + /// Id of the message + /// string MessageId { get; } + /// + /// Task Id contained in the message + /// string TaskId { get; } + /// + /// Status of the message. Used when the handler is disposed to notify the queue. + /// QueueMessageStatus Status { get; set; } + /// + /// Date of reception of the message + /// DateTime ReceptionDateTime { get; init; } } diff --git a/Base/src/QueueMessageStatus.cs b/Base/src/QueueMessageStatus.cs new file mode 100644 index 000000000..0b8d64ebb --- /dev/null +++ b/Base/src/QueueMessageStatus.cs @@ -0,0 +1,59 @@ +// This file is part of the ArmoniK project +// +// Copyright (C) ANEO, 2021-2023. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +namespace ArmoniK.Core.Base; + +/// +/// Represents the status of a queue message +/// +public enum QueueMessageStatus +{ + /// + /// Message is waiting for being processed. + /// + Waiting, + + /// + /// Message processing has failed. The message should be put back at the begin of the queue. + /// + Failed, + + /// + /// The message is being processed. + /// + Running, + + /// + /// Task is not ready to be processed. The message should be put at the end of the queue. + /// + Postponed, + + /// + /// The message has been processed. It can safely be removed from the queue. + /// + Processed, + + /// + /// The message processing has been cancelled. the message can safely be removed from the queue. + /// + Cancelled, + + /// + /// Message has been retried too many times and is considered as poisonous for the queue + /// + Poisonous, +} diff --git a/Common/src/Auth/Authentication/AuthData.cs b/Common/src/Auth/Authentication/AuthData.cs index d302ddfe2..70e6adaf3 100644 --- a/Common/src/Auth/Authentication/AuthData.cs +++ b/Common/src/Auth/Authentication/AuthData.cs @@ -22,12 +22,12 @@ namespace ArmoniK.Core.Common.Auth.Authentication; /// /// Unique Id of the entry /// Id of the user this entry refers to -/// Common Name of the certificate(s) +/// Common Name of the certificate(s) /// /// fingerprint of the certificate. If null, this entry matches with every certificates /// matching the Common Name /// public record AuthData(string AuthId, string UserId, - string CN, + string Cn, string? Fingerprint); diff --git a/Common/src/Auth/Authentication/AuthenticationCache.cs b/Common/src/Auth/Authentication/AuthenticationCache.cs index 3f683f3fb..ef28bfd1d 100644 --- a/Common/src/Auth/Authentication/AuthenticationCache.cs +++ b/Common/src/Auth/Authentication/AuthenticationCache.cs @@ -42,7 +42,7 @@ public AuthenticationCacheKey(string connectionId, string? impersonateUsername = "") { ConnectionId = connectionId; - CN = cn ?? ""; + Cn = cn ?? ""; Fingerprint = fingerprint ?? ""; ImpersonateId = impersonateId ?? ""; ImpersonateUsername = impersonateUsername ?? ""; @@ -56,7 +56,7 @@ public AuthenticationCacheKey(string connectionId, /// /// Certificate common name /// - public string CN { get; } + public string Cn { get; } /// /// Certificate fingerprint @@ -87,7 +87,7 @@ public bool Equals(AuthenticationCacheKey? other) return true; } - return ConnectionId == other.ConnectionId && CN == other.CN && Fingerprint == other.Fingerprint && ImpersonateId == other.ImpersonateId && + return ConnectionId == other.ConnectionId && Cn == other.Cn && Fingerprint == other.Fingerprint && ImpersonateId == other.ImpersonateId && ImpersonateUsername == other.ImpersonateUsername; } @@ -111,7 +111,7 @@ public override bool Equals(object? obj) /// public override int GetHashCode() => HashCode.Combine(ConnectionId, - CN, + Cn, Fingerprint, ImpersonateId, ImpersonateUsername); diff --git a/Common/src/Auth/Authentication/Authenticator.cs b/Common/src/Auth/Authentication/Authenticator.cs index 4aa5beb70..3738c8461 100644 --- a/Common/src/Auth/Authentication/Authenticator.cs +++ b/Common/src/Auth/Authentication/Authenticator.cs @@ -211,7 +211,9 @@ protected override async Task HandleAuthenticateAsync() var identity = cache_.Get(cacheKey); if (identity?.Identity is not null) { - logger_.LogInformation($"Found authenticated user {identity.Identity.Name} in cache. Authentication hashkey : {keyHash}."); + logger_.LogInformation("Found authenticated user {username} in cache. Authentication hashkey : {keyHash}.", + identity.Identity.Name, + keyHash); return AuthenticateResult.Success(new AuthenticationTicket(identity, SchemeName)); } @@ -246,7 +248,12 @@ protected override async Task HandleAuthenticateAsync() impersonationId, impersonationUsername) .ConfigureAwait(false); - logger_.LogInformation($"User with id {(prevIdentity.Identity as UserIdentity)!.UserId} and name {(prevIdentity.Identity as UserIdentity)!.UserName} impersonated the user with id {(identity.Identity as UserIdentity)!.UserId} and name {(identity.Identity as UserIdentity)!.UserName}. Authentication key : {keyHash}"); + logger_.LogInformation("User with id {userId} and name {userName} impersonated the user with id {impersonatedId} and name {impersonatedName}. Authentication key : {keyHash}", + (prevIdentity.Identity as UserIdentity)!.UserId, + (prevIdentity.Identity as UserIdentity)!.UserName, + (identity.Identity as UserIdentity)!.UserId, + (identity.Identity as UserIdentity)!.UserName, + keyHash); } catch (AuthenticationException e) { diff --git a/Common/src/Pollster/AgentHandler.cs b/Common/src/Pollster/AgentHandler.cs index f24852fba..0eb9a11e7 100644 --- a/Common/src/Pollster/AgentHandler.cs +++ b/Common/src/Pollster/AgentHandler.cs @@ -42,7 +42,7 @@ namespace ArmoniK.Core.Common.Pollster; /// /// Represents the handler that will provide servers to process requests from worker /// -public class AgentHandler : IAgentHandler, IAsyncDisposable +public sealed class AgentHandler : IAgentHandler, IAsyncDisposable { private readonly WebApplication app_; private readonly ComputePlane computePlaneOptions_; @@ -86,7 +86,8 @@ public AgentHandler(LoggerInit loggerInit, { if (computePlaneOptions.AgentChannel?.Address == null) { - throw new ArgumentNullException(nameof(computePlaneOptions.AgentChannel)); + throw new ArgumentNullException(nameof(computePlaneOptions), + $"{nameof(computePlaneOptions.AgentChannel)} is null"); } logger.LogDebug("Agent address is {address}", diff --git a/Common/src/Pollster/Pollster.cs b/Common/src/Pollster/Pollster.cs index 868197346..493987c6c 100644 --- a/Common/src/Pollster/Pollster.cs +++ b/Common/src/Pollster/Pollster.cs @@ -249,8 +249,7 @@ void RecordError(Exception e) var messages = pullQueueStorage_.PullMessagesAsync(messageBatchSize_, cancellationToken); - await foreach (var message in messages.WithCancellation(cancellationToken) - .ConfigureAwait(false)) + await foreach (var message in messages.ConfigureAwait(false)) { using var scopedLogger = logger_.BeginNamedScope("Prefetch messageHandler", ("messageHandler", message.MessageId), diff --git a/Common/src/Pollster/TaskHandler.cs b/Common/src/Pollster/TaskHandler.cs index d00311a4e..7d0b1b1dd 100644 --- a/Common/src/Pollster/TaskHandler.cs +++ b/Common/src/Pollster/TaskHandler.cs @@ -41,7 +41,7 @@ namespace ArmoniK.Core.Common.Pollster; -public class TaskHandler : IAsyncDisposable +public sealed class TaskHandler : IAsyncDisposable { private readonly ActivitySource activitySource_; private readonly IAgentHandler agentHandler_; @@ -181,13 +181,13 @@ public async Task AcquireTask() } /* - * Check preconditions: - * - Session is not cancelled - * - Task is not cancelled - * - Task status is OK - * - Dependencies have been checked - * - Max number of retries has not been reached - */ + * Check preconditions: + * - Session is not cancelled + * - Task is not cancelled + * - Task status is OK + * - Dependencies have been checked + * - Max number of retries has not been reached + */ logger_.LogDebug("Handling the task status ({status})", taskData_.Status); @@ -629,10 +629,16 @@ private async Task HandleErrorInternalAsync(Exception e, if (cancellationToken.IsCancellationRequested || (requeueIfUnavailable && isWorkerDown)) { - logger_.LogWarning(e, - cancellationToken.IsCancellationRequested - ? "Cancellation triggered, task cancelled here and re executed elsewhere" - : "Worker not available, task cancelled here and re executed elsewhere"); + if (cancellationToken.IsCancellationRequested) + { + logger_.LogWarning(e, + "Cancellation triggered, task cancelled here and re executed elsewhere"); + } + else + { + logger_.LogWarning(e, + "Worker not available, task cancelled here and re executed elsewhere"); + } await taskTable_.ReleaseTask(taskData, CancellationToken.None) @@ -642,9 +648,10 @@ await taskTable_.ReleaseTask(taskData, else { logger_.LogError(e, + "Error during task execution: {Decision}", resubmit - ? "Error during task execution, retrying task" - : "Error during task execution, cancelling task"); + ? "retrying task" + : "cancelling task"); await submitter_.CompleteTaskAsync(taskData, resubmit, @@ -657,6 +664,8 @@ await submitter_.CompleteTaskAsync(taskData, }, CancellationToken.None) .ConfigureAwait(false); + + messageHandler_.Status = resubmit ? QueueMessageStatus.Cancelled : QueueMessageStatus.Processed; diff --git a/Common/src/StateMachines/UmlMermaidGraphStyle.cs b/Common/src/StateMachines/UmlMermaidGraphStyle.cs index 3f60c0c8e..292c2df11 100644 --- a/Common/src/StateMachines/UmlMermaidGraphStyle.cs +++ b/Common/src/StateMachines/UmlMermaidGraphStyle.cs @@ -85,7 +85,7 @@ public override string FormatOneTransition(string sourceNodeName, { if (bld.Length > 0) { - bld.Append(" "); + bld.Append(' '); } bld.Append(info); diff --git a/Common/src/Stream/Worker/WorkerStreamHandler.cs b/Common/src/Stream/Worker/WorkerStreamHandler.cs index 021361744..a20d308cd 100644 --- a/Common/src/Stream/Worker/WorkerStreamHandler.cs +++ b/Common/src/Stream/Worker/WorkerStreamHandler.cs @@ -115,7 +115,7 @@ await Task.Delay(optionsInitWorker_.WorkerCheckDelay * retry, var e = new ArmoniKException("Could not get grpc channel"); logger_.LogError(e, - string.Empty); + "Could not get grpc channel"); throw e; } diff --git a/Common/src/Utils/LocalIPv4.cs b/Common/src/Utils/LocalIPv4.cs index 1a66c4c5c..5d1aa110c 100644 --- a/Common/src/Utils/LocalIPv4.cs +++ b/Common/src/Utils/LocalIPv4.cs @@ -40,7 +40,7 @@ public class LocalIPv4 /// public static string GetLocalIPv4(NetworkInterfaceType type) { - var output = ""; + var output = string.Empty; foreach (var item in NetworkInterface.GetAllNetworkInterfaces()) { if (item.NetworkInterfaceType == type && item.OperationalStatus == OperationalStatus.Up) @@ -56,7 +56,7 @@ public static string GetLocalIPv4(NetworkInterfaceType type) } } - if (output == "") + if (string.IsNullOrEmpty(output)) { throw new ArmoniKException("No local IPv4 found"); } diff --git a/Common/src/Utils/LoggerInit.cs b/Common/src/Utils/LoggerInit.cs index 67b5d2808..348d4ca7d 100644 --- a/Common/src/Utils/LoggerInit.cs +++ b/Common/src/Utils/LoggerInit.cs @@ -38,7 +38,7 @@ public LoggerInit(IConfiguration configuration) .Enrich.FromLogContext() .Enrich.WithProperty("CoreVersion", typeof(LoggerInit).Assembly.GetName() - .Version) + .Version?.ToString() ?? "Unknown") .CreateLogger(); logger_ = LoggerFactory.Create(builder => builder.AddSerilog(loggerConfiguration_)) diff --git a/Common/src/gRPC/EnumFieldExt.cs b/Common/src/gRPC/EnumFieldExt.cs index bbc295411..ef9a4b09a 100644 --- a/Common/src/gRPC/EnumFieldExt.cs +++ b/Common/src/gRPC/EnumFieldExt.cs @@ -76,8 +76,8 @@ public static class EnumFieldExt TaskSummaryEnumField.ReceivedAt => data => data.ReceptionDate, TaskSummaryEnumField.AcquiredAt => data => data.AcquisitionDate, TaskSummaryEnumField.Error => data => data.Output.Error, - TaskSummaryEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + TaskSummaryEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; @@ -100,8 +100,8 @@ public static class EnumFieldExt TaskOptionEnumField.ApplicationNamespace => data => data.Options.ApplicationNamespace, TaskOptionEnumField.ApplicationService => data => data.Options.ApplicationService, TaskOptionEnumField.EngineType => data => data.Options.EngineType, - TaskOptionEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + TaskOptionEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -120,9 +120,9 @@ public static class EnumFieldExt SessionRawEnumField.Options => session => session.Options, SessionRawEnumField.CreatedAt => session => session.CreationDate, SessionRawEnumField.CancelledAt => session => session.CancellationDate, - SessionRawEnumField.Duration => throw new ArgumentOutOfRangeException(), - SessionRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + SessionRawEnumField.Duration => throw new ArgumentOutOfRangeException(nameof(enumField)), + SessionRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -144,8 +144,8 @@ public static class EnumFieldExt Api.gRPC.V1.Sessions.TaskOptionEnumField.ApplicationNamespace => data => data.Options.ApplicationNamespace, Api.gRPC.V1.Sessions.TaskOptionEnumField.ApplicationService => data => data.Options.ApplicationService, Api.gRPC.V1.Sessions.TaskOptionEnumField.EngineType => data => data.Options.EngineType, - Api.gRPC.V1.Sessions.TaskOptionEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + Api.gRPC.V1.Sessions.TaskOptionEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -174,9 +174,9 @@ public static class EnumFieldExt ResultRawEnumField.Status => result => result.Status, ResultRawEnumField.CreatedAt => result => result.CreationDate, ResultRawEnumField.ResultId => result => result.ResultId, - ResultRawEnumField.CompletedAt => throw new ArgumentOutOfRangeException(), - ResultRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + ResultRawEnumField.CompletedAt => throw new ArgumentOutOfRangeException(nameof(enumField)), + ResultRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -195,8 +195,8 @@ public static class EnumFieldExt PartitionRawEnumField.PodMax => partitionData => partitionData.PodMax, PartitionRawEnumField.PreemptionPercentage => partitionData => partitionData.PreemptionPercentage, PartitionRawEnumField.Priority => partitionData => partitionData.Priority, - PartitionRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + PartitionRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -213,7 +213,7 @@ public static class EnumFieldExt ApplicationRawEnumField.Version => taskData => taskData.Options.ApplicationVersion, ApplicationRawEnumField.Namespace => taskData => taskData.Options.ApplicationNamespace, ApplicationRawEnumField.Service => taskData => taskData.Options.ApplicationService, - ApplicationRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + ApplicationRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; } diff --git a/Common/src/gRPC/FilterRangeExt.cs b/Common/src/gRPC/FilterRangeExt.cs index f02cd304a..0a6f12a2e 100644 --- a/Common/src/gRPC/FilterRangeExt.cs +++ b/Common/src/gRPC/FilterRangeExt.cs @@ -51,7 +51,7 @@ public static Expression> ToFilter(this FilterStatusOp FilterStatusOperator.NotEqual => ExpressionBuilders.MakeBinary(field, value, ExpressionType.NotEqual), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; /// @@ -87,7 +87,7 @@ public static Expression> ToFilter(this FilterDateOperator FilterDateOperator.NotEqual => ExpressionBuilders.MakeBinary(field, value, ExpressionType.NotEqual), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; @@ -124,7 +124,7 @@ public static Expression> ToFilter(this FilterNumberOperator FilterNumberOperator.GreaterThan => ExpressionBuilders.MakeBinary(field, value, ExpressionType.GreaterThan), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; @@ -162,7 +162,7 @@ public static Expression> ToFilter(this FilterStringOperator FilterStringOperator.EndsWith => ExpressionBuilders.MakeCallString(field, value, nameof(string.EndsWith)), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; /// @@ -189,7 +189,7 @@ public static Expression> ToFilter(this FilterArrayOperator typeof(Enumerable), nameof(Enumerable.Contains), true), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; /// @@ -210,6 +210,6 @@ public static Expression> ToFilter(this FilterBooleanOperator FilterBooleanOperator.Is => ExpressionBuilders.MakeBinary(field, value, ExpressionType.Equal), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; } diff --git a/Common/src/gRPC/ListApplicationsRequestExt.cs b/Common/src/gRPC/ListApplicationsRequestExt.cs index 08a8323ba..618c2df94 100644 --- a/Common/src/gRPC/ListApplicationsRequestExt.cs +++ b/Common/src/gRPC/ListApplicationsRequestExt.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; @@ -34,6 +35,9 @@ public static class ListApplicationsRequestExt /// The that access the field from the object /// /// the given message is not recognized + [SuppressMessage("Style", + "IDE0066:Convert switch statement to expression", + Justification = "Readibility with nested switch")] public static Expression> ToField(this ApplicationField field) { switch (field.FieldCase) @@ -45,13 +49,13 @@ public static class ListApplicationsRequestExt ApplicationRawEnumField.Version => application => application.Version, ApplicationRawEnumField.Namespace => application => application.Namespace, ApplicationRawEnumField.Service => application => application.Service, - ApplicationRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + ApplicationRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(field)), + _ => throw new ArgumentOutOfRangeException(nameof(field)), }; case ApplicationField.FieldOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(field)); } } @@ -63,6 +67,9 @@ public static class ListApplicationsRequestExt /// The that represents the filter conditions /// /// the given message is not recognized + [SuppressMessage("Style", + "IDE0066:Convert switch statement to expression", + Justification = "Readibility with nested switch")] public static Expression> ToApplicationFilter(this Filters filters) { Expression> expr = data => false; @@ -88,7 +95,7 @@ public static Expression> ToApplicationFilter(this Filters break; case FilterField.ValueConditionOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(filters)); } } diff --git a/Common/src/gRPC/ListPartitionsRequestExt.cs b/Common/src/gRPC/ListPartitionsRequestExt.cs index fd69ddad3..383039c61 100644 --- a/Common/src/gRPC/ListPartitionsRequestExt.cs +++ b/Common/src/gRPC/ListPartitionsRequestExt.cs @@ -36,24 +36,18 @@ public static class ListPartitionsRequestExt /// /// the given message is not recognized public static Expression> ToField(this ListPartitionsRequest.Types.Sort sort) - { - switch (sort.Field.FieldCase) - { - case PartitionField.FieldOneofCase.PartitionRawField: - return sort.Field.PartitionRawField.Field.ToField(); - - case PartitionField.FieldOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } - } + => sort.Field.FieldCase switch + { + PartitionField.FieldOneofCase.PartitionRawField => sort.Field.PartitionRawField.Field.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this PartitionField taskField) => taskField.FieldCase switch { - PartitionField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(), + PartitionField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(nameof(taskField)), PartitionField.FieldOneofCase.PartitionRawField => taskField.PartitionRawField.Field.ToField(), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(taskField)), }; /// @@ -78,28 +72,21 @@ public static Expression> ToPartitionFilter(this Filte Expression> exprAnd = data => true; foreach (var filterField in filtersAnd.And) { - switch (filterField.ValueConditionCase) - { - case FilterField.ValueConditionOneofCase.FilterString: - exprAnd = exprAnd.ExpressionAnd(filterField.FilterString.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterString.Value)); - break; - case FilterField.ValueConditionOneofCase.FilterNumber: - exprAnd = exprAnd.ExpressionAnd(filterField.FilterNumber.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterNumber.Value)); - break; - case FilterField.ValueConditionOneofCase.FilterBoolean: - exprAnd = exprAnd.ExpressionAnd(filterField.FilterBoolean.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterBoolean.Value)); - break; - case FilterField.ValueConditionOneofCase.FilterArray: - exprAnd = exprAnd.ExpressionAnd(filterField.FilterArray.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterArray.Value)); - break; - case FilterField.ValueConditionOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } + exprAnd = filterField.ValueConditionCase switch + { + FilterField.ValueConditionOneofCase.FilterString => exprAnd.ExpressionAnd(filterField.FilterString.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterString + .Value)), + FilterField.ValueConditionOneofCase.FilterNumber => exprAnd.ExpressionAnd(filterField.FilterNumber.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterNumber + .Value)), + FilterField.ValueConditionOneofCase.FilterBoolean => exprAnd.ExpressionAnd(filterField.FilterBoolean.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterBoolean + .Value)), + FilterField.ValueConditionOneofCase.FilterArray => exprAnd.ExpressionAnd(filterField.FilterArray.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterArray.Value)), + _ => throw new ArgumentOutOfRangeException(nameof(filters)), + }; } expr = expr.ExpressionOr(exprAnd); diff --git a/Common/src/gRPC/ListResultsRequestExt.cs b/Common/src/gRPC/ListResultsRequestExt.cs index 475ea0425..e1e074f5c 100644 --- a/Common/src/gRPC/ListResultsRequestExt.cs +++ b/Common/src/gRPC/ListResultsRequestExt.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; @@ -35,23 +36,18 @@ public static class ListResultsRequestExt /// /// the given message is not recognized public static Expression> ToField(this ListResultsRequest.Types.Sort sort) - { - switch (sort.Field.FieldCase) - { - case ResultField.FieldOneofCase.ResultRawField: - return sort.Field.ResultRawField.Field.ToField(); - case ResultField.FieldOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } - } + => sort.Field.FieldCase switch + { + ResultField.FieldOneofCase.ResultRawField => sort.Field.ResultRawField.Field.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this ResultField taskField) => taskField.FieldCase switch { - ResultField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(), + ResultField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(nameof(taskField)), ResultField.FieldOneofCase.ResultRawField => taskField.ResultRawField.Field.ToField(), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(taskField)), }; /// @@ -62,6 +58,9 @@ public static class ListResultsRequestExt /// The that represents the filter conditions /// /// the given message is not recognized + [SuppressMessage("Style", + "IDE0066:Convert switch statement to expression", + Justification = "Readibility for nested switch")] public static Expression> ToResultFilter(this Filters filters) { Expression> expr = data => false; @@ -96,7 +95,7 @@ public static Expression> ToResultFilter(this Filters filters break; case FilterField.ValueConditionOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(filters)); } } diff --git a/Common/src/gRPC/ListSessionsRequestExt.cs b/Common/src/gRPC/ListSessionsRequestExt.cs index ae15ac83f..96e9b9db5 100644 --- a/Common/src/gRPC/ListSessionsRequestExt.cs +++ b/Common/src/gRPC/ListSessionsRequestExt.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; @@ -35,29 +36,22 @@ public static class ListSessionsRequestExt /// /// the given message is not recognized public static Expression> ToField(this ListSessionsRequest.Types.Sort sort) - { - switch (sort.Field.FieldCase) - { - case SessionField.FieldOneofCase.SessionRawField: - return sort.Field.SessionRawField.Field.ToField(); - case SessionField.FieldOneofCase.TaskOptionField: - return sort.Field.TaskOptionField.Field.ToField(); - case SessionField.FieldOneofCase.TaskOptionGenericField: - return sort.Field.TaskOptionGenericField.ToField(); - case SessionField.FieldOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } - } + => sort.Field.FieldCase switch + { + SessionField.FieldOneofCase.SessionRawField => sort.Field.SessionRawField.Field.ToField(), + SessionField.FieldOneofCase.TaskOptionField => sort.Field.TaskOptionField.Field.ToField(), + SessionField.FieldOneofCase.TaskOptionGenericField => sort.Field.TaskOptionGenericField.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this SessionField taskField) => taskField.FieldCase switch { - SessionField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(), + SessionField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(nameof(taskField)), SessionField.FieldOneofCase.SessionRawField => taskField.SessionRawField.Field.ToField(), SessionField.FieldOneofCase.TaskOptionField => taskField.TaskOptionField.Field.ToField(), SessionField.FieldOneofCase.TaskOptionGenericField => taskField.TaskOptionGenericField.ToField(), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(taskField)), }; /// @@ -68,6 +62,9 @@ public static class ListSessionsRequestExt /// The that represents the filter conditions /// /// the given message is not recognized + [SuppressMessage("Style", + "IDE0066:Convert switch statement to expression", + Justification = "Readability for nested switch")] public static Expression> ToSessionDataFilter(this Filters filters) { Expression> expr = data => false; @@ -110,7 +107,7 @@ public static Expression> ToSessionDataFilter(this Filte break; case FilterField.ValueConditionOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(filters)); } } diff --git a/Common/src/gRPC/ListTasksRequestExt.cs b/Common/src/gRPC/ListTasksRequestExt.cs index d403eb42c..5975d57aa 100644 --- a/Common/src/gRPC/ListTasksRequestExt.cs +++ b/Common/src/gRPC/ListTasksRequestExt.cs @@ -37,29 +37,22 @@ public static class ListTasksRequestExt /// /// the given message is not recognized public static Expression> ToField(this ListTasksRequest.Types.Sort sort) - { - switch (sort.Field.FieldCase) - { - case TaskField.FieldOneofCase.TaskSummaryField: - return sort.Field.TaskSummaryField.Field.ToField(); - case TaskField.FieldOneofCase.TaskOptionField: - return sort.Field.TaskOptionField.Field.ToField(); - case TaskField.FieldOneofCase.TaskOptionGenericField: - return sort.Field.TaskOptionGenericField.ToField(); - case TaskField.FieldOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } - } + => sort.Field.FieldCase switch + { + TaskField.FieldOneofCase.TaskSummaryField => sort.Field.TaskSummaryField.Field.ToField(), + TaskField.FieldOneofCase.TaskOptionField => sort.Field.TaskOptionField.Field.ToField(), + TaskField.FieldOneofCase.TaskOptionGenericField => sort.Field.TaskOptionGenericField.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this TaskField taskField) => taskField.FieldCase switch { - TaskField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(), + TaskField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(nameof(taskField)), TaskField.FieldOneofCase.TaskSummaryField => taskField.TaskSummaryField.Field.ToField(), TaskField.FieldOneofCase.TaskOptionField => taskField.TaskOptionField.Field.ToField(), TaskField.FieldOneofCase.TaskOptionGenericField => taskField.TaskOptionGenericField.ToField(), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(taskField)), }; /// @@ -105,9 +98,7 @@ public static Expression> ToTaskDataFilter(this Filters fil case FilterField.ValueConditionOneofCase.FilterDate: var val = filterField.FilterDate.Value; exprAnd = exprAnd.ExpressionAnd(filterField.FilterDate.Operator.ToFilter(filterField.Field.ToField(), - val == null - ? null - : val.ToDateTime())); + val?.ToDateTime())); break; case FilterField.ValueConditionOneofCase.FilterArray: exprAnd = exprAnd.ExpressionAnd(filterField.FilterArray.Operator.ToFilter(filterField.Field.ToField(), @@ -115,7 +106,7 @@ public static Expression> ToTaskDataFilter(this Filters fil break; case FilterField.ValueConditionOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(filters)); } } diff --git a/Common/src/gRPC/Services/Agent.cs b/Common/src/gRPC/Services/Agent.cs index 0198e74b8..440abacf0 100644 --- a/Common/src/gRPC/Services/Agent.cs +++ b/Common/src/gRPC/Services/Agent.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Channels; @@ -49,7 +50,7 @@ namespace ArmoniK.Core.Common.gRPC.Services; /// /// Represents the internal processing requests received by the agent. Provides methods to process those requests /// -public class Agent : IAgent +public sealed class Agent : IAgent { private readonly List createdTasks_; private readonly ILogger logger_; @@ -187,6 +188,9 @@ await taskTable_.FinalizeTaskCreation(ids, } /// + [SuppressMessage("Usage", + "CA2208:Instantiate argument exceptions correctly", + Justification = "No correct value for ArgumentOutOfRange Exception in nested code")] public async Task CreateTask(IAsyncStreamReader requestStream, CancellationToken cancellationToken) { @@ -308,7 +312,7 @@ await taskRequestsChannel.Writer.WriteAsync(new TaskRequest(request.InitTask.Hea { currentTasks!.Select(_ => new CreateTaskReply.Types.CreationStatus { - Error = "An error occured during task creation", + Error = "An error occurred during task creation", }), }, }, @@ -317,7 +321,7 @@ await taskRequestsChannel.Writer.WriteAsync(new TaskRequest(request.InitTask.Hea case InitTaskRequest.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(InitTaskRequest.TypeOneofCase.LastTask)); } break; @@ -338,13 +342,13 @@ await taskRequestsChannel.Writer.WriteAsync(new TaskRequest(request.InitTask.Hea break; case DataChunk.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(request.TaskPayload.TypeCase)); } break; case CreateTaskRequest.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(CreateTaskRequest.TypeOneofCase.InitTask)); } } @@ -508,6 +512,9 @@ await responseStream.WriteAsync(new DataReply } /// + [SuppressMessage("Usage", + "CA2208:Instantiate argument exceptions correctly", + Justification = "")] public async Task SendResult(IAsyncStreamReader requestStream, CancellationToken cancellationToken) { @@ -582,7 +589,7 @@ await completionTask.WaitAsync(cancellationToken) case InitKeyedDataStream.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(request.Init.TypeCase)); } break; @@ -602,13 +609,13 @@ await chunksChannel.Writer.WriteAsync(request.Data.Data.Memory, case DataChunk.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(request.Data.TypeCase)); } break; case Result.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(request.TypeCase)); } } diff --git a/Common/src/gRPC/Services/GrpcAgentService.cs b/Common/src/gRPC/Services/GrpcAgentService.cs index fcdeeccb1..9182a864d 100644 --- a/Common/src/gRPC/Services/GrpcAgentService.cs +++ b/Common/src/gRPC/Services/GrpcAgentService.cs @@ -22,19 +22,12 @@ using Grpc.Core; -using Microsoft.Extensions.Logging; - namespace ArmoniK.Core.Common.gRPC.Services; [IgnoreAuthentication] public class GrpcAgentService : Api.gRPC.V1.Agent.Agent.AgentBase { - private readonly ILogger logger_; - private IAgent? agent_; - - - public GrpcAgentService(ILogger logger) - => logger_ = logger; + private IAgent? agent_; public Task Start(IAgent agent) { diff --git a/Common/src/gRPC/Services/GrpcApplicationsService.cs b/Common/src/gRPC/Services/GrpcApplicationsService.cs index a3c026b9d..dfa7ec5a1 100644 --- a/Common/src/gRPC/Services/GrpcApplicationsService.cs +++ b/Common/src/gRPC/Services/GrpcApplicationsService.cs @@ -54,36 +54,36 @@ public GrpcApplicationsService(ITaskTable taskTable, public override async Task ListApplications(ListApplicationsRequest request, ServerCallContext context) { - var tasks = await taskTable_.ListApplicationsAsync(request.Filters is null - ? data => true - : request.Filters.ToApplicationFilter(), - request.Sort is null - ? new List>> - { - application => application.Name, - } - : request.Sort.Fields.Select(field => field.ToField()) - .ToList(), - request.Sort is null || request.Sort.Direction == SortDirection.Asc, - request.Page, - request.PageSize, - context.CancellationToken) - .ConfigureAwait(false); + var (applications, totalCount) = await taskTable_.ListApplicationsAsync(request.Filters is null + ? data => true + : request.Filters.ToApplicationFilter(), + request.Sort is null + ? new List>> + { + application => application.Name, + } + : request.Sort.Fields.Select(field => field.ToField()) + .ToList(), + request.Sort is null || request.Sort.Direction == SortDirection.Asc, + request.Page, + request.PageSize, + context.CancellationToken) + .ConfigureAwait(false); return new ListApplicationsResponse { Page = request.Page, PageSize = request.PageSize, Applications = { - tasks.applications.Select(data => new ApplicationRaw - { - Name = data.Name, - Namespace = data.Namespace, - Version = data.Version, - Service = data.Service, - }), + applications.Select(data => new ApplicationRaw + { + Name = data.Name, + Namespace = data.Namespace, + Version = data.Version, + Service = data.Service, + }), }, - Total = tasks.totalCount, + Total = totalCount, }; } } diff --git a/Common/src/gRPC/Services/GrpcAuthService.cs b/Common/src/gRPC/Services/GrpcAuthService.cs index 844d5d39e..e10513a5d 100644 --- a/Common/src/gRPC/Services/GrpcAuthService.cs +++ b/Common/src/gRPC/Services/GrpcAuthService.cs @@ -28,7 +28,6 @@ using Grpc.Core; using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace ArmoniK.Core.Common.gRPC.Services; @@ -36,14 +35,11 @@ namespace ArmoniK.Core.Common.gRPC.Services; [Authorize(AuthenticationSchemes = Authenticator.SchemeName)] public class GrpcAuthService : Authentication.AuthenticationBase { - private readonly ILogger logger_; - private readonly bool requireAuthentication_; - private readonly bool requireAuthorization_; + private readonly bool requireAuthentication_; + private readonly bool requireAuthorization_; - public GrpcAuthService(IOptionsMonitor options, - ILogger logger) + public GrpcAuthService(IOptionsMonitor options) { - logger_ = logger; requireAuthentication_ = options.CurrentValue.RequireAuthentication; requireAuthorization_ = requireAuthentication_ && options.CurrentValue.RequireAuthorization; } diff --git a/Common/src/gRPC/Services/GrpcEventsService.cs b/Common/src/gRPC/Services/GrpcEventsService.cs index 74e34806a..9c22126fe 100644 --- a/Common/src/gRPC/Services/GrpcEventsService.cs +++ b/Common/src/gRPC/Services/GrpcEventsService.cs @@ -62,8 +62,7 @@ public override async Task GetEvents(EventSubscriptionRequest var wtg = new WatchToGrpc(taskTable_, taskWatcher_, resultTable_, - resultWatcher_, - logger_); + resultWatcher_); try { diff --git a/Common/src/gRPC/Services/GrpcSessionsService.cs b/Common/src/gRPC/Services/GrpcSessionsService.cs index 75548c2ca..8faf20fdf 100644 --- a/Common/src/gRPC/Services/GrpcSessionsService.cs +++ b/Common/src/gRPC/Services/GrpcSessionsService.cs @@ -129,17 +129,17 @@ public override async Task ListSessions(ListSessionsReques { try { - var sessionData = await sessionTable_.ListSessionsAsync(request.Filters is null - ? data => true - : request.Filters.ToSessionDataFilter(), - request.Sort is null - ? data => data.SessionId - : request.Sort.ToField(), - request.Sort is null || request.Sort.Direction == SortDirection.Asc, - request.Page, - request.PageSize, - context.CancellationToken) - .ConfigureAwait(false); + var (sessions, totalCount) = await sessionTable_.ListSessionsAsync(request.Filters is null + ? data => true + : request.Filters.ToSessionDataFilter(), + request.Sort is null + ? data => data.SessionId + : request.Sort.ToField(), + request.Sort is null || request.Sort.Direction == SortDirection.Asc, + request.Page, + request.PageSize, + context.CancellationToken) + .ConfigureAwait(false); return new ListSessionsResponse { @@ -147,9 +147,9 @@ request.Sort is null PageSize = request.PageSize, Sessions = { - sessionData.sessions.Select(data => new SessionRaw(data)), + sessions.Select(data => new SessionRaw(data)), }, - Total = (int)sessionData.totalCount, + Total = (int)totalCount, }; } catch (ArmoniKException e) diff --git a/Common/src/gRPC/Services/GrpcSubmitterService.cs b/Common/src/gRPC/Services/GrpcSubmitterService.cs index fe3976ad2..b315791c7 100644 --- a/Common/src/gRPC/Services/GrpcSubmitterService.cs +++ b/Common/src/gRPC/Services/GrpcSubmitterService.cs @@ -501,6 +501,7 @@ public override async Task TryGetTaskOutput(TaskOutputRequest request, [RequiresPermission(typeof(GrpcSubmitterService), nameof(WaitForAvailability))] + [Obsolete($"{nameof(ISubmitter.WaitForAvailabilityAsync)} is obsolete")] public override async Task WaitForAvailability(ResultRequest request, ServerCallContext context) { @@ -582,6 +583,7 @@ await taskTable_.GetTaskStatus(request.TaskIds, [RequiresPermission(typeof(GrpcSubmitterService), nameof(GetResultStatus))] + [Obsolete($"{nameof(Api.gRPC.V1.Submitter.Submitter.SubmitterBase.GetResultStatus)} is obsolete")] public override async Task GetResultStatus(GetResultStatusRequest request, ServerCallContext context) { diff --git a/Common/src/gRPC/Services/GrpcTasksService.cs b/Common/src/gRPC/Services/GrpcTasksService.cs index 992260831..d67bfd063 100644 --- a/Common/src/gRPC/Services/GrpcTasksService.cs +++ b/Common/src/gRPC/Services/GrpcTasksService.cs @@ -113,39 +113,39 @@ public override async Task ListTasks(ListTasksRequest reques request.Sort.Field.TaskOptionGenericField.Field); } - var taskData = await taskTable_.ListTasksAsync(request.Filters is null - ? data => true - : request.Filters.ToTaskDataFilter(), - request.Sort is null - ? data => data.TaskId - : request.Sort.ToField(), - data => new TaskDataSummary(data.SessionId, - data.TaskId, - data.OwnerPodId, - data.OwnerPodName, - data.ParentTaskIds.Count, - data.DataDependencies.Count, - data.ExpectedOutputIds.Count, - data.InitialTaskId, - data.RetryOfIds.Count, - data.Status, - data.StatusMessage, - data.Options, - data.CreationDate, - data.SubmittedDate, - data.StartDate, - data.EndDate, - data.ReceptionDate, - data.AcquisitionDate, - data.PodTtl, - data.ProcessingToEndDuration, - data.CreationToEndDuration, - data.Output), - request.Sort is null || request.Sort.Direction == SortDirection.Asc, - request.Page, - request.PageSize, - context.CancellationToken) - .ConfigureAwait(false); + var (tasks, totalCount) = await taskTable_.ListTasksAsync(request.Filters is null + ? data => true + : request.Filters.ToTaskDataFilter(), + request.Sort is null + ? data => data.TaskId + : request.Sort.ToField(), + data => new TaskDataSummary(data.SessionId, + data.TaskId, + data.OwnerPodId, + data.OwnerPodName, + data.ParentTaskIds.Count, + data.DataDependencies.Count, + data.ExpectedOutputIds.Count, + data.InitialTaskId, + data.RetryOfIds.Count, + data.Status, + data.StatusMessage, + data.Options, + data.CreationDate, + data.SubmittedDate, + data.StartDate, + data.EndDate, + data.ReceptionDate, + data.AcquisitionDate, + data.PodTtl, + data.ProcessingToEndDuration, + data.CreationToEndDuration, + data.Output), + request.Sort is null || request.Sort.Direction == SortDirection.Asc, + request.Page, + request.PageSize, + context.CancellationToken) + .ConfigureAwait(false); return new ListTasksResponse { @@ -153,9 +153,9 @@ request.Sort is null PageSize = request.PageSize, Tasks = { - taskData.tasks.Select(data => data.ToTaskSummary()), + tasks.Select(data => data.ToTaskSummary()), }, - Total = (int)taskData.totalCount, + Total = (int)totalCount, }; } catch (ArmoniKException e) @@ -326,18 +326,18 @@ public override async Task ListTasksRaw(ListTasksRequest request.Sort.Field.TaskOptionGenericField.Field); } - var taskData = await taskTable_.ListTasksAsync(request.Filters is null - ? data => true - : request.Filters.ToTaskDataFilter(), - request.Sort is null - ? data => data.TaskId - : request.Sort.ToField(), - data => data, - request.Sort is null || request.Sort.Direction == SortDirection.Asc, - request.Page, - request.PageSize, - context.CancellationToken) - .ConfigureAwait(false); + var (tasks, totalCount) = await taskTable_.ListTasksAsync(request.Filters is null + ? data => true + : request.Filters.ToTaskDataFilter(), + request.Sort is null + ? data => data.TaskId + : request.Sort.ToField(), + data => data, + request.Sort is null || request.Sort.Direction == SortDirection.Asc, + request.Page, + request.PageSize, + context.CancellationToken) + .ConfigureAwait(false); return new ListTasksRawResponse { @@ -345,9 +345,9 @@ request.Sort is null PageSize = request.PageSize, Tasks = { - taskData.tasks.Select(data => new TaskRaw(data)), + tasks.Select(data => new TaskRaw(data)), }, - Total = (int)taskData.totalCount, + Total = (int)totalCount, }; } catch (ArmoniKException e) diff --git a/Common/src/gRPC/Services/Submitter.cs b/Common/src/gRPC/Services/Submitter.cs index 3305684ff..8e5cc4e95 100644 --- a/Common/src/gRPC/Services/Submitter.cs +++ b/Common/src/gRPC/Services/Submitter.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -176,6 +177,9 @@ public async Task CreateSession(IList partitionI } /// + [SuppressMessage("Usage", + "CA2208:Instantiate argument exceptions correctly", + Justification = $"{nameof(ArgumentOutOfRangeException)} is used in nested code")] public async Task TryGetResult(ResultRequest request, IServerStreamWriter responseStream, CancellationToken cancellationToken) @@ -232,9 +236,10 @@ await responseStream.WriteAsync(new ResultReply .ConfigureAwait(false); return; + case TaskStatus.Retried: // TODO: If this case is not used, maybe remove it completely? case TaskStatus.Unspecified: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(taskData.Status)); } } @@ -450,6 +455,9 @@ await ResultLifeCycleHelper.AbortTaskAndResults(taskTable_, } /// + [SuppressMessage("Usage", + "CA2208:Instantiate argument exceptions correctly", + Justification = $"{nameof(ArgumentOutOfRangeException)} is used in nested code")] public async Task WaitForAvailabilityAsync(ResultRequest request, CancellationToken contextCancellationToken) { @@ -498,8 +506,9 @@ public async Task WaitForAvailabilityAsync(ResultRequest }, }; case ResultStatus.Unspecified: + case ResultStatus.Notfound: // TODO: define a specific error type ? default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(result.Status)); } await Task.Delay(currentPollingDelay, diff --git a/Common/src/gRPC/Services/WatchToGrpc.cs b/Common/src/gRPC/Services/WatchToGrpc.cs index 9156ea21d..d9521457c 100644 --- a/Common/src/gRPC/Services/WatchToGrpc.cs +++ b/Common/src/gRPC/Services/WatchToGrpc.cs @@ -24,8 +24,6 @@ using ArmoniK.Core.Common.Storage; using ArmoniK.Core.Common.Storage.Events; -using Microsoft.Extensions.Logging; - namespace ArmoniK.Core.Common.gRPC.Services; /// @@ -35,7 +33,6 @@ namespace ArmoniK.Core.Common.gRPC.Services; public class WatchToGrpc { private const int PageSize = 100; - private readonly ILogger logger_; private readonly IResultTable resultTable_; private readonly IResultWatcher resultWatcher_; private readonly ITaskTable taskTable_; @@ -52,14 +49,12 @@ public class WatchToGrpc public WatchToGrpc(ITaskTable taskTable, ITaskWatcher taskWatcher, IResultTable resultTable, - IResultWatcher resultWatcher, - ILogger logger) + IResultWatcher resultWatcher) { taskTable_ = taskTable; taskWatcher_ = taskWatcher; resultTable_ = resultTable; resultWatcher_ = resultWatcher; - logger_ = logger; } /// diff --git a/Common/tests/AdapterLoading/AdapterLoadingTest.cs b/Common/tests/AdapterLoading/AdapterLoadingTest.cs index 31634e5b8..ea1017fa2 100644 --- a/Common/tests/AdapterLoading/AdapterLoadingTest.cs +++ b/Common/tests/AdapterLoading/AdapterLoadingTest.cs @@ -58,7 +58,7 @@ public static IEnumerable TestCasesQueueLocation } } - public void Setup(Dictionary config) + public static void BuildServiceProvider(Dictionary config) { var loggerProvider = new ConsoleForwardingLoggerProvider(); var logger = loggerProvider.CreateLogger("root"); @@ -93,7 +93,7 @@ public void QueueShouldLoad(string path, }, }; - Assert.DoesNotThrow(() => Setup(config)); + Assert.DoesNotThrow(() => BuildServiceProvider(config)); } public static IEnumerable ConfInvalidOperationException @@ -163,7 +163,7 @@ public static IEnumerable ConfInvalidOperationException [Test] [TestCaseSource(nameof(ConfInvalidOperationException))] public void InvalidConfShouldFail(Dictionary config) - => Assert.Throws(() => Setup(config)); + => Assert.Throws(() => BuildServiceProvider(config)); public static IEnumerable ConfTypeLoadException { @@ -189,5 +189,5 @@ public static IEnumerable ConfTypeLoadException [Test] [TestCaseSource(nameof(ConfTypeLoadException))] public void InvalidTypeConfShouldFail(Dictionary config) - => Assert.Throws(() => Setup(config)); + => Assert.Throws(() => BuildServiceProvider(config)); } diff --git a/Common/tests/Auth/AuthenticationCacheTest.cs b/Common/tests/Auth/AuthenticationCacheTest.cs index c1c41e202..1de601d8c 100644 --- a/Common/tests/Auth/AuthenticationCacheTest.cs +++ b/Common/tests/Auth/AuthenticationCacheTest.cs @@ -35,11 +35,11 @@ public void Setup() } private const string ConnectionId = "TestConnectionId"; - private const string CN = "CN1"; + private const string Cn = "CN1"; private const string Fingerprint = "Fingerprint1"; private static readonly AuthenticationCacheKey BaseKey = new(ConnectionId, - CN, + Cn, Fingerprint); private static readonly ClaimsPrincipal BaseIdentity = new(new UserIdentity(new UserAuthenticationResult(), @@ -58,32 +58,32 @@ public void CacheShouldHit() [Test] [TestCase(ConnectionId, - CN, + Cn, Fingerprint, "ImpId", null)] [TestCase(ConnectionId, - CN, + Cn, Fingerprint, null, "ImpName")] [TestCase(ConnectionId, - CN + "0", + Cn + "0", Fingerprint + "0", null, null)] [TestCase(ConnectionId, - CN + "0", + Cn + "0", null, null, null)] [TestCase(ConnectionId + "0", - CN, + Cn, Fingerprint, null, null)] [TestCase(ConnectionId + "0", - CN + "0", + Cn + "0", Fingerprint + "0", null, null)] @@ -124,11 +124,11 @@ public void CacheKeyEquatableShouldMatch() { Assert.IsTrue(BaseKey.Equals(BaseKey)); Assert.IsTrue(BaseKey.Equals(new AuthenticationCacheKey(ConnectionId, - CN, + Cn, Fingerprint))); Assert.IsFalse(BaseKey.Equals(null)); Assert.IsFalse(BaseKey!.Equals(new AuthenticationCacheKey(ConnectionId, - CN + "0", + Cn + "0", Fingerprint))); Assert.IsFalse(BaseKey.Equals(new object())); } diff --git a/Common/tests/Auth/AuthenticationIntegrationTest.cs b/Common/tests/Auth/AuthenticationIntegrationTest.cs index 41bdd0cbe..e60b836a4 100644 --- a/Common/tests/Auth/AuthenticationIntegrationTest.cs +++ b/Common/tests/Auth/AuthenticationIntegrationTest.cs @@ -19,6 +19,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Threading; @@ -52,6 +53,8 @@ using Grpc.Core; +using JetBrains.Annotations; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -108,11 +111,11 @@ await helper_.StopServer() [SetUp] public void BeforeEach() - => singleThreadSemaphore.Wait(); + => SingleThreadSemaphore.Wait(); [TearDown] public void AfterEach() - => singleThreadSemaphore.Release(); + => SingleThreadSemaphore.Release(); private const string SessionId = "MySession"; private const string ResultKey = "ResultKey"; @@ -406,7 +409,7 @@ public static Metadata GetHeaders(IdentityIndex index, ? "DoesntExistCN" : Identities[(int)index] .Certificates.FirstOrDefault(defaultCertificate) - .CN); + .Cn); headers.Add(AuthenticatorOptions.DefaultAuth.FingerprintHeader, index == IdentityIndex.DoesntExist ? "DoesntExistFingerprint" @@ -979,7 +982,7 @@ public static Task SyncTestFunction(string method, client, args)); - private static readonly SemaphoreSlim singleThreadSemaphore = new(1, + private static readonly SemaphoreSlim SingleThreadSemaphore = new(1, 1); /// @@ -1154,6 +1157,7 @@ public void TransformResult(IdentityIndex initialUserIndex, } [NonParallelizable] + [PublicAPI] // removes a warning about unused parameter [TestCaseSource(nameof(GetTestReflectionCases), new object?[] { @@ -1182,6 +1186,9 @@ public void TransformResult(IdentityIndex initialUserIndex, false, true, })] + [SuppressMessage("Style", + "IDE0060:Remove unused parameter", + Justification = "Required for TestCaseSource")] public void AuthenticationShouldMatch(CaseParameters parameters, TRequest requestExample, TReply replyExample) @@ -1202,38 +1209,6 @@ public void AuthenticationShouldMatch(CaseParameters parameter Assert.IsNotNull(client); Assert.IsInstanceOf(client); - async Task TestFunction() - { - if (parameters.IsAsync) - { - await AsyncTestFunction(parameters.Method, - (ClientBase)client!, - parameters.Args) - .ConfigureAwait(false); - } - else if (parameters.ClientStream) - { - await ClientStreamTestFunction(parameters.Method, - (ClientBase)client!, - parameters.Args) - .ConfigureAwait(false); - } - else if (parameters.ServerStream) - { - await ServerStreamTestFunction(parameters.Method, - (ClientBase)client!, - parameters.Args) - .ConfigureAwait(false); - } - else - { - await SyncTestFunction(parameters.Method, - (ClientBase)client!, - parameters.Args) - .ConfigureAwait(false); - } - } - var serviceName = ServicesPermissions.FromType(ClientServerTypeMapping[parameters.ClientType]); if (shouldSucceed == ResultType.AlwaysTrue || (shouldSucceed == ResultType.AuthorizedForSome && Identities[finalUserIndex] @@ -1276,8 +1251,41 @@ await SyncTestFunction(parameters.Method, ((RpcException)finalException!).StatusCode); } - helper_.DeleteChannel(channel) - .Wait(); + GrpcSubmitterServiceHelper.DeleteChannel(channel) + .Wait(); + return; + + async Task TestFunction() + { + if (parameters.IsAsync) + { + await AsyncTestFunction(parameters.Method, + (ClientBase)client!, + parameters.Args) + .ConfigureAwait(false); + } + else if (parameters.ClientStream) + { + await ClientStreamTestFunction(parameters.Method, + (ClientBase)client!, + parameters.Args) + .ConfigureAwait(false); + } + else if (parameters.ServerStream) + { + await ServerStreamTestFunction(parameters.Method, + (ClientBase)client!, + parameters.Args) + .ConfigureAwait(false); + } + else + { + await SyncTestFunction(parameters.Method, + (ClientBase)client!, + parameters.Args) + .ConfigureAwait(false); + } + } } /// @@ -1300,10 +1308,14 @@ public static IEnumerable GetAuthServiceTestCaseSource() return GetCases(methodObjectList); } + [PublicAPI] [TestCaseSource(nameof(GetAuthServiceTestCaseSource))] + [SuppressMessage("Style", + "IDE0060:Remove unused parameter", + Justification = "Required for reflexion")] public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters, - object _, - object __) + object exampleRequest, + object exampleReply) { TransformResult(parameters.IdentityIndex, parameters.ImpersonationType, @@ -1382,7 +1394,7 @@ public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters, ((RpcException)exception.InnerException!).StatusCode); } - await helper_.DeleteChannel(channel) - .ConfigureAwait(false); + await GrpcSubmitterServiceHelper.DeleteChannel(channel) + .ConfigureAwait(false); } } diff --git a/Common/tests/Auth/MockIdentity.cs b/Common/tests/Auth/MockIdentity.cs index d1a4f6abb..4b456d0de 100644 --- a/Common/tests/Auth/MockIdentity.cs +++ b/Common/tests/Auth/MockIdentity.cs @@ -42,7 +42,7 @@ public MockIdentity(string userId, public bool HasCertificate(string cn, string fingerprint) - => Certificates.Any(t => t.CN == cn && t.Fingerprint == fingerprint); + => Certificates.Any(t => t.Cn == cn && t.Fingerprint == fingerprint); public UserAuthenticationResult ToUserAuthenticationResult() => new(UserId, @@ -50,6 +50,6 @@ public UserAuthenticationResult ToUserAuthenticationResult() Roles, Permissions.Select(perm => perm.ToString())); - public record MockCertificate(string CN, + public record MockCertificate(string Cn, string Fingerprint); } diff --git a/Common/tests/Helpers/ExceptionWorkerStreamHandler.cs b/Common/tests/Helpers/ExceptionWorkerStreamHandler.cs index 8dd375fba..f95153ed3 100644 --- a/Common/tests/Helpers/ExceptionWorkerStreamHandler.cs +++ b/Common/tests/Helpers/ExceptionWorkerStreamHandler.cs @@ -29,7 +29,7 @@ namespace ArmoniK.Core.Common.Tests.Helpers; -public class ExceptionWorkerStreamHandler : IWorkerStreamHandler +public sealed class ExceptionWorkerStreamHandler : IWorkerStreamHandler where T : Exception, new() { private readonly int delay_; diff --git a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs index 236a5276e..e3ec95272 100644 --- a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs +++ b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs @@ -27,6 +27,7 @@ using ArmoniK.Core.Common.Injection; using ArmoniK.Core.Common.Storage; using ArmoniK.Core.Common.Tests.Auth; +using ArmoniK.Utils; using Grpc.Core; using Grpc.Net.Client; @@ -42,23 +43,21 @@ namespace ArmoniK.Core.Common.Tests.Helpers; public class GrpcSubmitterServiceHelper : IDisposable { private readonly WebApplication app_; + private readonly Mutex channelMutex_ = new(); private readonly ILoggerFactory loggerFactory_; private ChannelBase? channel_; - private Mutex channelMutex_; private HttpMessageHandler? handler_; - private ILogger logger_; - private int nChannels; private TestServer? server_; public GrpcSubmitterServiceHelper(ISubmitter submitter, List authIdentities, AuthenticatorOptions authOptions, - LogLevel loglevel, + LogLevel logLevel, Action? serviceConfigurator = null, bool validateGrpcRequests = true) { loggerFactory_ = new LoggerFactory(); - loggerFactory_.AddProvider(new ConsoleForwardingLoggerProvider(loglevel)); + loggerFactory_.AddProvider(new ConsoleForwardingLoggerProvider(logLevel)); var builder = WebApplication.CreateBuilder(); @@ -71,7 +70,7 @@ public GrpcSubmitterServiceHelper(ISubmitter submitter, .AddSingleton() .AddSingleton() .Configure(o => o.CopyFrom(authOptions)) - .AddLogging(build => build.SetMinimumLevel(loglevel) + .AddLogging(build => build.SetMinimumLevel(logLevel) .AddConsole()) .AddAuthentication() .AddScheme(Authenticator.SchemeName, @@ -90,8 +89,7 @@ public GrpcSubmitterServiceHelper(ISubmitter submitter, serviceConfigurator?.Invoke(builder.Services); builder.WebHost.UseTestServer(options => options.PreserveExecutionContext = true); - logger_ = loggerFactory_.CreateLogger("Testing apps"); - app_ = builder.Build(); + app_ = builder.Build(); app_.UseRouting(); app_.UseAuthentication(); app_.UseAuthorization(); @@ -119,8 +117,7 @@ public GrpcSubmitterServiceHelper(ISubmitter submitter, public void Dispose() { app_.DisposeAsync() - .GetAwaiter() - .GetResult(); + .WaitSync(); server_?.Dispose(); server_ = null; handler_?.Dispose(); @@ -129,6 +126,7 @@ public void Dispose() .Wait(); channel_ = null; loggerFactory_.Dispose(); + channelMutex_?.Dispose(); GC.SuppressFinalize(this); } @@ -161,7 +159,7 @@ await StartServer() ; } - public async Task DeleteChannel(ChannelBase channel) + public static async Task DeleteChannel(ChannelBase channel) => await channel.ShutdownAsync() .ConfigureAwait(false); diff --git a/Common/tests/Helpers/SimpleAgent.cs b/Common/tests/Helpers/SimpleAgent.cs index 7b7f4c136..dc3b41da8 100644 --- a/Common/tests/Helpers/SimpleAgent.cs +++ b/Common/tests/Helpers/SimpleAgent.cs @@ -71,6 +71,5 @@ public Task CreateResults(CreateResultsRequest request, => Task.FromResult(new CreateResultsResponse()); public void Dispose() - { - } + => GC.SuppressFinalize(this); } diff --git a/Common/tests/Helpers/SimplePullQueueStorage.cs b/Common/tests/Helpers/SimplePullQueueStorage.cs index 045428979..e7e63ab61 100644 --- a/Common/tests/Helpers/SimplePullQueueStorage.cs +++ b/Common/tests/Helpers/SimplePullQueueStorage.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Runtime.CompilerServices; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -31,10 +31,7 @@ namespace ArmoniK.Core.Common.Tests.Helpers; public class SimplePullQueueStorage : IPullQueueStorage { - public readonly ConcurrentBag Messages; - - public SimplePullQueueStorage() - => Messages = new ConcurrentBag(); + public readonly ConcurrentBag Messages = new(); public Task Check(HealthCheckTag tag) => Task.FromResult(HealthCheckResult.Healthy()); @@ -42,27 +39,30 @@ public Task Check(HealthCheckTag tag) public Task Init(CancellationToken cancellationToken) => Task.CompletedTask; - public int MaxPriority { get; } = 10; + public int MaxPriority + => 10; + -#pragma warning disable CS1998 - public async IAsyncEnumerable PullMessagesAsync(int nbMessages, -#pragma warning restore CS1998 - [EnumeratorCancellation] CancellationToken cancellationToken = default) - { - var i = 0; - while (i < nbMessages && Messages.TryTake(out var m)) - { - i++; - cancellationToken.ThrowIfCancellationRequested(); - yield return new SimpleQueueMessageHandler - { - CancellationToken = CancellationToken.None, - TaskId = m, - MessageId = Guid.NewGuid() - .ToString(), - Status = QueueMessageStatus.Running, - ReceptionDateTime = DateTime.UtcNow, - }; - } - } + public IAsyncEnumerable PullMessagesAsync(int nbMessages, + CancellationToken cancellationToken = default) + // using ToAsyncEnumerable avoids using an async function needlessly + => Enumerable.Repeat(new ValueTuple(), + nbMessages) + .Select(_ => + { + var success = Messages.TryTake(out var m); + cancellationToken.ThrowIfCancellationRequested(); + return (success, message: m); + }) + .Where(tuple => tuple.success) + .Select(tuple => new SimpleQueueMessageHandler + { + CancellationToken = CancellationToken.None, + TaskId = tuple.message!, + MessageId = Guid.NewGuid() + .ToString(), + Status = QueueMessageStatus.Running, + ReceptionDateTime = DateTime.UtcNow, + } as IQueueMessageHandler) + .ToAsyncEnumerable(); } diff --git a/Common/tests/Helpers/SimpleQueueMessageHandler.cs b/Common/tests/Helpers/SimpleQueueMessageHandler.cs index 0fa7ef2af..615e91754 100644 --- a/Common/tests/Helpers/SimpleQueueMessageHandler.cs +++ b/Common/tests/Helpers/SimpleQueueMessageHandler.cs @@ -26,7 +26,10 @@ namespace ArmoniK.Core.Common.Tests.Helpers; public class SimpleQueueMessageHandler : IQueueMessageHandler { public ValueTask DisposeAsync() - => ValueTask.CompletedTask; + { + GC.SuppressFinalize(this); + return ValueTask.CompletedTask; + } public CancellationToken CancellationToken { get; set; } public string MessageId { get; init; } = ""; diff --git a/Common/tests/Helpers/SimpleWorkerStreamHandler.cs b/Common/tests/Helpers/SimpleWorkerStreamHandler.cs index 840e7686d..c57742a32 100644 --- a/Common/tests/Helpers/SimpleWorkerStreamHandler.cs +++ b/Common/tests/Helpers/SimpleWorkerStreamHandler.cs @@ -15,6 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +using System; using System.Threading; using System.Threading.Tasks; @@ -40,8 +41,7 @@ public Task Init(CancellationToken cancellationToken) => Task.CompletedTask; public void Dispose() - { - } + => GC.SuppressFinalize(this); public void StartTaskProcessing(TaskData taskData, CancellationToken cancellationToken) diff --git a/Common/tests/Helpers/TestDatabaseProvider.cs b/Common/tests/Helpers/TestDatabaseProvider.cs index a51595c58..45deb8bcd 100644 --- a/Common/tests/Helpers/TestDatabaseProvider.cs +++ b/Common/tests/Helpers/TestDatabaseProvider.cs @@ -60,12 +60,14 @@ public TestDatabaseProvider(Action? collectionConfigurato var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 }; var loggerProvider = new ConsoleForwardingLoggerProvider(); - var loggerDB = loggerProvider.CreateLogger("db commands"); + var loggerDb = loggerProvider.CreateLogger("db commands"); runner_ = MongoRunner.Run(options); var settings = MongoClientSettings.FromConnectionString(runner_.ConnectionString); @@ -74,7 +76,7 @@ public TestDatabaseProvider(Action? collectionConfigurato { settings.ClusterConfigurator = cb => { - cb.Subscribe(e => loggerDB.LogTrace("{CommandName} - {Command}", + cb.Subscribe(e => loggerDb.LogTrace("{CommandName} - {Command}", e.CommandName, e.Command.ToJson())); }; @@ -130,10 +132,8 @@ public TestDatabaseProvider(Action? collectionConfigurato builder.Services.AddMongoStorages(builder.Configuration, NullLogger.Instance) - .AddClientSubmitterAuthenticationStorage(builder.Configuration, - NullLogger.Instance) + .AddClientSubmitterAuthenticationStorage(builder.Configuration) .AddClientSubmitterAuthServices(builder.Configuration, - NullLogger.Instance, out _) .Configure(o => o.CopyFrom(AuthenticatorOptions.DefaultNoAuth)) .AddLogging() diff --git a/Common/tests/Helpers/TestPollingAgentProvider.cs b/Common/tests/Helpers/TestPollingAgentProvider.cs index 0ca2545a2..56c88ba07 100644 --- a/Common/tests/Helpers/TestPollingAgentProvider.cs +++ b/Common/tests/Helpers/TestPollingAgentProvider.cs @@ -47,20 +47,15 @@ namespace ArmoniK.Core.Common.Tests.Helpers; public class TestPollingAgentProvider : IDisposable { - private const string DatabaseName = "ArmoniK_TestDB"; - private static readonly ActivitySource ActivitySource = new("ArmoniK.Core.Common.Tests.FullIntegration"); - private readonly WebApplication app; - private readonly IMongoClient client_; - private readonly LoggerFactory loggerFactory_; - private readonly Common.Pollster.Pollster pollster_; + private const string DatabaseName = "ArmoniK_TestDB"; + private static readonly ActivitySource ActivitySource = new("ArmoniK.Core.Common.Tests.FullIntegration"); + private readonly WebApplication app_; + private readonly LoggerFactory loggerFactory_; private readonly CancellationTokenSource pollsterCancellationTokenSource_ = new(); - private readonly Task pollsterRunningTask; - private readonly IResultTable resultTable_; + private readonly Task pollsterRunningTask_; private readonly IMongoRunner runner_; - private readonly ISessionTable sessionTable_; public readonly ISubmitter Submitter; - private readonly ITaskTable taskTable_; public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) @@ -69,12 +64,14 @@ public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 }; runner_ = MongoRunner.Run(options); - client_ = new MongoClient(runner_.ConnectionString); + IMongoClient client = new MongoClient(runner_.ConnectionString); // Minimal set of configurations to operate on a toy DB Dictionary minimalConfig = new() @@ -114,7 +111,7 @@ public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) builder.Services.AddMongoStorages(builder.Configuration, logger) .AddSingleton(ActivitySource) - .AddSingleton(serviceProvider => client_) + .AddSingleton(serviceProvider => client) .AddLogging() .AddSingleton() .AddSingleton() @@ -126,28 +123,25 @@ public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) var computePlanOptions = builder.Configuration.GetRequiredValue(ComputePlane.SettingSection); builder.Services.AddSingleton(computePlanOptions); - app = builder.Build(); + app_ = builder.Build(); + var sessionTable = app_.Services.GetRequiredService(); + Submitter = app_.Services.GetRequiredService(); + var pollster = app_.Services.GetRequiredService(); - resultTable_ = app.Services.GetRequiredService(); - taskTable_ = app.Services.GetRequiredService(); - sessionTable_ = app.Services.GetRequiredService(); - Submitter = app.Services.GetRequiredService(); - pollster_ = app.Services.GetRequiredService(); + sessionTable.Init(CancellationToken.None) + .Wait(); - sessionTable_.Init(CancellationToken.None) - .Wait(); - - pollsterRunningTask = Task.Factory.StartNew(() => pollster_.MainLoop(pollsterCancellationTokenSource_.Token), - TaskCreationOptions.LongRunning); + pollsterRunningTask_ = Task.Factory.StartNew(() => pollster.MainLoop(pollsterCancellationTokenSource_.Token), + TaskCreationOptions.LongRunning); } public void Dispose() { pollsterCancellationTokenSource_?.Cancel(false); - pollsterRunningTask?.Wait(); - pollsterRunningTask?.Dispose(); + pollsterRunningTask_?.Wait(); + pollsterRunningTask_?.Dispose(); pollsterCancellationTokenSource_?.Dispose(); - ((IDisposable)app)?.Dispose(); + (app_ as IDisposable)?.Dispose(); loggerFactory_?.Dispose(); runner_?.Dispose(); GC.SuppressFinalize(this); diff --git a/Common/tests/Helpers/TestPollsterProvider.cs b/Common/tests/Helpers/TestPollsterProvider.cs index f0e3b7bb7..4e478c994 100644 --- a/Common/tests/Helpers/TestPollsterProvider.cs +++ b/Common/tests/Helpers/TestPollsterProvider.cs @@ -68,8 +68,10 @@ public TestPollsterProvider(IWorkerStreamHandler workerStreamHandler, var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 }; runner_ = MongoRunner.Run(options); diff --git a/Common/tests/Helpers/TestTaskHandlerProvider.cs b/Common/tests/Helpers/TestTaskHandlerProvider.cs index 6ed67ba8e..d0521bee9 100644 --- a/Common/tests/Helpers/TestTaskHandlerProvider.cs +++ b/Common/tests/Helpers/TestTaskHandlerProvider.cs @@ -73,8 +73,10 @@ public TestTaskHandlerProvider(IWorkerStreamHandler workerStreamHandler, var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 }; runner_ = MongoRunner.Run(options); diff --git a/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs b/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs index 11476681d..b58181758 100644 --- a/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs +++ b/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs @@ -79,24 +79,24 @@ public class ToApplicationFieldTest public static IEnumerable TestCasesInvoke() { - TestCaseData Case(ApplicationRawEnumField field, - object? expected) - => new TestCaseData(new ApplicationRawField - { - Field = field, - }, - expected).SetArgDisplayNames(field.ToString()); - - yield return Case(ApplicationRawEnumField.Service, - Options.ApplicationService); - yield return Case(ApplicationRawEnumField.Name, - Options.ApplicationName); - yield return Case(ApplicationRawEnumField.Namespace, - Options.ApplicationNamespace); - yield return Case(ApplicationRawEnumField.Version, - Options.ApplicationVersion); + yield return FieldToTestCase(ApplicationRawEnumField.Service, + Options.ApplicationService); + yield return FieldToTestCase(ApplicationRawEnumField.Name, + Options.ApplicationName); + yield return FieldToTestCase(ApplicationRawEnumField.Namespace, + Options.ApplicationNamespace); + yield return FieldToTestCase(ApplicationRawEnumField.Version, + Options.ApplicationVersion); } + private static TestCaseData FieldToTestCase(ApplicationRawEnumField field, + object? expected) + => new TestCaseData(new ApplicationRawField + { + Field = field, + }, + expected).SetArgDisplayNames(field.ToString()); + [Test] [TestCaseSource(nameof(TestCasesInvoke))] public void InvokeShouldReturnExpectedValue(ApplicationRawField field, diff --git a/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs b/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs index ea74721b8..6dfcde2d1 100644 --- a/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs +++ b/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs @@ -153,58 +153,58 @@ public void Filter2(IEnumerable filterFields, public static IEnumerable TestCasesFilter() { - TestCaseData CaseTrue(FilterField filterField) - => new TestCaseData(new[] - { - filterField, - }, - true).SetArgDisplayNames(filterField.ToString()); - - TestCaseData CaseFalse(FilterField filterField) - => new TestCaseData(new[] - { - filterField, - }, - false).SetArgDisplayNames(filterField.ToString()); - - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, - FilterStringOperator.Equal, - ApplicationName)); - yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, - FilterStringOperator.Equal, - ApplicationName + "bad")); - - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, - FilterStringOperator.Equal, - ApplicationNamespace)); - yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, - FilterStringOperator.Equal, - ApplicationNamespace + "bad")); - - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, - FilterStringOperator.Equal, - ApplicationVersion)); - yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, - FilterStringOperator.Equal, - ApplicationVersion + "bad")); - - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.Equal, - ApplicationService)); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.StartsWith, - ApplicationService)); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.EndsWith, - ApplicationService)); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.Contains, - ApplicationService)); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.NotContains, - ApplicationService + "bad")); - yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.Equal, - ApplicationService + "bad")); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, + FilterStringOperator.Equal, + ApplicationName)); + yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, + FilterStringOperator.Equal, + ApplicationName + "bad")); + + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, + FilterStringOperator.Equal, + ApplicationNamespace)); + yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, + FilterStringOperator.Equal, + ApplicationNamespace + "bad")); + + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, + FilterStringOperator.Equal, + ApplicationVersion)); + yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, + FilterStringOperator.Equal, + ApplicationVersion + "bad")); + + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.Equal, + ApplicationService)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.StartsWith, + ApplicationService)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.EndsWith, + ApplicationService)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.Contains, + ApplicationService)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.NotContains, + ApplicationService + "bad")); + yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.Equal, + ApplicationService + "bad")); } + + private static TestCaseData FieldToTestCaseFalse(FilterField filterField) + => new TestCaseData(new[] + { + filterField, + }, + false).SetArgDisplayNames(filterField.ToString()!); + + private static TestCaseData FieldToTestCaseTrue(FilterField filterField) + => new TestCaseData(new[] + { + filterField, + }, + true).SetArgDisplayNames(filterField.ToString()!); } diff --git a/Common/tests/ListPartitionsRequestExt/ToPartitionDataFieldTest.cs b/Common/tests/ListPartitionsRequestExt/ToPartitionDataFieldTest.cs index aee239276..06338800c 100644 --- a/Common/tests/ListPartitionsRequestExt/ToPartitionDataFieldTest.cs +++ b/Common/tests/ListPartitionsRequestExt/ToPartitionDataFieldTest.cs @@ -45,14 +45,6 @@ public class ToPartitionDataFieldTest public static IEnumerable TestCasesInvoke() { - TestCaseData Case(PartitionRawEnumField field, - object? expected) - => new TestCaseData(new PartitionRawField - { - Field = field, - }, - expected).SetArgDisplayNames(field.ToString()); - yield return Case(PartitionRawEnumField.ParentPartitionIds, PartitionData.ParentPartitionIds); yield return Case(PartitionRawEnumField.Id, @@ -67,6 +59,14 @@ TestCaseData Case(PartitionRawEnumField field, PartitionData.PreemptionPercentage); } + private static TestCaseData Case(PartitionRawEnumField field, + object? expected) + => new TestCaseData(new PartitionRawField + { + Field = field, + }, + expected).SetArgDisplayNames(field.ToString()); + [Test] [TestCaseSource(nameof(TestCasesInvoke))] public void InvokeShouldReturnExpectedValue(PartitionRawField field, diff --git a/Common/tests/ListResultsRequestExt/ToResultFieldTest.cs b/Common/tests/ListResultsRequestExt/ToResultFieldTest.cs index afa43c069..879cda321 100644 --- a/Common/tests/ListResultsRequestExt/ToResultFieldTest.cs +++ b/Common/tests/ListResultsRequestExt/ToResultFieldTest.cs @@ -44,15 +44,6 @@ public class ToResultFieldTest public static IEnumerable TestCasesInvoke() { - TestCaseData Case(ResultRawEnumField field, - object? expected) - => new TestCaseData(new ResultRawField - { - Field = field, - }, - expected).SetArgDisplayNames(field.ToString()); - - // TODO add completedDate yield return Case(ResultRawEnumField.Status, Result.Status); @@ -68,6 +59,14 @@ TestCaseData Case(ResultRawEnumField field, Result.SessionId); } + private static TestCaseData Case(ResultRawEnumField field, + object? expected) + => new TestCaseData(new ResultRawField + { + Field = field, + }, + expected).SetArgDisplayNames(field.ToString()); + [Test] [TestCaseSource(nameof(TestCasesInvoke))] public void InvokeShouldReturnExpectedValue(ResultRawField field, diff --git a/Common/tests/ListSessionsRequestExt/ToSessionDataFieldTest.cs b/Common/tests/ListSessionsRequestExt/ToSessionDataFieldTest.cs index 987dcc274..11ddeeb35 100644 --- a/Common/tests/ListSessionsRequestExt/ToSessionDataFieldTest.cs +++ b/Common/tests/ListSessionsRequestExt/ToSessionDataFieldTest.cs @@ -55,14 +55,6 @@ public class ToSessionDataFieldTest public static IEnumerable TestCasesInvoke() { - TestCaseData Case(SessionRawEnumField field, - object? expected) - => new TestCaseData(new SessionRawField - { - Field = field, - }, - expected).SetArgDisplayNames(field.ToString()); - // TODO add Duration yield return Case(SessionRawEnumField.Status, SessionData.Status); @@ -78,6 +70,14 @@ TestCaseData Case(SessionRawEnumField field, SessionData.PartitionIds); } + private static TestCaseData Case(SessionRawEnumField field, + object? expected) + => new TestCaseData(new SessionRawField + { + Field = field, + }, + expected).SetArgDisplayNames(field.ToString()); + [Test] [TestCaseSource(nameof(TestCasesInvoke))] public void InvokeShouldReturnExpectedValue(SessionRawField field, diff --git a/Common/tests/Pollster/PollsterTest.cs b/Common/tests/Pollster/PollsterTest.cs index cc26203c3..be9da9a37 100644 --- a/Common/tests/Pollster/PollsterTest.cs +++ b/Common/tests/Pollster/PollsterTest.cs @@ -422,8 +422,7 @@ public Task Init(CancellationToken cancellationToken) => Task.CompletedTask; public void Dispose() - { - } + => GC.SuppressFinalize(this); public IAsyncPipe? Pipe { get; private set; } @@ -441,7 +440,8 @@ public WaitAsyncPipe(double delay) public async Task ReadAsync(CancellationToken cancellationToken) { - await Task.Delay(TimeSpan.FromMilliseconds(delay_)) + await Task.Delay(TimeSpan.FromMilliseconds(delay_), + CancellationToken.None) .ConfigureAwait(false); return new ProcessReply { @@ -476,11 +476,11 @@ public async Task ExecuteTaskShouldSucceed(double delay) simpleAgentHandler, mockPullQueueStorage.Object); - var tuple = await InitSubmitter(testServiceProvider.Submitter, - testServiceProvider.PartitionTable, - testServiceProvider.ResultTable, - CancellationToken.None) - .ConfigureAwait(false); + var (_, _, taskSubmitted) = await InitSubmitter(testServiceProvider.Submitter, + testServiceProvider.PartitionTable, + testServiceProvider.ResultTable, + CancellationToken.None) + .ConfigureAwait(false); mockPullQueueStorage.Setup(storage => storage.PullMessagesAsync(It.IsAny(), It.IsAny())) @@ -492,7 +492,7 @@ public async Task ExecuteTaskShouldSucceed(double delay) Status = QueueMessageStatus.Waiting, MessageId = Guid.NewGuid() .ToString(), - TaskId = tuple.taskSubmitted, + TaskId = taskSubmitted, }, }.ToAsyncEnumerable()); @@ -508,7 +508,7 @@ await testServiceProvider.Pollster.Init(CancellationToken.None) Assert.AreEqual(TaskStatus.Completed, (await testServiceProvider.TaskTable.GetTaskStatus(new[] { - tuple.taskSubmitted, + taskSubmitted, }, CancellationToken.None) .ConfigureAwait(false)).Single() @@ -530,11 +530,11 @@ public async Task CancelLongTaskShouldSucceed() simpleAgentHandler, mockPullQueueStorage.Object); - var tuple = await InitSubmitter(testServiceProvider.Submitter, - testServiceProvider.PartitionTable, - testServiceProvider.ResultTable, - CancellationToken.None) - .ConfigureAwait(false); + var (_, _, taskSubmitted) = await InitSubmitter(testServiceProvider.Submitter, + testServiceProvider.PartitionTable, + testServiceProvider.ResultTable, + CancellationToken.None) + .ConfigureAwait(false); mockPullQueueStorage.Setup(storage => storage.PullMessagesAsync(It.IsAny(), It.IsAny())) @@ -546,7 +546,7 @@ public async Task CancelLongTaskShouldSucceed() Status = QueueMessageStatus.Waiting, MessageId = Guid.NewGuid() .ToString(), - TaskId = tuple.taskSubmitted, + TaskId = taskSubmitted, }, }.ToAsyncEnumerable()); @@ -563,7 +563,7 @@ await Task.Delay(TimeSpan.FromMilliseconds(200), await testServiceProvider.TaskTable.CancelTaskAsync(new List { - tuple.taskSubmitted, + taskSubmitted, }, CancellationToken.None) .ConfigureAwait(false); @@ -582,7 +582,7 @@ await Task.Delay(TimeSpan.FromMilliseconds(200), Assert.AreEqual(TaskStatus.Cancelled, (await testServiceProvider.TaskTable.GetTaskStatus(new[] { - tuple.taskSubmitted, + taskSubmitted, }, CancellationToken.None) .ConfigureAwait(false)).Single() @@ -685,11 +685,11 @@ public async Task UnavailableWorkerShouldFail() simpleAgentHandler, mockPullQueueStorage.Object); - var tuple = await InitSubmitter(testServiceProvider.Submitter, - testServiceProvider.PartitionTable, - testServiceProvider.ResultTable, - CancellationToken.None) - .ConfigureAwait(false); + var (_, _, taskSubmitted) = await InitSubmitter(testServiceProvider.Submitter, + testServiceProvider.PartitionTable, + testServiceProvider.ResultTable, + CancellationToken.None) + .ConfigureAwait(false); mockPullQueueStorage.Setup(storage => storage.PullMessagesAsync(It.IsAny(), It.IsAny())) @@ -701,7 +701,7 @@ public async Task UnavailableWorkerShouldFail() Status = QueueMessageStatus.Waiting, MessageId = Guid.NewGuid() .ToString(), - TaskId = tuple.taskSubmitted, + TaskId = taskSubmitted, }, }.ToAsyncEnumerable()); @@ -717,7 +717,7 @@ await testServiceProvider.Pollster.Init(CancellationToken.None) Assert.AreEqual(TaskStatus.Submitted, (await testServiceProvider.TaskTable.GetTaskStatus(new[] { - tuple.taskSubmitted, + taskSubmitted, }, CancellationToken.None) .ConfigureAwait(false)).Single() diff --git a/Common/tests/Pollster/TaskHandlerTest.cs b/Common/tests/Pollster/TaskHandlerTest.cs index 6befbfaf1..a473d5c2e 100644 --- a/Common/tests/Pollster/TaskHandlerTest.cs +++ b/Common/tests/Pollster/TaskHandlerTest.cs @@ -97,7 +97,7 @@ public async Task AcquireTaskShouldFail() Assert.IsFalse(acquired); } - private async Task<(string taskId, string taskUnresolvedDepId, string taskErrorId, string taskRetriedId, string sessionId)> InitProviderRunnableTask( + private static async Task<(string taskId, string taskUnresolvedDepId, string taskErrorId, string taskRetriedId, string sessionId)> InitProviderRunnableTask( TestTaskHandlerProvider testServiceProvider) { await testServiceProvider.PartitionTable.CreatePartitionsAsync(new[] @@ -558,7 +558,8 @@ public async Task ReadTaskAsync(string taskId, { if (waitMethod_ == WaitMethod.Read) { - await Task.Delay(delay_) + await Task.Delay(delay_, + cancellationToken) .ConfigureAwait(false); } @@ -708,7 +709,8 @@ public async Task AcquireTask(TaskData taskData, { if (waitMethod_ == WaitMethod.Acquire) { - await Task.Delay(delay_) + await Task.Delay(delay_, + cancellationToken) .ConfigureAwait(false); } @@ -843,7 +845,8 @@ public Task SetSessionDataAsync(IEnumerable partitionIds, public async Task GetSessionAsync(string sessionId, CancellationToken cancellationToken = default) { - await Task.Delay(delay_) + await Task.Delay(delay_, + cancellationToken) .ConfigureAwait(false); return sessionData_!; } @@ -996,10 +999,9 @@ public Task Init(CancellationToken cancellationToken) => Task.CompletedTask; public void Dispose() - { - } + => GC.SuppressFinalize(this); - public IAsyncPipe? Pipe { get; private set; } + public IAsyncPipe? Pipe { get; } public void StartTaskProcessing(TaskData taskData, CancellationToken cancellationToken) diff --git a/Common/tests/Submitter/GrpcSubmitterServiceTests.cs b/Common/tests/Submitter/GrpcSubmitterServiceTests.cs index c50c80d6b..8c371a305 100644 --- a/Common/tests/Submitter/GrpcSubmitterServiceTests.cs +++ b/Common/tests/Submitter/GrpcSubmitterServiceTests.cs @@ -1346,6 +1346,7 @@ await service.WaitForCompletion(new WaitRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityShouldSucceed() { var mockSubmitter = new Mock(); @@ -1376,6 +1377,7 @@ public async Task WaitForAvailabilityShouldSucceed() } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityExceptionShouldThrow() { var mockSubmitter = new Mock(); @@ -1410,6 +1412,7 @@ await service.WaitForAvailability(new ResultRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityArmonikExceptionShouldThrow() { var mockSubmitter = new Mock(); @@ -1444,6 +1447,7 @@ await service.WaitForAvailability(new ResultRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityTaskNotFoundExceptionShouldThrow() { var mockSubmitter = new Mock(); @@ -1478,6 +1482,7 @@ await service.WaitForAvailability(new ResultRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityResultNotFoundExceptionShouldThrow() { var mockSubmitter = new Mock(); @@ -1804,6 +1809,7 @@ await service.ListTasks(new TaskFilter } [Test] + [Obsolete("Method tested is obsolete")] public async Task GetResultStatusAsyncArmoniKNotFoundExceptionShouldThrow() { var mock = new Mock(); @@ -1841,6 +1847,7 @@ await service.GetResultStatus(new GetResultStatusRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task GetResultStatusShouldSucceed() { var mock = new Mock(); diff --git a/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs b/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs index 94cd86887..a5e8878d8 100644 --- a/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs +++ b/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs @@ -617,6 +617,7 @@ await streamingCall.RequestStream.CompleteAsync() nameof(TestCasesOutputSessionNotFoundInternal))] [TestCaseSource(typeof(IntegrationGrpcSubmitterServiceTest), nameof(TestCasesOutputTaskNotFound))] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityThrowsException(ISubmitter submitter) { helper_ = new GrpcSubmitterServiceHelper(submitter); @@ -686,6 +687,7 @@ await streamingCall.RequestStream.CompleteAsync() [Test] [TestCaseSource(typeof(IntegrationGrpcSubmitterServiceTest), nameof(TestCasesResultTable))] + [Obsolete("Method tested is obsolete")] public async Task GetResultStatusAsyncThrowsException(IResultTable resultTable) { helper_ = new GrpcSubmitterServiceHelper(mockSubmitter_.Object, diff --git a/Common/tests/Submitter/SubmitterTests.cs b/Common/tests/Submitter/SubmitterTests.cs index 3f302885f..69a7ae280 100644 --- a/Common/tests/Submitter/SubmitterTests.cs +++ b/Common/tests/Submitter/SubmitterTests.cs @@ -68,8 +68,10 @@ public async Task SetUp() var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 }; runner_ = MongoRunner.Run(options); diff --git a/Common/tests/TestBase/AuthenticationTableTestBase.cs b/Common/tests/TestBase/AuthenticationTableTestBase.cs index e90917e22..819f84bc2 100644 --- a/Common/tests/TestBase/AuthenticationTableTestBase.cs +++ b/Common/tests/TestBase/AuthenticationTableTestBase.cs @@ -194,7 +194,7 @@ static AuthenticationTableTestBase() protected bool RunTests; /* Function be override so it returns the suitable instance - * of AuthenticationTable to the corresponding interface implementation */ + * of AuthenticationTable to the corresponding interface implementation */ public virtual void GetAuthSource() { } diff --git a/Common/tests/TestBase/ObjectStorageTestBase.cs b/Common/tests/TestBase/ObjectStorageTestBase.cs index 3267ff466..a16cd5503 100644 --- a/Common/tests/TestBase/ObjectStorageTestBase.cs +++ b/Common/tests/TestBase/ObjectStorageTestBase.cs @@ -98,7 +98,7 @@ private static bool CheckForSkipSetup() /* Function be override so it returns the suitable instance * of TaskTable to the corresponding interface implementation */ - public virtual void GetObjectStorageInstance() + protected virtual void GetObjectStorageInstance() { } diff --git a/Common/tests/TestBase/PartitionTableTestBase.cs b/Common/tests/TestBase/PartitionTableTestBase.cs index b4a568227..8429ada58 100644 --- a/Common/tests/TestBase/PartitionTableTestBase.cs +++ b/Common/tests/TestBase/PartitionTableTestBase.cs @@ -229,16 +229,16 @@ public async Task ListPartitionsEmptyResultShouldSucceed() { if (RunTests) { - var listTasks = await PartitionTable!.ListPartitionsAsync(data => data.PartitionId == "NotExisting", - data => data.ParentPartitionIds, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await PartitionTable!.ListPartitionsAsync(data => data.PartitionId == "NotExisting", + data => data.ParentPartitionIds, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(0, - listTasks.totalCount); + totalCount); } } @@ -247,16 +247,16 @@ public async Task ListPartitionsContainsShouldSucceed() { if (RunTests) { - var listTasks = await PartitionTable!.ListPartitionsAsync(data => data.ParentPartitionIds.Contains("ParentPartitionId"), - data => data.PartitionId, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await PartitionTable!.ListPartitionsAsync(data => data.ParentPartitionIds.Contains("ParentPartitionId"), + data => data.PartitionId, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(1, - listTasks.totalCount); + totalCount); } } @@ -267,16 +267,16 @@ public async Task ListPartitionFilter(ListPartitionsRequest request, { if (RunTests) { - var listTasks = await PartitionTable!.ListPartitionsAsync(request.Filters.ToPartitionFilter(), - data => data.PartitionId, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await PartitionTable!.ListPartitionsAsync(request.Filters.ToPartitionFilter(), + data => data.PartitionId, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(count, - listTasks.totalCount); + totalCount); } } diff --git a/Common/tests/TestBase/QueueStorageTestsBase.cs b/Common/tests/TestBase/QueueStorageTestsBase.cs index e6dc21432..5bce78204 100644 --- a/Common/tests/TestBase/QueueStorageTestsBase.cs +++ b/Common/tests/TestBase/QueueStorageTestsBase.cs @@ -201,7 +201,6 @@ public async Task PullMessagesAsyncSucceedsOnMultipleCalls() await PullQueueStorage!.Init(CancellationToken.None) .ConfigureAwait(false); - const int priority = 1; var testTaskOptions = new TaskOptions(new Dictionary { { diff --git a/Common/tests/TestBase/SessionTableTestBase.cs b/Common/tests/TestBase/SessionTableTestBase.cs index 512b3cc14..607f02265 100644 --- a/Common/tests/TestBase/SessionTableTestBase.cs +++ b/Common/tests/TestBase/SessionTableTestBase.cs @@ -56,16 +56,7 @@ public async Task SetUp() await SessionTable!.Init(CancellationToken.None) .ConfigureAwait(false); - rootSessionId_ = await SessionTable!.SetSessionDataAsync(new[] - { - "part1", - "part2", - }, - Options, - CancellationToken.None) - .ConfigureAwait(false); - - rootSessionId2_ = await SessionTable!.SetSessionDataAsync(new[] + rootSessionId1_ = await SessionTable!.SetSessionDataAsync(new[] { "part1", "part2", @@ -74,7 +65,16 @@ public async Task SetUp() CancellationToken.None) .ConfigureAwait(false); - rootSessionId3_ = await SessionTable!.SetSessionDataAsync(new[] + await SessionTable!.SetSessionDataAsync(new[] + { + "part1", + "part2", + }, + Options, + CancellationToken.None) + .ConfigureAwait(false); + + rootSessionId2_ = await SessionTable!.SetSessionDataAsync(new[] { "part1", "part2", @@ -83,20 +83,20 @@ public async Task SetUp() CancellationToken.None) .ConfigureAwait(false); - rootSessionId4_ = await SessionTable!.SetSessionDataAsync(new[] - { - "part1", - "part2", - }, - Options with - { - ApplicationName = "ApplicationName2", - ApplicationVersion = "ApplicationVersion2", - }, - CancellationToken.None) - .ConfigureAwait(false); + await SessionTable!.SetSessionDataAsync(new[] + { + "part1", + "part2", + }, + Options with + { + ApplicationName = "ApplicationName2", + ApplicationVersion = "ApplicationVersion2", + }, + CancellationToken.None) + .ConfigureAwait(false); - await SessionTable.CancelSessionAsync(rootSessionId3_, + await SessionTable.CancelSessionAsync(rootSessionId2_, CancellationToken.None) .ConfigureAwait(false); } @@ -108,21 +108,21 @@ public virtual void TearDown() RunTests = false; } - public static TaskOptions Options = new(new Dictionary - { - { - "key1", "val1" - }, - }, - TimeSpan.FromMinutes(1), - 2, - 1, - "part1", - "ApplicationName", - "ApplicationVersion", - "", - "", - ""); + private static readonly TaskOptions Options = new(new Dictionary + { + { + "key1", "val1" + }, + }, + TimeSpan.FromMinutes(1), + 2, + 1, + "part1", + "ApplicationName", + "ApplicationVersion", + "", + "", + ""); private static bool CheckForSkipSetup() { @@ -134,10 +134,8 @@ private static bool CheckForSkipSetup() protected bool RunTests; - private string? rootSessionId_; + private string? rootSessionId1_; private string? rootSessionId2_; - private string? rootSessionId3_; - private string? rootSessionId4_; public virtual void GetSessionTableInstance() { @@ -179,7 +177,7 @@ public async Task IsSessionCancelledAsyncShouldSucceed() { if (RunTests) { - var res = await SessionTable!.IsSessionCancelledAsync(rootSessionId_!, + var res = await SessionTable!.IsSessionCancelledAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.IsFalse(res); @@ -205,7 +203,7 @@ public async Task GetDefaultTaskOptionAsyncShouldSucceed() { if (RunTests) { - var res = await SessionTable!.GetDefaultTaskOptionAsync(rootSessionId_!, + var res = await SessionTable!.GetDefaultTaskOptionAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.NotNull(res); @@ -231,14 +229,14 @@ public async Task CancelSessionAsyncShouldSucceed() { if (RunTests) { - var sessionData = await SessionTable!.CancelSessionAsync(rootSessionId_!, + var sessionData = await SessionTable!.CancelSessionAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.AreEqual(SessionStatus.Cancelled, sessionData.Status); - var wasSessionCanceled = await SessionTable.IsSessionCancelledAsync(rootSessionId_!, + var wasSessionCanceled = await SessionTable.IsSessionCancelledAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.IsTrue(wasSessionCanceled); @@ -264,13 +262,13 @@ public async Task CancelCancelledSessionAsyncShouldFail() { if (RunTests) { - await SessionTable!.CancelSessionAsync(rootSessionId_!, + await SessionTable!.CancelSessionAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.ThrowsAsync(async () => { - await SessionTable.CancelSessionAsync(rootSessionId_!, + await SessionTable.CancelSessionAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); }); @@ -283,7 +281,7 @@ public async Task DeleteSessionAsyncShouldSucceed() { if (RunTests) { - var res = SessionTable!.DeleteSessionAsync(rootSessionId_!, + var res = SessionTable!.DeleteSessionAsync(rootSessionId1_!, CancellationToken.None); await res.ConfigureAwait(false); @@ -338,7 +336,7 @@ public async Task ListSessionAsyncShouldSucceed2() { Sessions = { - rootSessionId_!, + rootSessionId1_!, }, }, CancellationToken.None) @@ -394,7 +392,7 @@ public async Task ListSessionAsyncFilterApplicationNameAndSessionIdShouldSucceed { if (RunTests) { - var res = (await SessionTable!.ListSessionsAsync(data => data.Options.ApplicationName == "ApplicationName" && data.SessionId == rootSessionId_!, + var res = (await SessionTable!.ListSessionsAsync(data => data.Options.ApplicationName == "ApplicationName" && data.SessionId == rootSessionId1_!, data => data.Status, true, 0, diff --git a/Common/tests/TestBase/TaskTableTestBase.cs b/Common/tests/TestBase/TaskTableTestBase.cs index d0859f244..3ad906c2b 100644 --- a/Common/tests/TestBase/TaskTableTestBase.cs +++ b/Common/tests/TestBase/TaskTableTestBase.cs @@ -15,6 +15,10 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// in tests, Tasks can be explicitly waited + +#pragma warning disable CA2012 + using System; using System.Collections.Generic; using System.Linq; @@ -396,9 +400,9 @@ public async Task UpdateAllTaskStatusAsyncShouldSucceed() Ids = { "SessionId", /* Task with TaskStatus.Processing was given this Id, - * for the Memory interface, adding it here is necessary for the test - * to succeed. For the MongoDB interface it may be ignored. - * TODO: Check filter definitions */ + * for the Memory interface, adding it here is necessary for the test + * to succeed. For the MongoDB interface it may be ignored. + * TODO: Check filter definitions */ }, }, }; @@ -406,18 +410,18 @@ public async Task UpdateAllTaskStatusAsyncShouldSucceed() TaskStatus.Timeout, CancellationToken.None) .ConfigureAwait(false); - var resCreating = await TaskTable.GetTaskStatus(new[] - { - "TaskCreatingId", - }, - CancellationToken.None) - .ConfigureAwait(false); - var resProcessing = await TaskTable.GetTaskStatus(new[] - { - "TaskProcessingId", - }, - CancellationToken.None) - .ConfigureAwait(false); + var resCreating = await TaskTable!.GetTaskStatus(new[] + { + "TaskCreatingId", + }, + CancellationToken.None) + .ConfigureAwait(false); + var resProcessing = await TaskTable!.GetTaskStatus(new[] + { + "TaskProcessingId", + }, + CancellationToken.None) + .ConfigureAwait(false); Assert.IsTrue(resCreating.Single() .Status == TaskStatus.Timeout && resProcessing.Single() @@ -445,18 +449,18 @@ public async Task UpdateAllTaskStatusAsyncShouldSucceedIfNoStatusGiven() TaskStatus.Timeout, CancellationToken.None) .ConfigureAwait(false); - var resCreating = await TaskTable.GetTaskStatus(new[] - { - "TaskCreatingId", - }, - CancellationToken.None) - .ConfigureAwait(false); - var resProcessing = await TaskTable.GetTaskStatus(new[] - { - "TaskProcessingId", - }, - CancellationToken.None) - .ConfigureAwait(false); + var resCreating = await TaskTable!.GetTaskStatus(new[] + { + "TaskCreatingId", + }, + CancellationToken.None) + .ConfigureAwait(false); + var resProcessing = await TaskTable!.GetTaskStatus(new[] + { + "TaskProcessingId", + }, + CancellationToken.None) + .ConfigureAwait(false); Assert.IsTrue(resCreating.Single() .Status == TaskStatus.Timeout && resProcessing.Single() @@ -700,12 +704,12 @@ public async Task SetTaskSuccessAsyncShouldSucceed() CancellationToken.None) .ConfigureAwait(false); - var resStatus = await TaskTable.GetTaskStatus(new[] - { - taskProcessingData_.TaskId, - }, - CancellationToken.None) - .ConfigureAwait(false); + var resStatus = await TaskTable!.GetTaskStatus(new[] + { + taskProcessingData_.TaskId, + }, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(TaskStatus.Completed, resStatus.Single() @@ -1332,16 +1336,16 @@ public async Task ListApplicationFromTasksShouldSucceed() Assert.IsTrue(validator.Validate(req) .IsValid); - var listTasks = await TaskTable!.ListApplicationsAsync(req.Filters.ToApplicationFilter(), - req.Sort.Fields.Select(sort => sort.ToField()) - .ToList(), - false, - req.Page, - req.PageSize, - CancellationToken.None) - .ConfigureAwait(false); + var (applications, _) = await TaskTable!.ListApplicationsAsync(req.Filters.ToApplicationFilter(), + req.Sort.Fields.Select(sort => sort.ToField()) + .ToList(), + false, + req.Page, + req.PageSize, + CancellationToken.None) + .ConfigureAwait(false); - var listTasksResponseTaskData = listTasks.applications.ToList(); + var listTasksResponseTaskData = applications.ToList(); foreach (var task in listTasksResponseTaskData) { Console.WriteLine(task); @@ -1508,16 +1512,16 @@ taskData1 with Assert.IsTrue(validator.Validate(req) .IsValid); - var listTasks = await TaskTable.ListApplicationsAsync(req.Filters.ToApplicationFilter(), - req.Sort.Fields.Select(sort => sort.ToField()) - .ToList(), - req.Sort.Direction == SortDirection.Asc, - req.Page, - req.PageSize, - CancellationToken.None) - .ConfigureAwait(false); + var (applications, _) = await TaskTable.ListApplicationsAsync(req.Filters.ToApplicationFilter(), + req.Sort.Fields.Select(sort => sort.ToField()) + .ToList(), + req.Sort.Direction == SortDirection.Asc, + req.Page, + req.PageSize, + CancellationToken.None) + .ConfigureAwait(false); - var listTasksResponseTaskData = listTasks.applications.ToList(); + var listTasksResponseTaskData = applications.ToList(); foreach (var task in listTasksResponseTaskData) { Console.WriteLine(task); @@ -1541,17 +1545,17 @@ public async Task ListTaskWithRequestShouldSucceed() { if (RunTests) { - var listTasks = await TaskTable!.ListTasksAsync(data => data.SessionId == "SessionId", - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(data => data.SessionId == "SessionId", + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(6, - listTasks.totalCount); + totalCount); } } @@ -1604,17 +1608,17 @@ public async Task ListTaskWithRequestOrderByTaskOptionsOptionsShouldSucceed() }, }; - var listTasks = await TaskTable!.ListTasksAsync(req.Filters.ToTaskDataFilter(), - req.Sort.ToField(), - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(req.Filters.ToTaskDataFilter(), + req.Sort.ToField(), + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(6, - listTasks.totalCount); + totalCount); } } @@ -1629,17 +1633,17 @@ public async Task ListTaskWithListInRequestShouldSucceed() TaskStatus.Completed, }; - var listTasks = await TaskTable!.ListTasksAsync(data => statusList.Contains(data.Status), - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(data => statusList.Contains(data.Status), + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(3, - listTasks.totalCount); + totalCount); } } @@ -1648,17 +1652,17 @@ public async Task ListTaskEmptyResultShouldSucceed() { if (RunTests) { - var listTasks = await TaskTable!.ListTasksAsync(data => data.TaskId == "NotExisting", - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(data => data.TaskId == "NotExisting", + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(0, - listTasks.totalCount); + totalCount); } } @@ -1669,17 +1673,17 @@ public async Task ListTaskFilter(ListTasksRequest request, { if (RunTests) { - var listTasks = await TaskTable!.ListTasksAsync(request.Filters.ToTaskDataFilter(), - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(request.Filters.ToTaskDataFilter(), + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(count, - listTasks.totalCount); + totalCount); } } @@ -1896,7 +1900,7 @@ public async Task FindTasksAsyncContainsShouldSucceed() .ConfigureAwait(false); Assert.AreEqual(6, - cancelledTasks.Count()); + cancelledTasks.Count); Assert.AreEqual(6, cancelledTasks.SelectMany(list => list) .Count(s => s == "dependency1")); diff --git a/Common/tests/WatchToGrpcTests.cs b/Common/tests/WatchToGrpcTests.cs index c3c951726..f6c3a3230 100644 --- a/Common/tests/WatchToGrpcTests.cs +++ b/Common/tests/WatchToGrpcTests.cs @@ -25,8 +25,6 @@ using ArmoniK.Core.Common.Tests.Helpers; using ArmoniK.Utils; -using Microsoft.Extensions.Logging.Abstractions; - using NUnit.Framework; namespace ArmoniK.Core.Common.Tests; @@ -42,8 +40,7 @@ public void WatchShouldSucceed() var watchToGrpcInstance = new WatchToGrpc(new SimpleTaskTable(), new SimpleTaskWatcher(), new SimpleResultTable(), - new SimpleResultWatcher(), - NullLogger.Instance); + new SimpleResultWatcher()); var list = new List(); @@ -53,7 +50,6 @@ public void WatchShouldSucceed() // Simple* that are used to create this instance do not check the session in their implementation await foreach (var eventSubscriptionResponse in watchToGrpcInstance.GetEvents("", cts.Token) - .WithCancellation(cts.Token) .ConfigureAwait(false)) { Console.WriteLine(eventSubscriptionResponse); @@ -80,8 +76,7 @@ public async Task MultipleWatchShouldSucceed(int nTries) var watchToGrpcInstance = new WatchToGrpc(new SimpleTaskTable(), new SimpleTaskWatcher(), new SimpleResultTable(), - new SimpleResultWatcher(), - NullLogger.Instance); + new SimpleResultWatcher()); Assert.ThrowsAsync(async () => { @@ -89,7 +84,6 @@ public async Task MultipleWatchShouldSucceed(int nTries) await foreach (var eventSubscriptionResponse in watchToGrpcInstance .GetEvents("", cts.Token) - .WithCancellation(cts.Token) .ConfigureAwait(false)) { Console.WriteLine(eventSubscriptionResponse); diff --git a/Control/Metrics/src/ArmoniK.Core.Control.Metrics.csproj b/Control/Metrics/src/ArmoniK.Core.Control.Metrics.csproj index 4a9bd17c3..5e7b32ff5 100644 --- a/Control/Metrics/src/ArmoniK.Core.Control.Metrics.csproj +++ b/Control/Metrics/src/ArmoniK.Core.Control.Metrics.csproj @@ -41,8 +41,8 @@ - + - + diff --git a/Control/Submitter/src/Program.cs b/Control/Submitter/src/Program.cs index 567103e2a..87ad82fde 100644 --- a/Control/Submitter/src/Program.cs +++ b/Control/Submitter/src/Program.cs @@ -129,10 +129,8 @@ public static async Task Main(string[] args) }); } - builder.Services.AddClientSubmitterAuthenticationStorage(builder.Configuration, - logger.GetLogger()); + builder.Services.AddClientSubmitterAuthenticationStorage(builder.Configuration); builder.Services.AddClientSubmitterAuthServices(builder.Configuration, - logger.GetLogger(), out var authCache); builder.WebHost.UseKestrel(options => diff --git a/Control/Submitter/tests/ArmoniK.Core.Control.Submitter.Tests.csproj b/Control/Submitter/tests/ArmoniK.Core.Control.Submitter.Tests.csproj index f12a2d145..ae7d4573d 100644 --- a/Control/Submitter/tests/ArmoniK.Core.Control.Submitter.Tests.csproj +++ b/Control/Submitter/tests/ArmoniK.Core.Control.Submitter.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/ProfilingTools/src/ArmoniK.Core.ProfilingTools.csproj b/ProfilingTools/src/ArmoniK.Core.ProfilingTools.csproj index bdb2ca4eb..10083c1d3 100644 --- a/ProfilingTools/src/ArmoniK.Core.ProfilingTools.csproj +++ b/ProfilingTools/src/ArmoniK.Core.ProfilingTools.csproj @@ -38,7 +38,7 @@ - + diff --git a/Tests/Bench/Client/src/Program.cs b/Tests/Bench/Client/src/Program.cs index 643703def..a32f1d9d0 100644 --- a/Tests/Bench/Client/src/Program.cs +++ b/Tests/Bench/Client/src/Program.cs @@ -84,7 +84,7 @@ private static async Task Main() benchOptions); using var _ = logger.BeginPropertyScope(("@benchOptions", benchOptions)); - var channelPool = new ObjectPool(() => GrpcChannelFactory.CreateChannel(options)); + var channelPool = new ObjectPool(() => GrpcChannelFactory.CreateChannel(options!)); // Get List of partitions for logging purpose var partitions = await channelPool.WithInstanceAsync(async channel => @@ -381,7 +381,9 @@ await results.ParallelForEach(new ParallelTaskOptions(benchOptions.DegreeOfParal Session = createSessionReply.SessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = await submitterClient.WaitForAvailabilityAsync(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete switch (availabilityReply.TypeCase) { diff --git a/Tests/Bench/Server/src/BenchComputerService.cs b/Tests/Bench/Server/src/BenchComputerService.cs index 0578c5e0c..34d2293d1 100644 --- a/Tests/Bench/Server/src/BenchComputerService.cs +++ b/Tests/Bench/Server/src/BenchComputerService.cs @@ -15,6 +15,10 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// In samples, Random can be used + +#pragma warning disable SEC0115 + using System; using System.Collections.Generic; using System.Threading.Tasks; diff --git a/Tests/Bench/Server/src/GlobalSuppressions.cs b/Tests/Bench/Server/src/GlobalSuppressions.cs new file mode 100644 index 000000000..6b6edd0db --- /dev/null +++ b/Tests/Bench/Server/src/GlobalSuppressions.cs @@ -0,0 +1,22 @@ +// This file is part of the ArmoniK project +// +// Copyright (C) ANEO, 2021-2023. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("CodeQuality", + "IDE0079:Remove unnecessary suppression", + Justification = "")] diff --git a/Tests/Common/Client/src/ConnectionTest.cs b/Tests/Common/Client/src/ConnectionTest.cs index 7f5a02fe6..892c50e59 100644 --- a/Tests/Common/Client/src/ConnectionTest.cs +++ b/Tests/Common/Client/src/ConnectionTest.cs @@ -43,7 +43,7 @@ public void TearDown() channel_ = null; } - private const string rootFolder = "../../../../../../../"; + private const string RootFolder = "../../../../../../../"; private ChannelBase? channel_; @@ -99,7 +99,7 @@ public void ConnectionShouldSucceed(string endpoint, { "GrpcClient:CertP12", string.IsNullOrEmpty(clientCertP12) ? "" - : Path.GetFullPath(Path.Combine(rootFolder, + : Path.GetFullPath(Path.Combine(RootFolder, clientCertP12)) }, { @@ -107,7 +107,7 @@ public void ConnectionShouldSucceed(string endpoint, ? "" : string.IsNullOrEmpty(caFile) ? "" - : Path.GetFullPath(Path.Combine(rootFolder, + : Path.GetFullPath(Path.Combine(RootFolder, caFile)) }, { diff --git a/Tests/HtcMock/Client/src/ArmoniK.Samples.HtcMock.Client.csproj b/Tests/HtcMock/Client/src/ArmoniK.Samples.HtcMock.Client.csproj index 90631aeac..50ec59c92 100644 --- a/Tests/HtcMock/Client/src/ArmoniK.Samples.HtcMock.Client.csproj +++ b/Tests/HtcMock/Client/src/ArmoniK.Samples.HtcMock.Client.csproj @@ -1,45 +1,45 @@  - - Exe - net6.0 - true - ANEO - Copyright (C) ANEO, 2021-2021 - AGPL-3.0-or-later - True - Linux - ..\..\..\.. + + Exe + net6.0 + true + ANEO + Copyright (C) ANEO, 2021-2021 + AGPL-3.0-or-later + True + Linux + ..\..\..\.. enable - + - - embedded - true - snupkg - DEBUG;TRACE - + + embedded + true + snupkg + DEBUG;TRACE + - - true - + + true + - - + + - - - - - - - - - - + + + + + + + + + + diff --git a/Tests/HtcMock/Client/src/Program.cs b/Tests/HtcMock/Client/src/Program.cs index ecc4b13b6..b0f249884 100644 --- a/Tests/HtcMock/Client/src/Program.cs +++ b/Tests/HtcMock/Client/src/Program.cs @@ -57,7 +57,7 @@ private static int Main() var optionsHtcMock = new Options.HtcMock(); configuration.GetSection(Options.HtcMock.SettingSection) .Bind(optionsHtcMock); - var channel = GrpcChannelFactory.CreateChannel(options); + var channel = GrpcChannelFactory.CreateChannel(options!); var gridClient = new GridClient(channel, factory, diff --git a/Tests/HtcMock/Client/src/SessionClient.cs b/Tests/HtcMock/Client/src/SessionClient.cs index 9711d2aec..ebbb5423b 100644 --- a/Tests/HtcMock/Client/src/SessionClient.cs +++ b/Tests/HtcMock/Client/src/SessionClient.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; @@ -36,7 +37,7 @@ namespace ArmoniK.Samples.HtcMock.Client; -public class SessionClient : ISessionClient +public sealed class SessionClient : ISessionClient { private readonly ChannelBase channel_; private readonly ILogger logger_; @@ -67,6 +68,9 @@ public void Dispose() .Wait(); } + [SuppressMessage("Style", + "CA2208", + Justification = "availabilityReply.TypeCase is not a real argument")] public byte[] GetResult(string id) { var resultRequest = new ResultRequest @@ -75,7 +79,9 @@ public byte[] GetResult(string id) Session = sessionId_, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = submitterClient_.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete switch (availabilityReply.TypeCase) { @@ -95,6 +101,9 @@ public byte[] GetResult(string id) return response.Result; } + [SuppressMessage("Style", + "CA2208", + Justification = "availabilityReply.TypeCase is not a real argument")] public Task WaitSubtasksCompletion(string id) { var resultRequest = new ResultRequest @@ -103,7 +112,9 @@ public Task WaitSubtasksCompletion(string id) Session = sessionId_, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = submitterClient_.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete switch (availabilityReply.TypeCase) { @@ -122,6 +133,9 @@ public Task WaitSubtasksCompletion(string id) return Task.CompletedTask; } + [SuppressMessage("Style", + "CA2208", + Justification = "createTaskReply.ResponseCase is not a real argument")] public IEnumerable SubmitTasksWithDependencies(IEnumerable>> payloadsWithDependencies) { var taskRequests = new List(); @@ -176,7 +190,7 @@ public IEnumerable SubmitTasksWithDependencies(IEnumerable Square(int input) Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete Assert.AreEqual(availabilityReply.TypeCase, AvailabilityReply.TypeOneofCase.Ok); @@ -352,7 +354,9 @@ public async Task MultipleTasks([Values(4, ResultId = request.ExpectedOutputKeys.Single(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); @@ -446,7 +450,9 @@ public async Task MultipleDataDependencies([Values(1, ResultId = request.ExpectedOutputKeys.First(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); @@ -459,7 +465,9 @@ public async Task MultipleDataDependencies([Values(1, ResultId = request.ExpectedOutputKeys.Last(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); @@ -559,7 +567,9 @@ public async Task LargePayloads([Values(2, ResultId = request.ExpectedOutputKeys.Single(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); @@ -624,7 +634,9 @@ public async Task EmptyPayload() ResultId = outputId, Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete Assert.AreEqual(AvailabilityReply.TypeOneofCase.Error, availabilityReply.TypeCase); @@ -725,7 +737,9 @@ private async Task RunForPriority(string sessionId, ResultId = request.ExpectedOutputKeys.Single(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); diff --git a/Tests/Stream/Client/SubmitterExt.cs b/Tests/Stream/Client/SubmitterExt.cs index 6a9a35f02..5a6bd985a 100644 --- a/Tests/Stream/Client/SubmitterExt.cs +++ b/Tests/Stream/Client/SubmitterExt.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; @@ -52,6 +53,10 @@ public static string CreateSessionAndCheckReply(this Submitter.SubmitterClient c return session.SessionId; } + + [SuppressMessage("Reliability", + "CA2208: Call the ArgumentOutOfRangeException constructor that contains a message and/or paramName parameter", + Justification = "createTaskReply.ResponseCase is not a real argument")] public static async Task> CreateTasksAndCheckReplyAsync(this Submitter.SubmitterClient client, string sessionId, TaskOptions? taskOptions, @@ -61,29 +66,22 @@ public static async Task> CreateTasksAndCheckReplyAsync(this taskOptions, taskRequestList) .ConfigureAwait(false); - switch (createTaskReply.ResponseCase) - { - case CreateTaskReply.ResponseOneofCase.None: - throw new Exception("Issue with Server !"); - case CreateTaskReply.ResponseOneofCase.CreationStatusList: - return createTaskReply.CreationStatusList.CreationStatuses.Select(status => - { - switch (status.StatusCase) - { - case CreateTaskReply.Types.CreationStatus.StatusOneofCase.None: - throw new Exception("Issue with Server !"); - case CreateTaskReply.Types.CreationStatus.StatusOneofCase.TaskInfo: - return status.TaskInfo.TaskId; - case CreateTaskReply.Types.CreationStatus.StatusOneofCase.Error: - return status.Error; - default: - throw new ArgumentOutOfRangeException(); - } - }); - case CreateTaskReply.ResponseOneofCase.Error: - throw new Exception("Error : " + createTaskReply.Error); - default: - throw new ArgumentOutOfRangeException(); - } + + return createTaskReply.ResponseCase switch + { + CreateTaskReply.ResponseOneofCase.None => throw new Exception("Issue with Server !"), + CreateTaskReply.ResponseOneofCase.CreationStatusList => createTaskReply.CreationStatusList.CreationStatuses.Select(StatusToString), + CreateTaskReply.ResponseOneofCase.Error => throw new Exception("Error : " + createTaskReply.Error), + _ => throw new ArgumentOutOfRangeException(nameof(createTaskReply.ResponseCase)), + }; } + + private static string StatusToString(CreateTaskReply.Types.CreationStatus status) + => status.StatusCase switch + { + CreateTaskReply.Types.CreationStatus.StatusOneofCase.None => throw new Exception("Issue with Server !"), + CreateTaskReply.Types.CreationStatus.StatusOneofCase.TaskInfo => status.TaskInfo.TaskId, + CreateTaskReply.Types.CreationStatus.StatusOneofCase.Error => status.Error, + _ => throw new ArgumentOutOfRangeException(nameof(status)), + }; } diff --git a/Tests/Stream/Client/TaskSubmissionTests.cs b/Tests/Stream/Client/TaskSubmissionTests.cs index 3f575d53b..02b64c22d 100644 --- a/Tests/Stream/Client/TaskSubmissionTests.cs +++ b/Tests/Stream/Client/TaskSubmissionTests.cs @@ -269,7 +269,9 @@ public async Task SubmitTasksShouldSucceed() TaskStatus.Processing, }); +#pragma warning disable CS0612 // Type or member is obsolete await submitterClient.WaitForAvailabilityAsync(new ResultRequest +#pragma warning restore CS0612 // Type or member is obsolete { ResultId = results.Results.Single() .ResultId, diff --git a/Tests/Stream/Common/ArmoniK.Extensions.Common.StreamWrapper.Tests.Common.csproj b/Tests/Stream/Common/ArmoniK.Extensions.Common.StreamWrapper.Tests.Common.csproj index 3577dd00c..27f702b83 100644 --- a/Tests/Stream/Common/ArmoniK.Extensions.Common.StreamWrapper.Tests.Common.csproj +++ b/Tests/Stream/Common/ArmoniK.Extensions.Common.StreamWrapper.Tests.Common.csproj @@ -5,9 +5,9 @@ enable enable - + - + diff --git a/Tests/Stream/Server/WorkerService.cs b/Tests/Stream/Server/WorkerService.cs index b86be9164..d8e1b16f1 100644 --- a/Tests/Stream/Server/WorkerService.cs +++ b/Tests/Stream/Server/WorkerService.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Security.Cryptography; using System.Threading.Tasks; @@ -40,6 +41,9 @@ public WorkerService(ILoggerFactory loggerFactory, { } + [SuppressMessage("Style", + "CA2208: Call the ArgumentOutOfRangeException constructor that contains a message and/or paramName parameter", + Justification = "taskHandler.ExpectedResults.Count is not a real argument")] public override async Task Process(ITaskHandler taskHandler) { var output = new Output(); @@ -112,7 +116,7 @@ await taskHandler.CreateTasksAsync(new[] req, }) .ConfigureAwait(false); - logger_.LogDebug("Sub Task created : {subtaskid}", + logger_.LogDebug("Sub Task created : {subtaskId}", taskId); output = new Output { @@ -122,11 +126,10 @@ await taskHandler.CreateTasksAsync(new[] break; case TestPayload.TaskType.DatadepTransfer: { - var taskId = "DatadepTransfer-" + Guid.NewGuid(); - TaskRequest req; + var taskId = "DataDepTransfer-" + Guid.NewGuid(); if (taskHandler.ExpectedResults.Count != 2) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(payload.Type)); } var resId = taskHandler.ExpectedResults.First(); @@ -135,18 +138,18 @@ await taskHandler.CreateTasksAsync(new[] payload.Type = TestPayload.TaskType.DatadepCompute; - req = new TaskRequest - { - Payload = ByteString.CopyFrom(payload.Serialize()), - ExpectedOutputKeys = - { - resId, - }, - DataDependencies = - { - depId, - }, - }; + var req = new TaskRequest + { + Payload = ByteString.CopyFrom(payload.Serialize()), + ExpectedOutputKeys = + { + resId, + }, + DataDependencies = + { + depId, + }, + }; logger_.LogDebug("DataDepTransfer Input {input}", input); @@ -164,7 +167,7 @@ await taskHandler.CreateTasksAsync(new[] req, }) .ConfigureAwait(false); - logger_.LogDebug("Sub Task created : {subtaskid}", + logger_.LogDebug("Sub Task created : {subtaskId}", taskId); output = new Output @@ -175,14 +178,9 @@ await taskHandler.CreateTasksAsync(new[] break; case TestPayload.TaskType.DatadepCompute: { - if (taskHandler.ExpectedResults.Count != 1) - { - throw new ArgumentOutOfRangeException(); - } - - if (taskHandler.DataDependencies.Count != 1) + if (taskHandler.ExpectedResults.Count != 1 || taskHandler.DataDependencies.Count != 1) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(payload.Type)); } var resId = taskHandler.ExpectedResults.First(); @@ -243,7 +241,7 @@ await taskHandler.SendResult(taskHandler.ExpectedResults.Single(), }; break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(payload.Type)); } } } diff --git a/Utils/src/IQueryableExt.cs b/Utils/src/QueryableExt.cs similarity index 98% rename from Utils/src/IQueryableExt.cs rename to Utils/src/QueryableExt.cs index ed0c53076..7c897858c 100644 --- a/Utils/src/IQueryableExt.cs +++ b/Utils/src/QueryableExt.cs @@ -22,7 +22,7 @@ namespace ArmoniK.Core.Utils; -public static class IQueryableExt +public static class QueryableExt { public static IOrderedQueryable OrderByList(this IQueryable queryable, ICollection>> orderFields, diff --git a/dotnet-coverage.runsettings.xml b/dotnet-coverage.runsettings.xml index 788f38e05..5f6bab48c 100644 --- a/dotnet-coverage.runsettings.xml +++ b/dotnet-coverage.runsettings.xml @@ -1,26 +1,27 @@ + - - - - .*\.dll$ - .*\.exe$ - - - .*Moq.dll$ - .*Mongo2Go.dll$ - .*FluentValidation.dll$ - .*NUnit3.TestAdapter.dll$ - .*System.*\.dll$ - .*StackExchange.Redis.dll$ - .*Protobuf.MSBuild.dll$ - .*Pipelines.Sockets.Unofficial.dll$ - - - - - ^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$ - - - + + + + .*\.dll$ + .*\.exe$ + + + .*Moq.dll$ + .*Mongo2Go.dll$ + .*FluentValidation.dll$ + .*NUnit3.TestAdapter.dll$ + .*System.*\.dll$ + .*StackExchange.Redis.dll$ + .*Protobuf.MSBuild.dll$ + .*Pipelines.Sockets.Unofficial.dll$ + + + + + ^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$ + + + diff --git a/terraform/activemq/activemq.xml b/terraform/activemq/activemq.xml index 0b7b98e96..fb3b95321 100644 --- a/terraform/activemq/activemq.xml +++ b/terraform/activemq/activemq.xml @@ -4,30 +4,30 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> - - - - file:${activemq.conf}/credentials.properties - - - - - - - - + + + file:${activemq.conf}/credentials.properties + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + - - - - + + + - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + diff --git a/terraform/activemq/jetty.xml b/terraform/activemq/jetty.xml index bf99de33e..f0f3865ef 100644 --- a/terraform/activemq/jetty.xml +++ b/terraform/activemq/jetty.xml @@ -1,5 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - index.html - - - - - - - - - + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + index.html - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - + + + diff --git a/terraform/artemis/broker.xml b/terraform/artemis/broker.xml index 43fbfc28c..8f16fb5c5 100644 --- a/terraform/artemis/broker.xml +++ b/terraform/artemis/broker.xml @@ -1,4 +1,5 @@ + - ASYNCIO + ASYNCIO - data/paging + data/paging - data/bindings + data/bindings - data/journal + data/journal - data/large-messages + data/large-messages - + true - true - - 2 + 2 - 10 + 10 - 4096 + 4096 - 10M + 10M - - 112000 + 112000 - - 4096 - - - - + + - - - - - - - - + + + + + - - 5000 + + 5000 - - 90 + 90 - - true - 120000 - 60000 - HALT - 592000 + + true + 120000 + 60000 + HALT + 592000 - - - -1 + -1 - + - - - - + + + - - - - tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=100000;amqpLowCredits=30000;amqpMinLargeMessageSize=102400;amqpDuplicateDetection=false - - - - - - - - - - - - - - - - - - - - - - - DLQ - ExpiryQueue - 0 - - -1 - 10 - PAGE - true - true - - - - DLQ - ExpiryQueue - 0 - - + tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=100000;amqpLowCredits=30000;amqpMinLargeMessageSize=102400;amqpDuplicateDetection=false + + + + + + + + + + + + + + + + + + + + + + + DLQ + ExpiryQueue + 0 + + -1 + 10 + PAGE + true + true + + + + DLQ + ExpiryQueue + 0 + + - - -1 + + -1 - - -1 + + -1 - - 10M - - - -1 - - - 20M - - 10 - PAGE - true - true - false - false - ANYCAST - ANYCAST - - - - -
- - - -
-
- - - -
- -
- - - + -1 + + + 20M + + 10 + PAGE + true + true + false + false + ANYCAST + ANYCAST + + + + +
+ + + +
+
+ + + +
+ +
+ + + - +