diff --git a/src/Akka.sln.DotSettings b/src/Akka.sln.DotSettings
index c5ab510a684..17e3ace15b0 100644
--- a/src/Akka.sln.DotSettings
+++ b/src/Akka.sln.DotSettings
@@ -9,12 +9,13 @@
True
True
//-----------------------------------------------------------------------
-// <copyright file="$FILENAME$" company="Akka.NET Project">
-// Copyright (C) 2009-$CURRENT_YEAR$ Lightbend Inc. <http://www.lightbend.com>
-// Copyright (C) 2013-$CURRENT_YEAR$ .NET Foundation <https://github.com/akkadotnet/akka.net>
+// <copyright file="${File.FileName}" company="Akka.NET Project">
+// Copyright (C) 2009-${CurrentDate.Year} Lightbend Inc. <http://www.lightbend.com>
+// Copyright (C) 2013-${CurrentDate.Year} .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
FSM
+ True
True
True
True
diff --git a/src/contrib/cluster/Akka.DistributedData.Tests/Serialization/ReplicatorMessageSerializerSpec.cs b/src/contrib/cluster/Akka.DistributedData.Tests/Serialization/ReplicatorMessageSerializerSpec.cs
index 1300a911e79..ee56fcd02a9 100644
--- a/src/contrib/cluster/Akka.DistributedData.Tests/Serialization/ReplicatorMessageSerializerSpec.cs
+++ b/src/contrib/cluster/Akka.DistributedData.Tests/Serialization/ReplicatorMessageSerializerSpec.cs
@@ -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;
@@ -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);
diff --git a/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs b/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs
index 02e212c216f..621c422eccc 100644
--- a/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs
+++ b/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs
@@ -23,7 +23,7 @@ public class XunitAssertions : ITestKitAssertions
/// An optional object array that contains zero or more objects to format.
public void Fail(string format = "", params object[] args)
{
- Assert.True(false, string.Format(format, args));
+ Assert.Fail(string.Format(format, args));
}
///
diff --git a/src/core/Akka.Cluster.Tests.MultiNode/ClusterDeathWatchSpec.cs b/src/core/Akka.Cluster.Tests.MultiNode/ClusterDeathWatchSpec.cs
index f19063c0b03..f77fe4d189c 100644
--- a/src/core/Akka.Cluster.Tests.MultiNode/ClusterDeathWatchSpec.cs
+++ b/src/core/Akka.Cluster.Tests.MultiNode/ClusterDeathWatchSpec.cs
@@ -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}]");
}
@@ -328,10 +328,10 @@ public void An_actor_watching_a_remote_actor_in_the_cluster_must_be_able_to_shut
///
/// Used to report events to the
///
- 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)
{
@@ -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(identity =>
- {
- Context.Watch(identity.Subject);
- });
-
- Receive(terminated =>
- {
- _testActorRef.Tell(terminated.ActorRef.Path);
- });
-
- Context.ActorSelection(path2).Tell(new Identify(path2));
- }
- }
}
}
diff --git a/src/core/Akka.Persistence.Tests/AtLeastOnceDeliverySpec.cs b/src/core/Akka.Persistence.Tests/AtLeastOnceDeliverySpec.cs
index af78af772d1..173ebb07b03 100644
--- a/src/core/Akka.Persistence.Tests/AtLeastOnceDeliverySpec.cs
+++ b/src/core/Akka.Persistence.Tests/AtLeastOnceDeliverySpec.cs
@@ -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
{
diff --git a/src/core/Akka.Persistence.Tests/EndToEndEventAdapterSpec.cs b/src/core/Akka.Persistence.Tests/EndToEndEventAdapterSpec.cs
index f943741e057..bea8ce86744 100644
--- a/src/core/Akka.Persistence.Tests/EndToEndEventAdapterSpec.cs
+++ b/src/core/Akka.Persistence.Tests/EndToEndEventAdapterSpec.cs
@@ -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;
}
diff --git a/src/core/Akka.Persistence.Tests/MemoryEventAdapterSpec.cs b/src/core/Akka.Persistence.Tests/MemoryEventAdapterSpec.cs
index 5ed94476268..b2f901bf58d 100644
--- a/src/core/Akka.Persistence.Tests/MemoryEventAdapterSpec.cs
+++ b/src/core/Akka.Persistence.Tests/MemoryEventAdapterSpec.cs
@@ -50,7 +50,7 @@ public override bool Equals(object obj)
}
[Serializable]
- public sealed class NotTagged : IJournalModel, IEquatable
+ public sealed class NotTagged : IJournalModel, IEquatable, IEquatable
{
public object Payload { get; private set; }
public ISet Tags { get { return new HashSet(); } }
@@ -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 { }
@@ -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]
@@ -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
@@ -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);
@@ -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",
diff --git a/src/core/Akka.Persistence.Tests/PersistentActorSpec.Actors.cs b/src/core/Akka.Persistence.Tests/PersistentActorSpec.Actors.cs
index f71b8ded9d4..6953ccf78c1 100644
--- a/src/core/Akka.Persistence.Tests/PersistentActorSpec.Actors.cs
+++ b/src/core/Akka.Persistence.Tests/PersistentActorSpec.Actors.cs
@@ -629,7 +629,6 @@ protected override bool ReceiveCommand(object message)
internal class AsyncPersistHandlerCorrelationCheck : ExamplePersistentActor
{
- private int _counter = 0;
public AsyncPersistHandlerCorrelationCheck(string name)
: base(name)
{
@@ -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 =>
{
@@ -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 =>
{
@@ -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);
@@ -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);
@@ -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);
diff --git a/src/core/Akka.Persistence.Tests/PersistentActorSpecAsyncAwait.Actors.cs b/src/core/Akka.Persistence.Tests/PersistentActorSpecAsyncAwait.Actors.cs
index 47bd4ce156d..e7bbc23c8e3 100644
--- a/src/core/Akka.Persistence.Tests/PersistentActorSpecAsyncAwait.Actors.cs
+++ b/src/core/Akka.Persistence.Tests/PersistentActorSpecAsyncAwait.Actors.cs
@@ -22,7 +22,9 @@ public partial class PersistentActorSpecAsyncAwait
{
internal class BehaviorOneActor : ExamplePersistentActor
{
- public BehaviorOneActor(string name) : base(name) { }
+ public BehaviorOneActor(string name) : base(name)
+ {
+ }
protected override bool ReceiveCommand(object message)
{
@@ -43,10 +45,12 @@ protected bool Receiver(object message)
else if (message is DeleteMessagesSuccess)
{
if (AskedForDelete == null)
- throw new ArgumentNullException("Received DeleteMessagesSuccess without anyone asking for delete!");
+ throw new ArgumentNullException(
+ "Received DeleteMessagesSuccess without anyone asking for delete!");
AskedForDelete.Tell(message);
}
else return false;
+
return true;
}
@@ -66,6 +70,7 @@ protected override void OnPersistFailure(Exception cause, object @event, long se
base.OnPersistFailure(cause, @event, sequenceNr);
}
}
+
internal class Cmd
{
public Cmd(object data)
@@ -97,9 +102,6 @@ public override string ToString()
}
-
-
-
internal class LatchCmd : INoSerializationVerificationNeeded
{
public LatchCmd(TestLatch latch, object data)
@@ -172,6 +174,7 @@ protected bool CommonBehavior(object message)
});
}
else return false;
+
return true;
}
}
@@ -179,7 +182,9 @@ protected bool CommonBehavior(object message)
internal class BehaviorTwoActor : ExamplePersistentActor
{
- public BehaviorTwoActor(string name) : base(name) { }
+ public BehaviorTwoActor(string name) : base(name)
+ {
+ }
protected override bool ReceiveCommand(object message)
{
@@ -199,12 +204,16 @@ protected bool Receiver(object message)
});
return true;
}
+
return false;
}
}
+
internal class BehaviorThreeActor : ExamplePersistentActor
{
- public BehaviorThreeActor(string name) : base(name) { }
+ public BehaviorThreeActor(string name) : base(name)
+ {
+ }
protected override bool ReceiveCommand(object message)
{
@@ -224,13 +233,16 @@ protected bool Receiver(object message)
});
return true;
}
+
return false;
}
}
internal class ChangeBehaviorInLastEventHandlerActor : ExamplePersistentActor
{
- public ChangeBehaviorInLastEventHandlerActor(string name) : base(name) { }
+ public ChangeBehaviorInLastEventHandlerActor(string name) : base(name)
+ {
+ }
protected override bool ReceiveCommand(object message)
{
@@ -250,6 +262,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
@@ -270,13 +283,16 @@ protected bool NewBehavior(object message)
});
return true;
}
+
return false;
}
}
internal class ChangeBehaviorInFirstEventHandlerActor : ExamplePersistentActor
{
- public ChangeBehaviorInFirstEventHandlerActor(string name) : base(name) { }
+ public ChangeBehaviorInFirstEventHandlerActor(string name) : base(name)
+ {
+ }
protected override bool ReceiveCommand(object message)
{
@@ -296,6 +312,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
@@ -316,12 +333,16 @@ protected bool NewBehavior(object message)
});
return true;
}
+
return false;
}
}
+
internal class ChangeBehaviorInCommandHandlerFirstActor : ExamplePersistentActor
{
- public ChangeBehaviorInCommandHandlerFirstActor(string name) : base(name) { }
+ public ChangeBehaviorInCommandHandlerFirstActor(string name) : base(name)
+ {
+ }
protected override bool ReceiveCommand(object message)
{
@@ -338,6 +359,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
@@ -355,13 +377,16 @@ protected bool NewBehavior(object message)
});
return true;
}
+
return false;
}
}
internal class ChangeBehaviorInCommandHandlerLastActor : ExamplePersistentActor
{
- public ChangeBehaviorInCommandHandlerLastActor(string name) : base(name) { }
+ public ChangeBehaviorInCommandHandlerLastActor(string name) : base(name)
+ {
+ }
protected override bool ReceiveCommand(object message)
{
@@ -378,6 +403,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
@@ -395,6 +421,7 @@ protected bool NewBehavior(object message)
});
return true;
}
+
return false;
}
}
@@ -402,6 +429,7 @@ protected bool NewBehavior(object message)
internal class SnapshottingPersistentActor : ExamplePersistentActor
{
protected readonly IActorRef Probe;
+
public SnapshottingPersistentActor(string name, IActorRef probe)
: base(name)
{
@@ -419,6 +447,7 @@ protected override bool ReceiveRecover(object message)
}
else return false;
}
+
return true;
}
@@ -447,7 +476,10 @@ internal class SnapshottingBecomingPersistentActor : SnapshottingPersistentActor
{
public const string Message = "It's changing me";
public const string Response = "I'm becoming";
- public SnapshottingBecomingPersistentActor(string name, IActorRef probe) : base(name, probe) { }
+
+ public SnapshottingBecomingPersistentActor(string name, IActorRef probe) : base(name, probe)
+ {
+ }
private bool BecomingRecover(object message)
{
@@ -459,6 +491,7 @@ private bool BecomingRecover(object message)
Self.Tell(Message);
return base.ReceiveRecover(message);
}
+
return false;
}
@@ -478,7 +511,9 @@ private bool BecomingCommand(object message)
internal class ReplyInEventHandlerActor : ExamplePersistentActor
{
- public ReplyInEventHandlerActor(string name) : base(name) { }
+ public ReplyInEventHandlerActor(string name) : base(name)
+ {
+ }
protected override bool ReceiveCommand(object message)
{
@@ -492,6 +527,7 @@ protected override bool ReceiveCommand(object message)
});
}
else return false;
+
return true;
}
}
@@ -499,6 +535,7 @@ protected override bool ReceiveCommand(object message)
internal class AsyncPersistActor : ExamplePersistentActor
{
private int _counter = 0;
+
public AsyncPersistActor(string name)
: base(name)
{
@@ -517,16 +554,15 @@ protected override bool ReceiveCommand(object message)
await Task.Delay(100);
Sender.Tell(cmd.Data);
- PersistAsync(new Evt(cmd.Data.ToString() + "-" + (++_counter)), evt =>
- {
- Sender.Tell(evt.Data);
- });
+ PersistAsync(new Evt(cmd.Data.ToString() + "-" + (++_counter)),
+ evt => { Sender.Tell(evt.Data); });
});
return true;
}
}
else return true;
+
return false;
}
@@ -542,6 +578,7 @@ protected override void OnPersistFailure(Exception cause, object @event, long se
internal class AsyncPersistThreeTimesActor : ExamplePersistentActor
{
private int _counter = 0;
+
public AsyncPersistThreeTimesActor(string name)
: base(name)
{
@@ -562,10 +599,8 @@ protected override bool ReceiveCommand(object message)
Sender.Tell(cmd.Data);
for (int i = 1; i <= 3; i++)
{
- PersistAsync(new Evt(cmd.Data.ToString() + "-" + (++_counter)), evt =>
- {
- Sender.Tell("a" + evt.Data.ToString().Substring(1));
- });
+ PersistAsync(new Evt(cmd.Data.ToString() + "-" + (++_counter)),
+ evt => { Sender.Tell("a" + evt.Data.ToString().Substring(1)); });
}
});
@@ -573,6 +608,7 @@ protected override bool ReceiveCommand(object message)
}
}
else return true;
+
return false;
}
}
@@ -580,6 +616,7 @@ protected override bool ReceiveCommand(object message)
internal class AsyncPersistSameEventTwiceActor : ExamplePersistentActor
{
private AtomicCounter _sendMessageCounter = new(0);
+
public AsyncPersistSameEventTwiceActor(string name)
: base(name)
{
@@ -606,13 +643,16 @@ protected override bool ReceiveCommand(object message)
Sender.Tell(evt.Data.ToString() + "-a-" + _sendMessageCounter.IncrementAndGet());
});
- PersistAsync(@event, evt => Sender.Tell(evt.Data.ToString() + "-b-" + _sendMessageCounter.IncrementAndGet()));
+ PersistAsync(@event,
+ evt => Sender.Tell(evt.Data.ToString() + "-b-" +
+ _sendMessageCounter.IncrementAndGet()));
});
return true;
}
}
else return true;
+
return false;
}
}
@@ -658,6 +698,7 @@ protected override bool ReceiveCommand(object message)
}
}
else return true;
+
return false;
}
}
@@ -665,6 +706,7 @@ protected override bool ReceiveCommand(object message)
internal class AsyncPersistAndPersistMixedSyncAsyncSyncActor : ExamplePersistentActor
{
private int _counter = 0;
+
public AsyncPersistAndPersistMixedSyncAsyncSyncActor(string name)
: base(name)
{
@@ -693,6 +735,7 @@ protected override bool ReceiveCommand(object message)
}
}
else return true;
+
return false;
}
}
@@ -727,13 +770,13 @@ protected override bool ReceiveCommand(object message)
}
}
else return true;
+
return false;
}
}
internal class AsyncPersistHandlerCorrelationCheck : ExamplePersistentActor
{
- private int _counter = 0;
public AsyncPersistHandlerCorrelationCheck(string name)
: base(name)
{
@@ -743,25 +786,23 @@ protected override bool ReceiveCommand(object message)
{
if (!CommonBehavior(message))
{
- var cmd = message as Cmd;
- if (cmd != null)
+ if (message is not Cmd cmd) return false;
+ RunTask(async () =>
{
- RunTask(async () =>
+ await Task.Yield();
+ await Task.Delay(10);
+ PersistAsync(new Evt(cmd.Data), evt =>
{
- await Task.Yield();
- await Task.Delay(10);
- PersistAsync(new Evt(cmd.Data), evt =>
- {
- if (!cmd.Data.Equals(evt.Data)) Sender.Tell("Expected " + cmd.Data + " but got " + evt.Data);
- if ("done" != evt.Data.ToString()) Sender.Tell("done");
- });
+ if (!cmd.Data.Equals(evt.Data))
+ Sender.Tell("Expected " + cmd.Data + " but got " + evt.Data);
+ if ("done" != evt.Data.ToString()) Sender.Tell("done");
});
+ });
- return true;
- }
+ return true;
}
- else return true;
- return false;
+
+ return true;
}
}
@@ -774,17 +815,14 @@ 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")
{
RunTask(async () =>
{
await Task.Yield();
await Task.Delay(100);
- Persist(5L, i =>
- {
- Sender.Tell(i);
- });
+ // ReSharper disable once MethodHasAsyncOverload
+ Persist(5L, i => { Sender.Tell(i); });
});
return true;
}
@@ -812,20 +850,23 @@ protected override bool ReceiveRecover(object message)
protected bool SendingRecover(object message)
{
- if (message is SnapshotOffer)
- {
- // sending ourself a normal message tests
- // that we stash them until recovery is complete
- Self.Tell("I am the stashed");
- base.ReceiveRecover(message);
- }
- else if (message is RecoveryCompleted)
+ switch (message)
{
- Probe.Tell(RecoveryCompleted.Instance);
- Self.Tell("I am the recovered");
- UpdateState(new Evt(RecoveryCompleted.Instance));
+ case SnapshotOffer:
+ // sending ourself a normal message tests
+ // that we stash them until recovery is complete
+ Self.Tell("I am the stashed");
+ base.ReceiveRecover(message);
+ break;
+ case RecoveryCompleted:
+ Probe.Tell(RecoveryCompleted.Instance);
+ Self.Tell("I am the recovered");
+ UpdateState(new Evt(RecoveryCompleted.Instance));
+ break;
+ default:
+ return false;
}
- else return false;
+
return true;
}
}
@@ -847,6 +888,7 @@ protected override bool ReceiveCommand(object message)
await Task.Yield();
await Task.Delay(100);
DeferAsync("d-1", Sender.Tell);
+ // ReSharper disable once MethodHasAsyncOverload
Persist(cmd.Data + "-2", Sender.Tell);
DeferAsync("d-3", Sender.Tell);
DeferAsync("d-4", Sender.Tell);
@@ -854,6 +896,7 @@ protected override bool ReceiveCommand(object message)
return true;
}
+
return false;
}
}
@@ -882,6 +925,7 @@ protected override bool ReceiveCommand(object message)
return true;
}
+
return false;
}
}
@@ -912,6 +956,7 @@ protected override bool ReceiveCommand(object message)
return true;
}
+
return false;
}
}
@@ -940,6 +985,7 @@ protected override bool ReceiveCommand(object message)
return true;
}
+
return false;
}
}
@@ -979,6 +1025,7 @@ protected override bool ReceiveCommand(object message)
else if (message is string)
Sender.Tell(message.ToString());
else return false;
+
return true;
}
}
@@ -986,9 +1033,9 @@ protected override bool ReceiveCommand(object message)
internal class RecoverMessageCausedRestart : ExamplePersistentActor
{
private IActorRef _master;
+
public RecoverMessageCausedRestart(string name) : base(name)
{
-
}
protected override bool ReceiveCommand(object message)
@@ -998,6 +1045,7 @@ protected override bool ReceiveCommand(object message)
_master = Sender;
throw new TestException("boom");
}
+
return false;
}
@@ -1041,6 +1089,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
}
@@ -1078,6 +1127,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
}
@@ -1115,6 +1165,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
}
@@ -1152,6 +1203,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
}
@@ -1183,7 +1235,7 @@ protected override bool ReceiveCommand(object message)
{
_probe.Tell(inner);
Thread.Sleep(1000); // really long wait here
- // the next incoming command must be handled by the following function
+ // the next incoming command must be handled by the following function
Context.Become(_ =>
{
Sender.Tell("done");
@@ -1194,6 +1246,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
}
@@ -1242,6 +1295,7 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
}
@@ -1290,9 +1344,9 @@ protected override bool ReceiveCommand(object message)
});
return true;
}
+
return false;
}
}
}
-}
-
+}
\ No newline at end of file
diff --git a/src/core/Akka.Persistence.Tests/SnapshotSpec.cs b/src/core/Akka.Persistence.Tests/SnapshotSpec.cs
index fca49477ca1..d196cf4a035 100644
--- a/src/core/Akka.Persistence.Tests/SnapshotSpec.cs
+++ b/src/core/Akka.Persistence.Tests/SnapshotSpec.cs
@@ -364,7 +364,9 @@ public void PersistentActor_should_support_single_snapshot_deletions()
pref.Tell("done");
var offer = ExpectMsg(o => o.Metadata.PersistenceId == persistenceId && o.Metadata.SequenceNr == 4);
- (offer.Snapshot as IEnumerable).Reverse().ShouldOnlyContainInOrder("a-1", "b-2", "c-3", "d-4");
+ var strSnapshot1 = offer.Snapshot as IEnumerable;
+ Assert.NotNull(strSnapshot1);
+ strSnapshot1.Reverse().ShouldOnlyContainInOrder("a-1", "b-2", "c-3", "d-4");
ExpectMsg();
ExpectMsg("done");
@@ -376,7 +378,9 @@ public void PersistentActor_should_support_single_snapshot_deletions()
ActorOf(() => new DeleteSnapshotTestActor(Name, new Recovery(SnapshotSelectionCriteria.Latest, 4), TestActor));
var offer2 = ExpectMsg(o => o.Metadata.PersistenceId == persistenceId && o.Metadata.SequenceNr == 2);
- (offer2.Snapshot as IEnumerable).Reverse().ShouldOnlyContainInOrder("a-1", "b-2");
+ var strSnapshot2 = offer2.Snapshot as IEnumerable;
+ Assert.NotNull(strSnapshot2);
+ strSnapshot2.Reverse().ShouldOnlyContainInOrder("a-1", "b-2");
ExpectMsg("c-3");
ExpectMsg("d-4");
@@ -395,12 +399,12 @@ public void PersistentActor_should_support_bulk_snapshot_deletions()
// recover persistentActor and the delete first three (= all) snapshots
pref.Tell(new DeleteMany(new SnapshotSelectionCriteria(4, DateTime.MaxValue)));
- ExpectMsgPf("offer", o =>
+ ExpectMsgOf("offer", o =>
{
- var offer = o as SnapshotOffer;
- if (offer != null)
+ if (o is SnapshotOffer offer)
{
var snapshot = offer.Snapshot as IEnumerable;
+ Assert.NotNull(snapshot);
snapshot.Reverse().ShouldOnlyContainInOrder("a-1", "b-2", "c-3", "d-4");
Assert.Equal(persistenceId, offer.Metadata.PersistenceId);
@@ -408,7 +412,8 @@ public void PersistentActor_should_support_bulk_snapshot_deletions()
return offer;
}
- else return null;
+
+ return null;
});
ExpectMsg();
diff --git a/src/core/Akka.Streams.TestKit.Tests/StreamTestKitSpec.cs b/src/core/Akka.Streams.TestKit.Tests/StreamTestKitSpec.cs
index aa87a4d7416..17a995e71e0 100644
--- a/src/core/Akka.Streams.TestKit.Tests/StreamTestKitSpec.cs
+++ b/src/core/Akka.Streams.TestKit.Tests/StreamTestKitSpec.cs
@@ -6,6 +6,7 @@
//-----------------------------------------------------------------------
using System;
+using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Akka.Streams.Dsl;
@@ -56,11 +57,11 @@ await Source.From(Enumerable.Range(1, 3).Select(i =>
.ToStrictAsync(TimeSpan.FromMilliseconds(300))
.ToListAsync();
})
- .Should().ThrowAsync();
+ .Should().ThrowAsync();
var error = err.Subject.First();
var aggregateException = error.InnerException;
- aggregateException.InnerException.Message.Should().Contain("Boom!");
+ aggregateException!.InnerException!.Message.Should().Contain("Boom!");
error.Message.Should().Contain("1, 2");
}
@@ -105,7 +106,7 @@ await Source.From(Enumerable.Range(1, 4)).RunWith(this.SinkProbe(), Materia
.Request(4)
.ExpectNextOrError(100, Ex())
.ExecuteAsync();
- }).Should().ThrowAsync().WithMessage("*OnNext(100)*");
+ }).Should().ThrowAsync().WithMessage("*OnNext(100)*");
}
[Fact]
@@ -127,7 +128,7 @@ await Source.From(Enumerable.Range(1, 4)).RunWith(this.SinkProbe(), Materia
.AsyncBuilder()
.Request(1)
.ExpectErrorAsync();
- }).Should().ThrowAsync().WithMessage("*OnNext(1)*");
+ }).Should().ThrowAsync().WithMessage("*OnNext(1)*");
}
[Fact]
@@ -140,7 +141,7 @@ await Source.Failed(Ex()).RunWith(this.SinkProbe(), Materializer)
.Request(1)
.ExpectComplete()
.ExecuteAsync();
- }).Should().ThrowAsync().WithMessage("*OnError(Boom!)*");
+ }).Should().ThrowAsync().WithMessage("*OnError(Boom!)*");
}
[Fact]
@@ -153,7 +154,7 @@ await Source.From(Enumerable.Range(1, 4)).RunWith(this.SinkProbe(), Materia
.Request(1)
.ExpectComplete()
.ExecuteAsync();
- }).Should().ThrowAsync().WithMessage("*OnNext(1)*");
+ }).Should().ThrowAsync().WithMessage("*OnNext(1)*");
}
[Fact]
@@ -196,7 +197,7 @@ await Source.Single(1).RunWith(this.SinkProbe(), Materializer)
.AsyncBuilder()
.Request(1)
.ExpectNextAsync(i => i == 2);
- }).Should().ThrowAsync().WithMessage("Got a message of the expected type*");
+ }).Should().ThrowAsync().WithMessage("Got a message of the expected type*");
}
[Fact]
@@ -230,7 +231,7 @@ await Source.Single(1).RunWith(this.SinkProbe(), Materializer)
.Request(1)
.MatchNext(i => i == 2)
.ExecuteAsync();
- }).Should().ThrowAsync().WithMessage("Got a message of the expected type*");
+ }).Should().ThrowAsync().WithMessage("Got a message of the expected type*");
}
[Fact]
diff --git a/src/core/Akka.Streams.TestKit/Utils.cs b/src/core/Akka.Streams.TestKit/Utils.cs
index bc93467bd13..20688b1531c 100644
--- a/src/core/Akka.Streams.TestKit/Utils.cs
+++ b/src/core/Akka.Streams.TestKit/Utils.cs
@@ -70,7 +70,7 @@ public static async Task AssertAllStagesStoppedAsync(
{
timeout ??= 20.Seconds();
var result = await block().ShouldCompleteWithin(timeout.Value);
- if (!(materializer is ActorMaterializerImpl impl))
+ if (materializer is not ActorMaterializerImpl impl)
return result;
var probe = spec.CreateTestProbe(impl.System);
diff --git a/src/core/Akka.TestKit.Tests/TestEventListenerTests/AllTestForEventFilterBase.cs b/src/core/Akka.TestKit.Tests/TestEventListenerTests/AllTestForEventFilterBase.cs
index aa183a5ecaa..8e78a1d1508 100644
--- a/src/core/Akka.TestKit.Tests/TestEventListenerTests/AllTestForEventFilterBase.cs
+++ b/src/core/Akka.TestKit.Tests/TestEventListenerTests/AllTestForEventFilterBase.cs
@@ -264,7 +264,7 @@ await _testingEventFilter.ForLogLevel(LogLevel).ExpectAsync(2, TimeSpan.FromMill
LogMessage("whatever");
return Task.CompletedTask;
});
- }).Should().ThrowAsync().WithMessage("Timeout (*");
+ }).Should().ThrowAsync().WithMessage("Timeout (*");
}
[Fact]
diff --git a/src/core/Akka.TestKit.Tests/TestEventListenerTests/ExceptionEventFilterTests.cs b/src/core/Akka.TestKit.Tests/TestEventListenerTests/ExceptionEventFilterTests.cs
index e65bec61ea3..b202e1e0767 100644
--- a/src/core/Akka.TestKit.Tests/TestEventListenerTests/ExceptionEventFilterTests.cs
+++ b/src/core/Akka.TestKit.Tests/TestEventListenerTests/ExceptionEventFilterTests.cs
@@ -127,7 +127,7 @@ await EventFilter.Exception().ExpectAsync(2, () => {
return Task.CompletedTask;
});
})
- .Should().ThrowAsync().WithMessage("Received 1 message too many.*");
+ .Should().ThrowAsync().WithMessage("Received 1 message too many.*");
}
[Fact]
diff --git a/src/core/Akka.TestKit.Tests/TestKitBaseTests/DilatedTests.cs b/src/core/Akka.TestKit.Tests/TestKitBaseTests/DilatedTests.cs
index 9cd710f125f..5db4419d8ee 100644
--- a/src/core/Akka.TestKit.Tests/TestKitBaseTests/DilatedTests.cs
+++ b/src/core/Akka.TestKit.Tests/TestKitBaseTests/DilatedTests.cs
@@ -40,7 +40,7 @@ public async Task AwaitConditionAsync_should_dilate_timeout()
{
var stopwatch = Stopwatch.StartNew();
await Awaiting(() => AwaitConditionAsync(() => Task.FromResult(false), TimeSpan.FromMilliseconds(Timeout)))
- .Should().ThrowAsync();
+ .Should().ThrowAsync();
stopwatch.Stop();
AssertDilated(stopwatch.ElapsedMilliseconds, $"Expected the timeout to be {ExpectedTimeout} but in fact it was {stopwatch.ElapsedMilliseconds}.");
}
@@ -70,7 +70,7 @@ public async Task FishForMessageAsync_should_dilate_timeout()
{
var stopwatch = Stopwatch.StartNew();
await Awaiting(async () => await FishForMessageAsync(_=>false, TimeSpan.FromMilliseconds(Timeout)))
- .Should().ThrowAsync();
+ .Should().ThrowAsync();
stopwatch.Stop();
AssertDilated(stopwatch.ElapsedMilliseconds, $"Expected the timeout to be {ExpectedTimeout} but in fact it was {stopwatch.ElapsedMilliseconds}.");
}
diff --git a/src/core/Akka.Tests/Actor/AskSpec.cs b/src/core/Akka.Tests/Actor/AskSpec.cs
index 8df4ef668de..2cf85d9c3b2 100644
--- a/src/core/Akka.Tests/Actor/AskSpec.cs
+++ b/src/core/Akka.Tests/Actor/AskSpec.cs
@@ -214,7 +214,7 @@ public async Task Ask_should_honor_config_specified_timeout()
try
{
await actor.Ask("timeout");
- Assert.True(false, "the ask should have timed out with default timeout");
+ Assert.Fail("the ask should have timed out with default timeout");
}
catch (AskTimeoutException e)
{