Skip to content

Commit

Permalink
Cleanup #nullability warnings (#437)
Browse files Browse the repository at this point in the history
* Cleanup #nullability warnings

* Fix CSV tags nullability

---------

Co-authored-by: Aaron Stannard <[email protected]>
  • Loading branch information
Arkatufus and Aaronontheweb authored Aug 29, 2024
1 parent 7f5a65b commit 09b8c15
Show file tree
Hide file tree
Showing 34 changed files with 136 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected virtual async ValueTask DisposeAsyncCore()
{
await _readDockerTask;
}
catch(TaskCanceledException _) { }
catch(TaskCanceledException) { }

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public void Log<TState>(
LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter)
Exception? exception,
Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
return;
Expand All @@ -48,7 +48,7 @@ public bool IsEnabled(LogLevel logLevel)
_ => logLevel >= _logLevel,
};

public IDisposable BeginScope<TState>(TState state)
public IDisposable BeginScope<TState>(TState state) where TState : notnull
=> throw new NotImplementedException();

private void WriteLogEntry(LogLevel logLevel, EventId eventId, string message, Exception? exception)
Expand All @@ -73,8 +73,8 @@ private void WriteLogEntry(LogLevel logLevel, EventId eventId, string message, E

private static bool TryFormatMessage<TState>(
TState state,
Exception exception,
Func<TState, Exception, string> formatter,
Exception? exception,
Func<TState, Exception?, string> formatter,
out string result)
{
formatter = formatter ?? throw new ArgumentNullException(nameof(formatter));
Expand Down
10 changes: 5 additions & 5 deletions src/Akka.Persistence.Sql.HelperLib/JournalIndexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public IndexDefinition DefaultJournalIndex(
string tableName,
string persistenceIdCol,
string sequenceNoCol,
string schemaName = null)
string? schemaName = null)
{
var idx = BeginCreateIndex(
tableName,
Expand All @@ -33,7 +33,7 @@ public IndexDefinition DefaultJournalIndex(
public IndexDefinition JournalOrdering(
string tableName,
string orderingCol,
string schemaName = null)
string? schemaName = null)
{
var idx = BeginCreateIndex(
tableName,
Expand All @@ -51,7 +51,7 @@ public IndexDefinition JournalOrdering(
public IndexDefinition JournalTimestamp(
string tableName,
string timestampCol,
string schemaName = null)
string? schemaName = null)
{
var idx = BeginCreateIndex(
tableName,
Expand All @@ -64,11 +64,11 @@ public IndexDefinition JournalTimestamp(
return idx;
}

private static IndexDefinition BeginCreateIndex(string tableName, string schemaName, string indexName)
private static IndexDefinition BeginCreateIndex(string tableName, string? schemaName, string indexName)
{
var idx = new IndexDefinition();

if (string.IsNullOrWhiteSpace(schemaName) == false)
if (!string.IsNullOrWhiteSpace(schemaName))
idx.SchemaName = schemaName;

idx.TableName = tableName;
Expand Down
4 changes: 2 additions & 2 deletions src/Akka.Persistence.Sql.HelperLib/TagTableMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public async Task Migrate(long startOffset, int batchSize, long? endOffset = nul
var tagList = new List<JournalTagRow>();
foreach (var row in rows)
{
var tags = row.Tags
var tags = row.Tags?
.Split(new[] { _separator }, StringSplitOptions.RemoveEmptyEntries)
.Where(s => !string.IsNullOrWhiteSpace(s));
.Where(s => !string.IsNullOrWhiteSpace(s)) ?? Array.Empty<string>();

tagList.AddRange(
tags.Select(
Expand Down
4 changes: 2 additions & 2 deletions src/Akka.Persistence.Sql.IndexHelperApp/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public class Options
"file",
Required = true,
HelpText = "Specify the HOCON file to use")]
public string File { get; set; }
public string File { get; set; } = string.Empty;

[Option(
'p',
"path",
Required = true,
HelpText = "The Path to the Akka.Persistence.Sql Config in the HOCON.")]
public string HoconPath { get; set; }
public string HoconPath { get; set; } = string.Empty;

[Option(
"OrderingIdx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected virtual async ValueTask DisposeAsyncCore()
{
await _readDockerTask;
}
catch(TaskCanceledException _) {}
catch(TaskCanceledException) {}


try
Expand Down
10 changes: 5 additions & 5 deletions src/Akka.Persistence.Sql.Tests.Common/Internal/XUnitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public void Log<TState>(
LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter)
Exception? exception,
Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
return;
Expand All @@ -48,7 +48,7 @@ public bool IsEnabled(LogLevel logLevel)
_ => logLevel >= _logLevel,
};

public IDisposable BeginScope<TState>(TState state)
public IDisposable BeginScope<TState>(TState state) where TState : notnull
=> throw new NotImplementedException();

private void WriteLogEntry(LogLevel logLevel, EventId eventId, string message, Exception? exception)
Expand All @@ -73,8 +73,8 @@ private void WriteLogEntry(LogLevel logLevel, EventId eventId, string message, E

private static bool TryFormatMessage<TState>(
TState state,
Exception exception,
Func<TState, Exception, string> formatter,
Exception? exception,
Func<TState, Exception?, string> formatter,
out string result)
{
formatter = formatter ?? throw new ArgumentNullException(nameof(formatter));
Expand Down
6 changes: 3 additions & 3 deletions src/Akka.Persistence.Sql.Tests/Internal/Events/SomeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace Akka.Persistence.Sql.Tests.Internal.Events
{
public sealed class SomeEvent : IEquatable<SomeEvent>
{
public string EventName { get; set; }
public string EventName { get; set; } = string.Empty;
public int Number { get; set; }
public Guid Guid { get; set; }

public bool Equals(SomeEvent other)
public bool Equals(SomeEvent? other)
{
if (ReferenceEquals(null, other))
return false;
Expand All @@ -25,7 +25,7 @@ public bool Equals(SomeEvent other)
return EventName == other.EventName && Number == other.Number && Guid.Equals(other.Guid);
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
=> ReferenceEquals(this, obj) || (obj is SomeEvent other && Equals(other));

public override int GetHashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class JournalCompatibilityActor : ReceivePersistentActor
{
private readonly List<SomeEvent> _events = new();

private IActorRef _deleteSubscriber;
private IActorRef? _deleteSubscriber;

public JournalCompatibilityActor(string journal, string persistenceId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SnapshotCompatibilityActor : ReceivePersistentActor
{
private List<SomeEvent> _events = new();

private IActorRef _sender;
private IActorRef? _sender;

public SnapshotCompatibilityActor(string snapshot, string persistenceId)
{
Expand Down
30 changes: 15 additions & 15 deletions src/Akka.Persistence.Sql.Tests/SqlCommonJournalCompatibilitySpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ protected SqlCommonJournalCompatibilitySpec(T fixture, ITestOutputHelper outputH

protected abstract string OldJournal { get; }
protected abstract string NewJournal { get; }
protected ActorSystem Sys { get; private set; }
protected Akka.TestKit.Xunit2.TestKit TestKit { get; private set; }
protected TestProbe Probe { get; private set; }
protected ActorSystem? Sys { get; private set; }
protected Akka.TestKit.Xunit2.TestKit? TestKit { get; private set; }
protected TestProbe? Probe { get; private set; }

public async Task InitializeAsync()
{
Expand All @@ -60,18 +60,18 @@ public async Task InitializeAsync()

public Task DisposeAsync()
{
TestKit.Shutdown();
TestKit?.Shutdown();
return Task.CompletedTask;
}

[Fact]
public void Can_Recover_SqlCommon_Journal()
{
var persistRef = Sys.ActorOf(Props.Create(() => new JournalCompatibilityActor(OldJournal, "p-1")));
var persistRef = Sys!.ActorOf(Props.Create(() => new JournalCompatibilityActor(OldJournal, "p-1")));
var ourGuid = Guid.NewGuid();
var someEvent = new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 };

Probe.Send(persistRef, someEvent);
Probe!.Send(persistRef, someEvent);
Probe.ExpectMsg(someEvent, 5.Seconds());
Probe.Send(persistRef, new ContainsEvent { Guid = ourGuid });
Probe.ExpectMsg(true, 5.Seconds());
Expand All @@ -86,11 +86,11 @@ public void Can_Recover_SqlCommon_Journal()
[Fact]
public void Can_Persist_SqlCommon_Journal()
{
var persistRef = Sys.ActorOf(Props.Create(() => new JournalCompatibilityActor(OldJournal, "p-2")));
var persistRef = Sys!.ActorOf(Props.Create(() => new JournalCompatibilityActor(OldJournal, "p-2")));
var ourGuid = Guid.NewGuid();
var someEvent = new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 };

Probe.Send(persistRef, someEvent);
Probe!.Send(persistRef, someEvent);
Probe.ExpectMsg(someEvent, 5.Seconds());
Probe.Send(persistRef, new ContainsEvent { Guid = ourGuid });
Probe.ExpectMsg(true, 5.Seconds());
Expand All @@ -113,11 +113,11 @@ public void Can_Persist_SqlCommon_Journal()
[Fact]
public void SqlCommon_Journal_Can_Recover_L2Db_Journal()
{
var persistRef = Sys.ActorOf(Props.Create(() => new JournalCompatibilityActor(NewJournal, "p-3")));
var persistRef = Sys!.ActorOf(Props.Create(() => new JournalCompatibilityActor(NewJournal, "p-3")));
var ourGuid = Guid.NewGuid();
var someEvent = new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 };

Probe.Send(persistRef, someEvent);
Probe!.Send(persistRef, someEvent);
Probe.ExpectMsg(someEvent, 5.Seconds());
Probe.Send(persistRef, new ContainsEvent { Guid = ourGuid });
Probe.ExpectMsg(true, 5.Seconds());
Expand All @@ -132,11 +132,11 @@ public void SqlCommon_Journal_Can_Recover_L2Db_Journal()
[Fact]
public void SqlCommon_Journal_Can_Persist_L2db_Journal()
{
var persistRef = Sys.ActorOf(Props.Create(() => new JournalCompatibilityActor(NewJournal, "p-4")));
var persistRef = Sys!.ActorOf(Props.Create(() => new JournalCompatibilityActor(NewJournal, "p-4")));
var ourGuid = Guid.NewGuid();
var someEvent = new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 };

Probe.Send(persistRef, someEvent);
Probe!.Send(persistRef, someEvent);
Probe.ExpectMsg(someEvent, 5.Seconds());
Probe.Send(persistRef, new ContainsEvent { Guid = ourGuid });
Probe.ExpectMsg(true, 5.Seconds());
Expand All @@ -159,7 +159,7 @@ public void SqlCommon_Journal_Can_Persist_L2db_Journal()
public void L2db_Journal_Delete_Compat_mode_Preserves_proper_SequenceNr()
{
const string persistenceId = "d-1";
var persistRef = Sys.ActorOf(Props.Create(() => new JournalCompatibilityActor(NewJournal, persistenceId)));
var persistRef = Sys!.ActorOf(Props.Create(() => new JournalCompatibilityActor(NewJournal, persistenceId)));

var ourGuid1 = Guid.NewGuid();
var ourGuid2 = Guid.NewGuid();
Expand All @@ -172,7 +172,7 @@ public void L2db_Journal_Delete_Compat_mode_Preserves_proper_SequenceNr()
var event4 = new SomeEvent { EventName = "rec-test", Guid = ourGuid4, Number = 4 };
var event5 = new SomeEvent { EventName = "rec-test", Guid = ourGuid5, Number = 5 };

Probe.Send(persistRef, event1);
Probe!.Send(persistRef, event1);
Probe.ExpectMsg(event1, 5.Seconds());
Probe.Send(persistRef, event2);
Probe.ExpectMsg(event2, 5.Seconds());
Expand Down Expand Up @@ -214,7 +214,7 @@ public void L2db_Journal_Delete_Compat_mode_Preserves_proper_SequenceNr()

private void EnsureTerminated(IActorRef actorRef)
{
Probe.Watch(actorRef);
Probe!.Watch(actorRef);
actorRef.Tell(PoisonPill.Instance);
Probe.ExpectTerminated(actorRef);
Probe.Unwatch(actorRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public SqlCommonSnapshotCompatibilitySpec(T fixture, ITestOutputHelper helper)
protected ITestOutputHelper Output { get; }
protected abstract string OldSnapshot { get; }
protected abstract string NewSnapshot { get; }
protected ActorSystem Sys { get; private set; }
protected Akka.TestKit.Xunit2.TestKit TestKit { get; private set; }
protected TestProbe Probe { get; private set; }
protected ActorSystem? Sys { get; private set; }
protected Akka.TestKit.Xunit2.TestKit? TestKit { get; private set; }
protected TestProbe? Probe { get; private set; }

public async Task InitializeAsync()
{
Expand All @@ -58,17 +58,17 @@ public async Task InitializeAsync()

public Task DisposeAsync()
{
TestKit.Shutdown();
TestKit?.Shutdown();
return Task.CompletedTask;
}

[Fact]
public void Can_Recover_SqlCommon_Snapshot()
{
var persistRef = Sys.ActorOf(Props.Create(() => new SnapshotCompatibilityActor(OldSnapshot, "p-1")));
var persistRef = Sys!.ActorOf(Props.Create(() => new SnapshotCompatibilityActor(OldSnapshot, "p-1")));
var ourGuid = Guid.NewGuid();

Probe.Send(persistRef, new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 });
Probe!.Send(persistRef, new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 });
Probe.ExpectMsg(true);
Probe.Send(persistRef, new ContainsEvent { Guid = ourGuid });
Probe.ExpectMsg(true, 5.Seconds());
Expand All @@ -83,10 +83,10 @@ public void Can_Recover_SqlCommon_Snapshot()
[Fact]
public void Can_Persist_SqlCommon_Snapshot()
{
var persistRef = Sys.ActorOf(Props.Create(() => new SnapshotCompatibilityActor(OldSnapshot, "p-2")));
var persistRef = Sys!.ActorOf(Props.Create(() => new SnapshotCompatibilityActor(OldSnapshot, "p-2")));
var ourGuid = Guid.NewGuid();

Probe.Send(persistRef, new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 });
Probe!.Send(persistRef, new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 });
Probe.ExpectMsg(true);
Probe.Send(persistRef, new ContainsEvent { Guid = ourGuid });
Probe.ExpectMsg(true, 5.Seconds());
Expand All @@ -107,10 +107,10 @@ public void Can_Persist_SqlCommon_Snapshot()
[Fact]
public void SqlCommon_Snapshot_Can_Recover_L2Db_Snapshot()
{
var persistRef = Sys.ActorOf(Props.Create(() => new SnapshotCompatibilityActor(NewSnapshot, "p-3")));
var persistRef = Sys!.ActorOf(Props.Create(() => new SnapshotCompatibilityActor(NewSnapshot, "p-3")));
var ourGuid = Guid.NewGuid();

Probe.Send(persistRef, new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 });
Probe!.Send(persistRef, new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 });
Probe.ExpectMsg(true);
Probe.Send(persistRef, new ContainsEvent { Guid = ourGuid });
Probe.ExpectMsg(true, 5.Seconds());
Expand All @@ -125,10 +125,10 @@ public void SqlCommon_Snapshot_Can_Recover_L2Db_Snapshot()
[Fact]
public void SqlCommon_Snapshot_Can_Persist_L2db_Snapshot()
{
var persistRef = Sys.ActorOf(Props.Create(() => new SnapshotCompatibilityActor(NewSnapshot, "p-4")));
var persistRef = Sys!.ActorOf(Props.Create(() => new SnapshotCompatibilityActor(NewSnapshot, "p-4")));
var ourGuid = Guid.NewGuid();

Probe.Send(persistRef, new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 });
Probe!.Send(persistRef, new SomeEvent { EventName = "rec-test", Guid = ourGuid, Number = 1 });
Probe.ExpectMsg(true);
Probe.Send(persistRef, new ContainsEvent { Guid = ourGuid });
Probe.ExpectMsg(true, 5.Seconds());
Expand All @@ -148,7 +148,7 @@ public void SqlCommon_Snapshot_Can_Persist_L2db_Snapshot()

private void EnsureTerminated(IActorRef actorRef)
{
Probe.Watch(actorRef);
Probe!.Watch(actorRef);
actorRef.Tell(PoisonPill.Instance);
Probe.ExpectTerminated(actorRef);
Probe.Unwatch(actorRef);
Expand Down
2 changes: 1 addition & 1 deletion src/Akka.Persistence.Sql/Config/JournalConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public JournalConfig(Configuration.Config config)

public string MaterializerDispatcher { get; }

public string UseSharedDb { get; }
public string? UseSharedDb { get; }

public BaseByteArrayJournalDaoConfig DaoConfig { get; }

Expand Down
Loading

0 comments on commit 09b8c15

Please sign in to comment.