diff --git a/Adaptors/Amqp/src/ConnectionAmqp.cs b/Adaptors/Amqp/src/ConnectionAmqp.cs index dfdc18031..208d60464 100644 --- a/Adaptors/Amqp/src/ConnectionAmqp.cs +++ b/Adaptors/Amqp/src/ConnectionAmqp.cs @@ -133,7 +133,7 @@ await Task.Delay(1000 * retry, private static void OnCloseConnection(Error? error, ILogger logger) { - if (error == null) + if (error is null) { logger.LogInformation("AMQP Connection closed with no error"); } diff --git a/Adaptors/MongoDB/src/AuthenticationTable.cs b/Adaptors/MongoDB/src/AuthenticationTable.cs index e81b53f2c..07b61b215 100644 --- a/Adaptors/MongoDB/src/AuthenticationTable.cs +++ b/Adaptors/MongoDB/src/AuthenticationTable.cs @@ -183,11 +183,11 @@ await sessionProvider_.Init(cancellationToken) var sessionHandle = sessionProvider_.Get(); Expression> expression; // Id matching has priority - if (id != null) + if (id is not null) { expression = data => data.UserId == id; } - else if (username != null) + else if (username is not null) { expression = data => data.Username == username; } @@ -280,7 +280,7 @@ await sessionProvider_.Init(cancellationToken) /// The user to identity pipeline private PipelineDefinition GetUserToIdentityPipeline() { - if (userToIdentityPipeline_ != null) + if (userToIdentityPipeline_ is not null) { return userToIdentityPipeline_; } @@ -396,7 +396,7 @@ private PipelineDefinition GetUserToIdentityPipeline( /// Pipeline to obtain the identity from the certificate private PipelineDefinition GetAuthToIdentityPipeline() { - if (authToIdentityPipeline_ != null) + if (authToIdentityPipeline_ is not null) { return authToIdentityPipeline_; } diff --git a/Common/src/Auth/Authentication/Authenticator.cs b/Common/src/Auth/Authentication/Authenticator.cs index 305d0543a..4e56c5878 100644 --- a/Common/src/Auth/Authentication/Authenticator.cs +++ b/Common/src/Auth/Authentication/Authenticator.cs @@ -225,7 +225,7 @@ protected override async Task HandleAuthenticateAsync() .ConfigureAwait(false); - if (identity == null) + if (identity is null) { return AuthenticateResult.Fail("Unrecognized user certificate"); } @@ -236,7 +236,7 @@ protected override async Task HandleAuthenticateAsync() } // Try to impersonate only if at least one of the impersonation headers is set - if (impersonationId != null || impersonationUsername != null) + if (impersonationId is not null || impersonationUsername is not null) { // Only users with the impersonate permission can impersonate if (identity.HasClaim(c => c.Type == GeneralService.Impersonate.Claim.Type)) @@ -296,7 +296,7 @@ protected override async Task HandleAuthenticateAsync() cancellationToken) .ConfigureAwait(false); - if (result == null) + if (result is null) { return null; } @@ -324,7 +324,7 @@ public async Task GetImpersonatedIdentityAsync(ClaimsPrincipal CancellationToken cancellationToken = default) { UserAuthenticationResult? result; - if (impersonationId != null || impersonationUsername != null) + if (impersonationId is not null || impersonationUsername is not null) { result = await authTable_.GetIdentityFromUserAsync(impersonationId, impersonationUsername, @@ -336,7 +336,7 @@ public async Task GetImpersonatedIdentityAsync(ClaimsPrincipal throw new AuthenticationException("Impersonation headers are missing"); } - if (result == null) + if (result is null) { throw new AuthenticationException("User being impersonated does not exist"); } diff --git a/Common/src/Injection/AdapterLoadContext.cs b/Common/src/Injection/AdapterLoadContext.cs index 2c52bb302..b88ad9981 100644 --- a/Common/src/Injection/AdapterLoadContext.cs +++ b/Common/src/Injection/AdapterLoadContext.cs @@ -39,7 +39,7 @@ public AdapterLoadContext(string assemblyPath) protected override Assembly? Load(AssemblyName assemblyName) { var assemblyPath = resolver_.ResolveAssemblyToPath(assemblyName); - return assemblyPath != null + return assemblyPath is not null ? LoadFromAssemblyPath(assemblyPath) : null; } @@ -48,7 +48,7 @@ public AdapterLoadContext(string assemblyPath) protected override IntPtr LoadUnmanagedDll(string unmanagedDllName) { var libraryPath = resolver_.ResolveUnmanagedDllToPath(unmanagedDllName); - return libraryPath != null + return libraryPath is not null ? LoadUnmanagedDllFromPath(libraryPath) : IntPtr.Zero; } diff --git a/Common/src/Injection/ServiceCollectionExt.cs b/Common/src/Injection/ServiceCollectionExt.cs index 1f7ed19d3..ee56fc356 100644 --- a/Common/src/Injection/ServiceCollectionExt.cs +++ b/Common/src/Injection/ServiceCollectionExt.cs @@ -63,7 +63,7 @@ public static IServiceCollection AddArmoniKWorkerConnection(this IServiceCollect var computePlanOptions = computePlanComponent.Get(); - if (computePlanOptions == null) + if (computePlanOptions is null) { return services; } diff --git a/Common/src/Pollster/AgentHandler.cs b/Common/src/Pollster/AgentHandler.cs index 36c22aeaf..bcef12d56 100644 --- a/Common/src/Pollster/AgentHandler.cs +++ b/Common/src/Pollster/AgentHandler.cs @@ -84,7 +84,7 @@ public AgentHandler(LoggerInit loggerInit, try { - if (computePlaneOptions.AgentChannel?.Address == null) + if (computePlaneOptions.AgentChannel?.Address is null) { throw new ArgumentNullException(nameof(computePlaneOptions), $"{nameof(computePlaneOptions.AgentChannel)} is null"); diff --git a/Common/src/Pollster/TaskHandler.cs b/Common/src/Pollster/TaskHandler.cs index 80a10674e..cd4b96bfb 100644 --- a/Common/src/Pollster/TaskHandler.cs +++ b/Common/src/Pollster/TaskHandler.cs @@ -521,7 +521,7 @@ await taskTable_.ReleaseTask(taskData_, /// The metadata of the task /// public TaskInfo GetAcquiredTaskInfo() - => taskData_ != null + => taskData_ is not null ? new TaskInfo(taskData_.SessionId, taskData_.TaskId, messageHandler_.MessageId) @@ -537,7 +537,7 @@ public TaskInfo GetAcquiredTaskInfo() /// input data are not found public async Task PreProcessing() { - if (taskData_ == null) + if (taskData_ is null) { throw new NullReferenceException(); } @@ -574,7 +574,7 @@ await HandleErrorRequeueAsync(e, /// worker pipe is not initialized public async Task ExecuteTask() { - if (taskData_ == null || sessionData_ == null) + if (taskData_ is null || sessionData_ is null) { throw new NullReferenceException(); } diff --git a/Common/src/Storage/TaskLifeCycleHelper.cs b/Common/src/Storage/TaskLifeCycleHelper.cs index 24e1efc59..b36ef976a 100644 --- a/Common/src/Storage/TaskLifeCycleHelper.cs +++ b/Common/src/Storage/TaskLifeCycleHelper.cs @@ -55,7 +55,7 @@ public static TaskOptions ValidateSession(SessionData sessionData, ILogger logger, CancellationToken cancellationToken) { - var localOptions = submissionOptions != null + var localOptions = submissionOptions is not null ? TaskOptions.Merge(submissionOptions, sessionData.Options) : sessionData.Options; diff --git a/Common/src/Stream/Worker/WorkerStreamHandler.cs b/Common/src/Stream/Worker/WorkerStreamHandler.cs index 6f0d38f9e..8b3bf7e39 100644 --- a/Common/src/Stream/Worker/WorkerStreamHandler.cs +++ b/Common/src/Stream/Worker/WorkerStreamHandler.cs @@ -138,7 +138,7 @@ public async Task StartTaskProcessing(TaskData taskData, string dataFolder, CancellationToken cancellationToken) { - if (workerClient_ == null) + if (workerClient_ is null) { throw new ArmoniKException("Worker client should be initialized"); } diff --git a/Common/src/gRPC/Convertors/TaskTableExt.cs b/Common/src/gRPC/Convertors/TaskTableExt.cs index fed30f1f8..8e020efd9 100644 --- a/Common/src/gRPC/Convertors/TaskTableExt.cs +++ b/Common/src/gRPC/Convertors/TaskTableExt.cs @@ -77,10 +77,10 @@ public static async Task UpdateAllTaskStatusAsync(this ITaskTable taskTa TaskStatus status, CancellationToken cancellationToken = default) { - if (filter.Included != null && (filter.Included.Statuses.Contains(TaskStatus.Completed.ToGrpcStatus()) || - filter.Included.Statuses.Contains(TaskStatus.Cancelled.ToGrpcStatus()) || - filter.Included.Statuses.Contains(TaskStatus.Error.ToGrpcStatus()) || - filter.Included.Statuses.Contains(TaskStatus.Retried.ToGrpcStatus()))) + if (filter.Included is not null && (filter.Included.Statuses.Contains(TaskStatus.Completed.ToGrpcStatus()) || + filter.Included.Statuses.Contains(TaskStatus.Cancelled.ToGrpcStatus()) || + filter.Included.Statuses.Contains(TaskStatus.Error.ToGrpcStatus()) || + filter.Included.Statuses.Contains(TaskStatus.Retried.ToGrpcStatus()))) { throw new ArmoniKException("The given TaskFilter contains a terminal state, update forbidden"); } diff --git a/Common/src/gRPC/ListApplicationsRequestExt.cs b/Common/src/gRPC/ListApplicationsRequestExt.cs index 61e79651e..375456c4a 100644 --- a/Common/src/gRPC/ListApplicationsRequestExt.cs +++ b/Common/src/gRPC/ListApplicationsRequestExt.cs @@ -75,7 +75,7 @@ public static Expression> ToApplicationFilter(this Filters Expression> expr = data => false; - if (filters.Or == null || !filters.Or.Any()) + if (filters.Or is null || !filters.Or.Any()) { return data => true; } diff --git a/Common/src/gRPC/ListPartitionsRequestExt.cs b/Common/src/gRPC/ListPartitionsRequestExt.cs index a4ba6a798..28a40d806 100644 --- a/Common/src/gRPC/ListPartitionsRequestExt.cs +++ b/Common/src/gRPC/ListPartitionsRequestExt.cs @@ -61,7 +61,7 @@ public static Expression> ToPartitionFilter(this Filte { Expression> expr = data => false; - if (filters.Or == null || !filters.Or.Any()) + if (filters.Or is null || !filters.Or.Any()) { return data => true; } diff --git a/Common/src/gRPC/ListResultsRequestExt.cs b/Common/src/gRPC/ListResultsRequestExt.cs index 9ce83f160..c6ea8ff6a 100644 --- a/Common/src/gRPC/ListResultsRequestExt.cs +++ b/Common/src/gRPC/ListResultsRequestExt.cs @@ -66,7 +66,7 @@ public static Expression> ToResultFilter(this Filters filters { Expression> expr = data => false; - if (filters.Or == null || !filters.Or.Any()) + if (filters.Or is null || !filters.Or.Any()) { return data => true; } diff --git a/Common/src/gRPC/ListSessionsRequestExt.cs b/Common/src/gRPC/ListSessionsRequestExt.cs index 6b4fc86af..020e55e15 100644 --- a/Common/src/gRPC/ListSessionsRequestExt.cs +++ b/Common/src/gRPC/ListSessionsRequestExt.cs @@ -69,7 +69,7 @@ public static Expression> ToSessionDataFilter(this Filte { Expression> expr = data => false; - if (filters.Or == null || !filters.Or.Any()) + if (filters.Or is null || !filters.Or.Any()) { return data => true; } diff --git a/Common/src/gRPC/ListTasksRequestExt.cs b/Common/src/gRPC/ListTasksRequestExt.cs index 2911a2421..1a979f64b 100644 --- a/Common/src/gRPC/ListTasksRequestExt.cs +++ b/Common/src/gRPC/ListTasksRequestExt.cs @@ -65,7 +65,7 @@ public static Expression> ToTaskDataFilter(this Filters fil { Expression> expr = data => false; - if (filters.Or == null || !filters.Or.Any()) + if (filters.Or is null || !filters.Or.Any()) { return data => true; } diff --git a/Common/src/gRPC/Services/GrpcAgentService.cs b/Common/src/gRPC/Services/GrpcAgentService.cs index 1cbeaca4d..113439e7d 100644 --- a/Common/src/gRPC/Services/GrpcAgentService.cs +++ b/Common/src/gRPC/Services/GrpcAgentService.cs @@ -60,7 +60,7 @@ public Task Stop() public override async Task CreateTask(IAsyncStreamReader requestStream, ServerCallContext context) { - if (agent_ == null) + if (agent_ is null) { return new CreateTaskReply { @@ -247,7 +247,7 @@ await agent_.NotifyResultData(agent_.Token, public override async Task GetCommonData(DataRequest request, ServerCallContext context) { - if (agent_ != null) + if (agent_ is not null) { return new DataResponse { @@ -266,7 +266,7 @@ public override async Task GetCommonData(DataRequest request public override async Task GetResourceData(DataRequest request, ServerCallContext context) { - if (agent_ != null) + if (agent_ is not null) { return new DataResponse { @@ -285,7 +285,7 @@ public override async Task GetResourceData(DataRequest reque public override async Task GetDirectData(DataRequest request, ServerCallContext context) { - if (agent_ != null) + if (agent_ is not null) { return new DataResponse { @@ -304,7 +304,7 @@ public override async Task GetDirectData(DataRequest request public override async Task NotifyResultData(NotifyResultDataRequest request, ServerCallContext context) { - if (agent_ != null) + if (agent_ is not null) { var results = await agent_.NotifyResultData(request.CommunicationToken, request.Ids.ViewSelect(identifier => identifier.ResultId), @@ -328,7 +328,7 @@ public override async Task NotifyResultData(NotifyResu public override async Task CreateResultsMetaData(CreateResultsMetaDataRequest request, ServerCallContext context) { - if (agent_ != null) + if (agent_ is not null) { var results = await agent_.CreateResultsMetaData(request.CommunicationToken, request.Results.ViewSelect(create => new ResultCreationRequest(request.SessionId, @@ -360,7 +360,7 @@ public override async Task CreateResultsMetaData( public override async Task SubmitTasks(SubmitTasksRequest request, ServerCallContext context) { - if (agent_ != null) + if (agent_ is not null) { var createdTasks = await agent_.SubmitTasks(request.TaskCreations.ViewSelect(creation => new TaskSubmissionRequest(creation.PayloadId, creation.TaskOptions.ToNullableTaskOptions(), @@ -402,7 +402,7 @@ public override async Task SubmitTasks(SubmitTasksRequest r public override async Task CreateResults(CreateResultsRequest request, ServerCallContext context) { - if (agent_ != null) + if (agent_ is not null) { var results = await agent_.CreateResults(request.CommunicationToken, request.Results.ViewSelect(create => (new ResultCreationRequest(request.SessionId, diff --git a/Common/src/gRPC/Validators/EventSubscriptionRequestValidator.cs b/Common/src/gRPC/Validators/EventSubscriptionRequestValidator.cs index 038c8ab11..2f90463d7 100644 --- a/Common/src/gRPC/Validators/EventSubscriptionRequestValidator.cs +++ b/Common/src/gRPC/Validators/EventSubscriptionRequestValidator.cs @@ -32,7 +32,7 @@ public class EventSubscriptionRequestValidator : AbstractValidator public override ValidationResult Validate(ValidationContext context) { - if (context.InstanceToValidate.ResultsFilters != null) + if (context.InstanceToValidate.ResultsFilters is not null) { foreach (var filtersAnd in context.InstanceToValidate.ResultsFilters.Or) { @@ -74,7 +74,7 @@ public override ValidationResult Validate(ValidationContext GetAllServices() .Where(t => t.BaseType?.Namespace?.ToUpperInvariant() .StartsWith("ArmoniK.Api.gRPC".ToUpperInvariant()) == true) // Keep only the non-nested types - .Where(t => t.DeclaringType == null) + .Where(t => t.DeclaringType is null) .Select(t => new TestCaseData(t).SetName("{m}" + $"({t.Name})"))); /// diff --git a/Common/tests/Auth/MockAuthenticationTable.cs b/Common/tests/Auth/MockAuthenticationTable.cs index b78db433d..643202abe 100644 --- a/Common/tests/Auth/MockAuthenticationTable.cs +++ b/Common/tests/Auth/MockAuthenticationTable.cs @@ -49,7 +49,7 @@ public Task Init(CancellationToken cancellationToken) public Task GetIdentityFromUserAsync(string? id, string? username, CancellationToken cancellationToken) - => Task.FromResult(identities_.Find(i => id != null + => Task.FromResult(identities_.Find(i => id is not null ? i.UserId == id : i.UserName == username) ?.ToUserAuthenticationResult()); diff --git a/Common/tests/HealthChecks/HowHealthCheckWorkTest.cs b/Common/tests/HealthChecks/HowHealthCheckWorkTest.cs index c382675a9..e3e238387 100644 --- a/Common/tests/HealthChecks/HowHealthCheckWorkTest.cs +++ b/Common/tests/HealthChecks/HowHealthCheckWorkTest.cs @@ -104,7 +104,7 @@ public virtual async Task TearDown() server_?.Dispose(); server_ = null; - if (app_ != null) + if (app_ is not null) { await app_.DisposeAsync() .ConfigureAwait(false); diff --git a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs index 70e09604f..737f0cfea 100644 --- a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs +++ b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs @@ -144,7 +144,7 @@ public async Task CreateChannel() { using (channelMutex_) { - if (handler_ == null) + if (handler_ is null) { await StartServer() .ConfigureAwait(false); diff --git a/Common/tests/Helpers/TestServerCallContext.cs b/Common/tests/Helpers/TestServerCallContext.cs index 3b5517f5c..684799155 100644 --- a/Common/tests/Helpers/TestServerCallContext.cs +++ b/Common/tests/Helpers/TestServerCallContext.cs @@ -72,7 +72,7 @@ protected override ContextPropagationToken CreatePropagationTokenCore(ContextPro protected override Task WriteResponseHeadersAsyncCore(Metadata? responseHeaders) { - if (ResponseHeaders != null) + if (ResponseHeaders is not null) { throw new InvalidOperationException("Response headers have already been written."); } diff --git a/Common/tests/Pollster/TaskHandlerTest.cs b/Common/tests/Pollster/TaskHandlerTest.cs index 2862b70f1..854272fda 100644 --- a/Common/tests/Pollster/TaskHandlerTest.cs +++ b/Common/tests/Pollster/TaskHandlerTest.cs @@ -1335,7 +1335,7 @@ await testServiceProvider.TaskHandler.PreProcessing() await testServiceProvider.TaskHandler.ExecuteTask() .ConfigureAwait(false); - if (agentHandler.Agent == null) + if (agentHandler.Agent is null) { throw new NullReferenceException(nameof(agentHandler.Agent)); } diff --git a/Common/tests/Submitter/ExceptionInterceptorTests.cs b/Common/tests/Submitter/ExceptionInterceptorTests.cs index eb6f9d987..2fdb62720 100644 --- a/Common/tests/Submitter/ExceptionInterceptorTests.cs +++ b/Common/tests/Submitter/ExceptionInterceptorTests.cs @@ -69,7 +69,7 @@ public void OneTimeSetUp() [TearDown] public async Task TearDown() { - if (helper_ != null) + if (helper_ is not null) { await helper_.StopServer() .ConfigureAwait(false); diff --git a/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs b/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs index 7538e5174..d0d789a06 100644 --- a/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs +++ b/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs @@ -73,7 +73,7 @@ public void OneTimeSetUp() [TearDown] public async Task TearDown() { - if (helper_ != null) + if (helper_ is not null) { await helper_.StopServer() .ConfigureAwait(false); diff --git a/Control/PartitionMetrics/src/ArmoniKMeter.cs b/Control/PartitionMetrics/src/ArmoniKMeter.cs index 11b7ac673..730549edd 100644 --- a/Control/PartitionMetrics/src/ArmoniKMeter.cs +++ b/Control/PartitionMetrics/src/ArmoniKMeter.cs @@ -128,7 +128,7 @@ private async Task> FetchMeasurementsAsync(Cancellatio { var metricValue = (metrics[$"armonik_{partition.PartitionId}_tasks_queued"] as Metric)?.MetricValue; - if (metricValue != null) + if (metricValue is not null) { var numberOfTasks = (long)metricValue.Value; measurements[partition.PartitionId] = Math.Min(numberOfTasks, diff --git a/Tests/Stream/Common/TestPayload.cs b/Tests/Stream/Common/TestPayload.cs index 26d1c4877..e23165da9 100644 --- a/Tests/Stream/Common/TestPayload.cs +++ b/Tests/Stream/Common/TestPayload.cs @@ -51,7 +51,7 @@ public byte[] Serialize() public static TestPayload? Deserialize(byte[]? payload) { - if (payload == null || payload.Length == 0) + if (payload is null || payload.Length == 0) { return new TestPayload { diff --git a/Tests/Stream/Server/WorkerService.cs b/Tests/Stream/Server/WorkerService.cs index 84edca9c7..8bb8f9c51 100644 --- a/Tests/Stream/Server/WorkerService.cs +++ b/Tests/Stream/Server/WorkerService.cs @@ -69,7 +69,7 @@ public override async Task Process(ITaskHandler taskHandler) try { var payload = TestPayload.Deserialize(taskHandler.Payload); - if (payload != null) + if (payload is not null) { switch (payload.Type) {