Skip to content

Commit

Permalink
refactor: use is null and is not null (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
aneojgurhem authored Jan 29, 2024
2 parents 2bc14ea + a770369 commit cdbe160
Show file tree
Hide file tree
Showing 30 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Adaptors/Amqp/src/ConnectionAmqp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
8 changes: 4 additions & 4 deletions Adaptors/MongoDB/src/AuthenticationTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ await sessionProvider_.Init(cancellationToken)
var sessionHandle = sessionProvider_.Get();
Expression<Func<UserData, bool>> 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;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ await sessionProvider_.Init(cancellationToken)
/// <returns>The user to identity pipeline</returns>
private PipelineDefinition<UserData, MongoAuthResult> GetUserToIdentityPipeline()
{
if (userToIdentityPipeline_ != null)
if (userToIdentityPipeline_ is not null)
{
return userToIdentityPipeline_;
}
Expand Down Expand Up @@ -396,7 +396,7 @@ private PipelineDefinition<UserData, MongoAuthResult> GetUserToIdentityPipeline(
/// <returns>Pipeline to obtain the identity from the certificate</returns>
private PipelineDefinition<AuthData, MongoAuthResult> GetAuthToIdentityPipeline()
{
if (authToIdentityPipeline_ != null)
if (authToIdentityPipeline_ is not null)
{
return authToIdentityPipeline_;
}
Expand Down
10 changes: 5 additions & 5 deletions Common/src/Auth/Authentication/Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
.ConfigureAwait(false);


if (identity == null)
if (identity is null)
{
return AuthenticateResult.Fail("Unrecognized user certificate");
}
Expand All @@ -236,7 +236,7 @@ protected override async Task<AuthenticateResult> 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))
Expand Down Expand Up @@ -296,7 +296,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
cancellationToken)
.ConfigureAwait(false);

if (result == null)
if (result is null)
{
return null;
}
Expand Down Expand Up @@ -324,7 +324,7 @@ public async Task<ClaimsPrincipal> 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,
Expand All @@ -336,7 +336,7 @@ public async Task<ClaimsPrincipal> 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");
}
Expand Down
4 changes: 2 additions & 2 deletions Common/src/Injection/AdapterLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/src/Injection/ServiceCollectionExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static IServiceCollection AddArmoniKWorkerConnection(this IServiceCollect

var computePlanOptions = computePlanComponent.Get<ComputePlane>();

if (computePlanOptions == null)
if (computePlanOptions is null)
{
return services;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/src/Pollster/AgentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions Common/src/Pollster/TaskHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ await taskTable_.ReleaseTask(taskData_,
/// The metadata of the task
/// </returns>
public TaskInfo GetAcquiredTaskInfo()
=> taskData_ != null
=> taskData_ is not null
? new TaskInfo(taskData_.SessionId,
taskData_.TaskId,
messageHandler_.MessageId)
Expand All @@ -537,7 +537,7 @@ public TaskInfo GetAcquiredTaskInfo()
/// <exception cref="ObjectDataNotFoundException">input data are not found</exception>
public async Task PreProcessing()
{
if (taskData_ == null)
if (taskData_ is null)
{
throw new NullReferenceException();
}
Expand Down Expand Up @@ -574,7 +574,7 @@ await HandleErrorRequeueAsync(e,
/// <exception cref="ArmoniKException">worker pipe is not initialized</exception>
public async Task ExecuteTask()
{
if (taskData_ == null || sessionData_ == null)
if (taskData_ is null || sessionData_ is null)
{
throw new NullReferenceException();
}
Expand Down
2 changes: 1 addition & 1 deletion Common/src/Storage/TaskLifeCycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Common/src/Stream/Worker/WorkerStreamHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task<Output> StartTaskProcessing(TaskData taskData,
string dataFolder,
CancellationToken cancellationToken)
{
if (workerClient_ == null)
if (workerClient_ is null)
{
throw new ArmoniKException("Worker client should be initialized");
}
Expand Down
8 changes: 4 additions & 4 deletions Common/src/gRPC/Convertors/TaskTableExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public static async Task<long> 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");
}
Expand Down
2 changes: 1 addition & 1 deletion Common/src/gRPC/ListApplicationsRequestExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static Expression<Func<TaskData, bool>> ToApplicationFilter(this Filters
Expression<Func<TaskData, bool>> expr = data => false;


if (filters.Or == null || !filters.Or.Any())
if (filters.Or is null || !filters.Or.Any())
{
return data => true;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/src/gRPC/ListPartitionsRequestExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static Expression<Func<PartitionData, bool>> ToPartitionFilter(this Filte
{
Expression<Func<PartitionData, bool>> expr = data => false;

if (filters.Or == null || !filters.Or.Any())
if (filters.Or is null || !filters.Or.Any())
{
return data => true;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/src/gRPC/ListResultsRequestExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static Expression<Func<Result, bool>> ToResultFilter(this Filters filters
{
Expression<Func<Result, bool>> expr = data => false;

if (filters.Or == null || !filters.Or.Any())
if (filters.Or is null || !filters.Or.Any())
{
return data => true;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/src/gRPC/ListSessionsRequestExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static Expression<Func<SessionData, bool>> ToSessionDataFilter(this Filte
{
Expression<Func<SessionData, bool>> expr = data => false;

if (filters.Or == null || !filters.Or.Any())
if (filters.Or is null || !filters.Or.Any())
{
return data => true;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/src/gRPC/ListTasksRequestExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static Expression<Func<TaskData, bool>> ToTaskDataFilter(this Filters fil
{
Expression<Func<TaskData, bool>> expr = data => false;

if (filters.Or == null || !filters.Or.Any())
if (filters.Or is null || !filters.Or.Any())
{
return data => true;
}
Expand Down
16 changes: 8 additions & 8 deletions Common/src/gRPC/Services/GrpcAgentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Task Stop()
public override async Task<CreateTaskReply> CreateTask(IAsyncStreamReader<CreateTaskRequest> requestStream,
ServerCallContext context)
{
if (agent_ == null)
if (agent_ is null)
{
return new CreateTaskReply
{
Expand Down Expand Up @@ -247,7 +247,7 @@ await agent_.NotifyResultData(agent_.Token,
public override async Task<DataResponse> GetCommonData(DataRequest request,
ServerCallContext context)
{
if (agent_ != null)
if (agent_ is not null)
{
return new DataResponse
{
Expand All @@ -266,7 +266,7 @@ public override async Task<DataResponse> GetCommonData(DataRequest request
public override async Task<DataResponse> GetResourceData(DataRequest request,
ServerCallContext context)
{
if (agent_ != null)
if (agent_ is not null)
{
return new DataResponse
{
Expand All @@ -285,7 +285,7 @@ public override async Task<DataResponse> GetResourceData(DataRequest reque
public override async Task<DataResponse> GetDirectData(DataRequest request,
ServerCallContext context)
{
if (agent_ != null)
if (agent_ is not null)
{
return new DataResponse
{
Expand All @@ -304,7 +304,7 @@ public override async Task<DataResponse> GetDirectData(DataRequest request
public override async Task<NotifyResultDataResponse> 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),
Expand All @@ -328,7 +328,7 @@ public override async Task<NotifyResultDataResponse> NotifyResultData(NotifyResu
public override async Task<CreateResultsMetaDataResponse> 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,
Expand Down Expand Up @@ -360,7 +360,7 @@ public override async Task<CreateResultsMetaDataResponse> CreateResultsMetaData(
public override async Task<SubmitTasksResponse> 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(),
Expand Down Expand Up @@ -402,7 +402,7 @@ public override async Task<SubmitTasksResponse> SubmitTasks(SubmitTasksRequest r
public override async Task<CreateResultsResponse> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class EventSubscriptionRequestValidator : AbstractValidator<EventSubscrip
/// <inheritdoc />
public override ValidationResult Validate(ValidationContext<EventSubscriptionRequest> context)
{
if (context.InstanceToValidate.ResultsFilters != null)
if (context.InstanceToValidate.ResultsFilters is not null)
{
foreach (var filtersAnd in context.InstanceToValidate.ResultsFilters.Or)
{
Expand Down Expand Up @@ -74,7 +74,7 @@ public override ValidationResult Validate(ValidationContext<EventSubscriptionReq
}

// ReSharper disable once InvertIf
if (context.InstanceToValidate.TasksFilters != null)
if (context.InstanceToValidate.TasksFilters is not null)
{
foreach (var filtersAnd in context.InstanceToValidate.TasksFilters.Or)
{
Expand Down
2 changes: 1 addition & 1 deletion Common/tests/Auth/AuthenticationCacheTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void CacheShouldMiss(string connectionId,
fingerprint,
impersonationId,
impersonationUsername));
Assert.IsTrue(result == null || BaseIdentity != result);
Assert.IsTrue(result is null || BaseIdentity != result);
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion Common/tests/Auth/AuthenticationIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void BeforeAll()
[OneTimeTearDown]
public async Task TearDown()
{
if (helper_ != null)
if (helper_ is not null)
{
await helper_.StopServer()
.ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion Common/tests/Auth/CheckAuthenticationAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static List<TestCaseData> 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})")));

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Common/tests/Auth/MockAuthenticationTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Task Init(CancellationToken cancellationToken)
public Task<UserAuthenticationResult?> 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());
Expand Down
2 changes: 1 addition & 1 deletion Common/tests/HealthChecks/HowHealthCheckWorkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Common/tests/Helpers/GrpcSubmitterServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task<ChannelBase> CreateChannel()
{
using (channelMutex_)
{
if (handler_ == null)
if (handler_ is null)
{
await StartServer()
.ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion Common/tests/Helpers/TestServerCallContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
2 changes: 1 addition & 1 deletion Common/tests/Pollster/TaskHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion Common/tests/Submitter/ExceptionInterceptorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit cdbe160

Please sign in to comment.