Skip to content

Commit

Permalink
Cleanup warnings (#7026)
Browse files Browse the repository at this point in the history
* cleaned up `ClusterDeathWatchSpecs`

* null warnings in Akka.Persistence.Tests

* more build warnings

* fixed Streams.TestKit regressions

* replaced `TrueException` instances with `FailException`

* fixed another `FailException` instance

* more

* fixed DData serializer spec warning
  • Loading branch information
Aaronontheweb committed Dec 14, 2023
1 parent b3f7d38 commit 3aeebb0
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 176 deletions.
7 changes: 4 additions & 3 deletions src/Akka.sln.DotSettings
Expand Up @@ -9,12 +9,13 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">//-----------------------------------------------------------------------&#xD;
// &lt;copyright file="$FILENAME$" company="Akka.NET Project"&gt;&#xD;
// Copyright (C) 2009-$CURRENT_YEAR$ Lightbend Inc. &lt;http://www.lightbend.com&gt;&#xD;
// Copyright (C) 2013-$CURRENT_YEAR$ .NET Foundation &lt;https://github.com/akkadotnet/akka.net&gt;&#xD;
// &lt;copyright file="${File.FileName}" company="Akka.NET Project"&gt;&#xD;
// Copyright (C) 2009-${CurrentDate.Year} Lightbend Inc. &lt;http://www.lightbend.com&gt;&#xD;
// Copyright (C) 2013-${CurrentDate.Year} .NET Foundation &lt;https://github.com/akkadotnet/akka.net&gt;&#xD;
// &lt;/copyright&gt;&#xD;
//-----------------------------------------------------------------------</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FSM/@EntryIndexedValue">FSM</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
Expand Up @@ -34,8 +34,6 @@ public class ReplicatorMessageSerializerSpec : TestKit.Xunit2.TestKit

private readonly ReplicatorMessageSerializer _serializer;

private readonly string _protocol;

private readonly UniqueAddress _address1;
private readonly UniqueAddress _address2;
private readonly UniqueAddress _address3;
Expand All @@ -48,7 +46,6 @@ public ReplicatorMessageSerializerSpec(ITestOutputHelper output) : base(BaseConf

// We dont have Artery implementation
// _protocol = ((RemoteActorRefProvider) ((ExtendedActorSystem)Sys).Provider).RemoteSettings.Artery.Enabled
_protocol = "akka.tcp";

_address1 = new UniqueAddress(new Address("akka.tcp", Sys.Name, "some.host.org", 4711), 1);
_address2 = new UniqueAddress(new Address("akka.tcp", Sys.Name, "other.host.org", 4711), 2);
Expand Down
Expand Up @@ -23,7 +23,7 @@ public class XunitAssertions : ITestKitAssertions
/// <param name="args">An optional object array that contains zero or more objects to format.</param>
public void Fail(string format = "", params object[] args)
{
Assert.True(false, string.Format(format, args));
Assert.Fail(string.Format(format, args));
}

/// <summary>
Expand Down
30 changes: 4 additions & 26 deletions src/core/Akka.Cluster.Tests.MultiNode/ClusterDeathWatchSpec.cs
Expand Up @@ -278,12 +278,12 @@ public void An_actor_watching_a_remote_actor_in_the_cluster_must_be_able_to_shut
{
if (!Sys.WhenTerminated.Wait(timeout)) // TestConductor.Shutdown called by First MUST terminate this actor system
{
Assert.True(false, String.Format("Failed to stop [{0}] within [{1}]", Sys.Name, timeout));
Assert.Fail($"Failed to stop [{Sys.Name}] within [{timeout}]");
}
}
catch (TimeoutException)
{
Assert.True(false, String.Format("Failed to stop [{0}] within [{1}]", Sys.Name, timeout));
Assert.Fail($"Failed to stop [{Sys.Name}] within [{timeout}]");
}
Expand Down Expand Up @@ -328,10 +328,10 @@ public void An_actor_watching_a_remote_actor_in_the_cluster_must_be_able_to_shut
/// <summary>
/// Used to report <see cref="Terminated"/> events to the <see cref="TestActor"/>
/// </summary>
class Observer : ReceiveActor
private class Observer : ReceiveActor
{
private readonly IActorRef _testActorRef;
readonly TestLatch _watchEstablished;
private readonly TestLatch _watchEstablished;

public Observer(ActorPath path2, ActorPath path3, TestLatch watchEstablished, IActorRef testActorRef)
{
Expand Down Expand Up @@ -360,28 +360,6 @@ public Observer(ActorPath path2, ActorPath path3, TestLatch watchEstablished, IA

}
}

class DumbObserver : ReceiveActor
{
private readonly IActorRef _testActorRef;

public DumbObserver(ActorPath path2, IActorRef testActorRef)
{
_testActorRef = testActorRef;

Receive<ActorIdentity>(identity =>
{
Context.Watch(identity.Subject);
});

Receive<Terminated>(terminated =>
{
_testActorRef.Tell(terminated.ActorRef.Path);
});

Context.ActorSelection(path2).Tell(new Identify(path2));
}
}
}
}

1 change: 1 addition & 0 deletions src/core/Akka.Persistence.Tests/AtLeastOnceDeliverySpec.cs
Expand Up @@ -15,6 +15,7 @@
using Xunit;
using Xunit.Abstractions;
using FluentAssertions;
#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()

namespace Akka.Persistence.Tests
{
Expand Down
5 changes: 4 additions & 1 deletion src/core/Akka.Persistence.Tests/EndToEndEventAdapterSpec.cs
Expand Up @@ -240,7 +240,10 @@ protected bool PersistIncoming(object message)

protected override bool ReceiveRecover(object message)
{
if (message is RecoveryCompleted) ;
if (message is RecoveryCompleted)
{
// skip
}
else _state.AddLast(message);
return true;
}
Expand Down
137 changes: 85 additions & 52 deletions src/core/Akka.Persistence.Tests/MemoryEventAdapterSpec.cs
Expand Up @@ -50,7 +50,7 @@ public override bool Equals(object obj)
}

[Serializable]
public sealed class NotTagged : IJournalModel, IEquatable<IJournalModel>
public sealed class NotTagged : IJournalModel, IEquatable<IJournalModel>, IEquatable<NotTagged>
{
public object Payload { get; private set; }
public ISet<string> Tags { get { return new HashSet<string>(); } }
Expand All @@ -69,6 +69,18 @@ public override bool Equals(object obj)
{
return Equals(obj as IJournalModel);
}

public bool Equals(NotTagged other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(Payload, other.Payload);
}

public override int GetHashCode()
{
return (Payload != null ? Payload.GetHashCode() : 0);
}
}

public interface IDomainEvent { }
Expand All @@ -94,6 +106,14 @@ public override bool Equals(object obj)
{
return Equals(obj as TaggedDataChanged);
}

public override int GetHashCode()
{
unchecked
{
return ((Tags != null ? Tags.GetHashCode() : 0) * 397) ^ Value;
}
}
}

[Serializable]
Expand All @@ -117,6 +137,14 @@ public override bool Equals(object obj)
{
return Equals(obj as UserDataChanged);
}

public override int GetHashCode()
{
unchecked
{
return ((CountryCode != null ? CountryCode.GetHashCode() : 0) * 397) ^ Age;
}
}
}

public class UserAgeTaggingAdapter : IEventAdapter
Expand Down Expand Up @@ -208,7 +236,10 @@ private bool PersistIncoming(object message)

protected override bool ReceiveRecover(object message)
{
if (message is RecoveryCompleted) ;
if (message is RecoveryCompleted)
{
// skip
}
else
{
State.AddLast(message);
Expand All @@ -228,56 +259,58 @@ protected override bool ReceiveCommand(object message)
private static readonly string JournalModelTypeName = typeof(IJournalModel).FullName + ", Akka.Persistence.Tests";
private static readonly string DomainEventTypeName = typeof(IDomainEvent).FullName + ", Akka.Persistence.Tests";

private static readonly string _configFormat = @"
akka.persistence.journal {{
common-event-adapters {{
age = ""{0}""
replay-pass-through = ""{1}""
}}
inmem {{
# change to path reference $akka.persistence.journal.common-event-adapters
event-adapters {{
age = ""{0}""
replay-pass-through = ""{1}""
}}
event-adapter-bindings {{
""{2}"" = age
""{3}"" = age
}}
}}
with-actor-system {{
class = ""Akka.Persistence.Journal.MemoryJournal, Akka.Persistence""
dispatcher = default-dispatcher
dir = ""journal-1""
event-adapters {{
logging = ""{4}""
}}
event-adapters-bindings {{
""System.Object"" = logging
}}
}}
replay-pass-through-adapter-journal {{
class = ""Akka.Persistence.Journal.MemoryJournal, Akka.Persistence""
dispatcher = default-dispatcher
dir = ""journal-2""
# change to path reference $akka.persistence.journal.common-event-adapters
event-adapters {{
age = ""{0}""
replay-pass-through = ""{1}""
}}
event-adapter-bindings {{
""{2}"" = replay-pass-through
""{3}"" = replay-pass-through
}}
}}
no-adapter {{
class = ""Akka.Persistence.Journal.MemoryJournal, Akka.Persistence""
dispatcher = default-dispatcher
dir = ""journal-3""
}}
}}";
private static readonly string _configFormat = """

akka.persistence.journal {{
common-event-adapters {{
age = "{0}"
replay-pass-through = "{1}"
}}
inmem {{
# change to path reference $akka.persistence.journal.common-event-adapters
event-adapters {{
age = "{0}"
replay-pass-through = "{1}"
}}
event-adapter-bindings {{
"{2}" = age
"{3}" = age
}}
}}
with-actor-system {{
class = "Akka.Persistence.Journal.MemoryJournal, Akka.Persistence"
dispatcher = default-dispatcher
dir = "journal-1"

event-adapters {{
logging = "{4}"
}}
event-adapters-bindings {{
"System.Object" = logging
}}
}}
replay-pass-through-adapter-journal {{
class = "Akka.Persistence.Journal.MemoryJournal, Akka.Persistence"
dispatcher = default-dispatcher
dir = "journal-2"

# change to path reference $akka.persistence.journal.common-event-adapters
event-adapters {{
age = "{0}"
replay-pass-through = "{1}"
}}
event-adapter-bindings {{
"{2}" = replay-pass-through
"{3}" = replay-pass-through
}}
}}
no-adapter {{
class = "Akka.Persistence.Journal.MemoryJournal, Akka.Persistence"
dispatcher = default-dispatcher
dir = "journal-3"
}}
}}
""";

public static readonly string AdapterSpecConfig = string.Format(_configFormat,
typeof(UserAgeTaggingAdapter).FullName + ", Akka.Persistence.Tests",
Expand Down
16 changes: 5 additions & 11 deletions src/core/Akka.Persistence.Tests/PersistentActorSpec.Actors.cs
Expand Up @@ -629,7 +629,6 @@ protected override bool ReceiveCommand(object message)

internal class AsyncPersistHandlerCorrelationCheck : ExamplePersistentActor
{
private int _counter = 0;
public AsyncPersistHandlerCorrelationCheck(string name)
: base(name)
{
Expand All @@ -639,8 +638,7 @@ protected override bool ReceiveCommand(object message)
{
if (!CommonBehavior(message))
{
var cmd = message as Cmd;
if (cmd != null)
if (message is Cmd cmd)
{
PersistAsync(new Evt(cmd.Data), evt =>
{
Expand All @@ -665,8 +663,7 @@ public ValueTypeEventPersistentActor(string name)

protected override bool ReceiveCommand(object message)
{
var cmd = message as Cmd;
if (cmd != null && cmd.Data.ToString() == "a")
if (message is Cmd cmd && cmd.Data.ToString() == "a")
{
Persist(5L, i =>
{
Expand Down Expand Up @@ -725,8 +722,7 @@ public DeferringWithPersistActor(string name)

protected override bool ReceiveCommand(object message)
{
var cmd = message as Cmd;
if (cmd != null)
if (message is Cmd cmd)
{
DeferAsync("d-1", Sender.Tell);
Persist(cmd.Data + "-2", Sender.Tell);
Expand Down Expand Up @@ -771,8 +767,7 @@ public DeferringMixedCallsPPADDPADPersistActor(string name)

protected override bool ReceiveCommand(object message)
{
var cmd = message as Cmd;
if (cmd != null)
if (message is Cmd cmd)
{
Persist("p-" + cmd.Data + "-1", Sender.Tell);
PersistAsync("pa-" + cmd.Data + "-2", Sender.Tell);
Expand All @@ -796,8 +791,7 @@ public DeferringWithNoPersistCallsPersistActor(string name)

protected override bool ReceiveCommand(object message)
{
var cmd = message as Cmd;
if (cmd != null)
if (message is Cmd cmd)
{
DeferAsync("d-1", Sender.Tell);
DeferAsync("d-2", Sender.Tell);
Expand Down

0 comments on commit 3aeebb0

Please sign in to comment.