Skip to content

Commit

Permalink
[fixes] API Tests (#6746)
Browse files Browse the repository at this point in the history
* use char based overrides

* [Fixes] API Tests

---------

Co-authored-by: Simon Cropp <[email protected]>
  • Loading branch information
eaba and SimonCropp authored May 9, 2023
1 parent 7dbfc94 commit 15ab3b1
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ protected override bool Receive(object message)
private bool IsAsk()
{
var pathElements = _client.Path.Elements;
return pathElements.Count == 2 && pathElements[0] == "temp" && pathElements.Last().StartsWith("$");
return pathElements.Count == 2 && pathElements[0] == "temp" && pathElements.Last().StartsWith('$');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ private IEnumerable<string> GetCurrentTopics()
if (key.StartsWith(topicPrefix))
{
var topic = key.Substring(topicPrefix.Length + 1);
if (!topic.Contains("/"))
if (!topic.Contains('/'))
{
yield return Uri.EscapeDataString(topic);
}
Expand Down
2 changes: 1 addition & 1 deletion src/contrib/cluster/Akka.DistributedData/Replicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public Replicator(ReplicatorSettings settings)
var durableWildcardsBuilder = ImmutableHashSet<string>.Empty.ToBuilder();
foreach (var key in settings.DurableKeys)
{
if (key.EndsWith("*"))
if (key.EndsWith('*'))
durableWildcardsBuilder.Add(key.Substring(0, key.Length - 1));
else
durableKeysBuilder.Add(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private class ReceiveAnyPersistentActor : TestReceivePersistentActor
{
public ReceiveAnyPersistentActor(string pid) : base(pid)
{
Command<string>(str => str.StartsWith("s"), e =>
Command<string>(str => str.StartsWith('s'), e =>
{
Persist(e, h =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.DistributedData")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.MultiNodeTestRunner.Shared.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Persistence")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Persistence.Sql.TestKit")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Persistence.TCK")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Persistence.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote.TestKit")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote.TestKit.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote.Tests.MultiNode")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.DistributedData")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.MultiNodeTestRunner.Shared.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Persistence")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Persistence.Sql.TestKit")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Persistence.TCK")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Persistence.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote.TestKit")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote.TestKit.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Remote.Tests.MultiNode")]
Expand Down
8 changes: 4 additions & 4 deletions src/core/Akka.Persistence.Tests/EndToEndEventAdapterSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public object ToJournal(object evt)
public IEventSequence FromJournal(object evt, string manifest)
{
Json m;
if ((m = evt as Json) != null && m.Payload.ToString().StartsWith("a"))
if ((m = evt as Json) != null && m.Payload.ToString().StartsWith('a'))
return EventSequence.Single(new A(m.Payload));
else
return EventSequence.Empty;
Expand All @@ -145,7 +145,7 @@ public object ToJournal(object evt)
public IEventSequence FromJournal(object evt, string manifest)
{
Json m;
if ((m = evt as Json) != null && m.Payload.ToString().StartsWith("a"))
if ((m = evt as Json) != null && m.Payload.ToString().StartsWith('a'))
return EventSequence.Single(new NewA(m.Payload));
else
return EventSequence.Empty;
Expand All @@ -172,7 +172,7 @@ public object ToJournal(object evt)
public IEventSequence FromJournal(object evt, string manifest)
{
Json m;
if ((m = evt as Json) != null && m.Payload.ToString().StartsWith("b"))
if ((m = evt as Json) != null && m.Payload.ToString().StartsWith('b'))
return EventSequence.Single(new B(m.Payload));
else
return EventSequence.Empty;
Expand All @@ -199,7 +199,7 @@ public object ToJournal(object evt)
public IEventSequence FromJournal(object evt, string manifest)
{
Json m;
if ((m = evt as Json) != null && m.Payload.ToString().StartsWith("b"))
if ((m = evt as Json) != null && m.Payload.ToString().StartsWith('b'))
return EventSequence.Single(new NewB(m.Payload));
else
return EventSequence.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TestJournal(Config config)
_testValue = config.GetString("test-value", null);
}

protected override bool AroundReceive(Receive receive, object message)
protected internal override bool AroundReceive(Receive receive, object message)
{
if (message is TestRequest)
{
Expand All @@ -57,7 +57,7 @@ public TestSnapshotStore(Config config)
_testValue = config.GetString("test-value", null);
}

protected override bool AroundReceive(Receive receive, object message)
protected internal override bool AroundReceive(Receive receive, object message)
{
if (message is TestRequest)
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka.Persistence.Tests/PersistenceConfigSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TestJournal(Config config)
_testValue = config.GetString("test-value", null);
}

protected override bool AroundReceive(Receive receive, object message)
protected internal override bool AroundReceive(Receive receive, object message)
{
if (message is TestRequest)
{
Expand All @@ -57,7 +57,7 @@ public TestSnapshotStore(Config config)
_testValue = config.GetString("test-value", null);
}

protected override bool AroundReceive(Receive receive, object message)
protected internal override bool AroundReceive(Receive receive, object message)
{
if (message is TestRequest)
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka.Persistence.Tests/PersistentActorSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ public void PersistentActor_should_allow_multiple_PersistAsyncs_with_nested_Pers
pref.Tell("b");

var msgs = ReceiveN(10).Select(m => m.ToString()).ToArray();
var amsgs = msgs.Where(m => m.StartsWith("a")).ToArray();
var bmsgs = msgs.Where(m => m.StartsWith("b")).ToArray();
var amsgs = msgs.Where(m => m.StartsWith('a')).ToArray();
var bmsgs = msgs.Where(m => m.StartsWith('b')).ToArray();
amsgs.ShouldOnlyContainInOrder("a", "a-outer-1", "a-outer-2", "a-inner-1", "a-inner-2");
bmsgs.ShouldOnlyContainInOrder("b", "b-outer-1", "b-outer-2", "b-inner-1", "b-inner-2");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ public void PersistentActor_should_allow_multiple_PersistAsyncs_with_nested_Pers
pref.Tell("b");

var msgs = ReceiveN(10).Select(m => m.ToString()).ToArray();
var amsgs = msgs.Where(m => m.StartsWith("a")).ToArray();
var bmsgs = msgs.Where(m => m.StartsWith("b")).ToArray();
var amsgs = msgs.Where(m => m.StartsWith('a')).ToArray();
var bmsgs = msgs.Where(m => m.StartsWith('b')).ToArray();
amsgs.ShouldOnlyContainInOrder("a", "a-outer-1", "a-outer-2", "a-inner-1", "a-inner-2");
bmsgs.ShouldOnlyContainInOrder("b", "b-outer-1", "b-outer-2", "b-inner-1", "b-inner-2");
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Persistence/AtLeastOnceDelivery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void Deliver(ActorPath destination, Func<long, object> deliveryMessageMap
/// <exception cref="NotSupportedException">TBD</exception>
public void Deliver(ActorSelection destination, Func<long, object> deliveryMessageMapper)
{
var isWildcardSelection = destination.PathString.Contains("*");
var isWildcardSelection = destination.PathString.Contains('*');
if (isWildcardSelection)
throw new NotSupportedException(
"Delivering to wildcard actor selections is not supported by AtLeastOnceDelivery. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void Deliver(ActorPath destination, Func<long, object> deliveryMessageMap
/// </exception>
public void Deliver(ActorSelection destination, Func<long, object> deliveryMessageMapper)
{
var isWildcardSelection = destination.PathString.Contains("*");
var isWildcardSelection = destination.PathString.Contains('*');
if (isWildcardSelection)
throw new NotSupportedException(
"Delivering to wildcard actor selections is not supported by AtLeastOnceDelivery. " +
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Remote.TestKit/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void Initialize(string[] args)
var fixedArgs = new List<string>();
for (var i = 1; i < args.Length - 1; ++i)
{
if (args[i].Equals("-Dmultinode") && args[i + 1].StartsWith("."))
if (args[i].Equals("-Dmultinode") && args[i + 1].StartsWith('.'))
{
fixedArgs.Add(args[i] + args[i+1]);
++i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected override string Compute(string k)

protected override bool IsCacheable(string v)
{
return !v.StartsWith("#");
return !v.StartsWith('#');
}

public int InternalProbeDistanceOf(int idealSlot, int actualSlot)
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public async Task GroupBy_must_fail_when_key_function_returns_null()
await this.AssertAllStagesStoppedAsync(async () =>
{
var source = (Source<IEnumerable<string>, NotUsed>)Source.From(new[] { "Aaa", "Abb", "Bcc", "Cdd", "Cee" })
.GroupBy(3, s => s.StartsWith("A") ? null : s.Substring(0, 1))
.GroupBy(3, s => s.StartsWith('A') ? null : s.Substring(0, 1))
.Grouped(10)
.MergeSubstreams();
var down = source.RunWith(this.SinkProbe<IEnumerable<string>>(), Materializer);
Expand Down
32 changes: 16 additions & 16 deletions src/core/Akka.Streams.Tests/Dsl/UnfoldResourceSourceSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ await this.AssertAllStagesStoppedAsync(async() => {
public async Task A_UnfoldResourceSource_must_continue_when_strategy_is_resume_and_exception_happened()
{
await this.AssertAllStagesStoppedAsync(async() => {
var p = Source.UnfoldResource(_open, reader =>
{
var s = reader.ReadLine();
if (s != null && s.Contains("b"))
throw new TestException("");
return s ?? Option<string>.None;
}, Close)
.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider))
var p = Source.UnfoldResource(_open, reader =>
{
var s = reader.ReadLine();
if (s != null && s.Contains('b'))
throw new TestException("");
return s ?? Option<string>.None;
}, Close)
.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider))
.RunWith(Sink.AsPublisher<string>(false), Materializer);
var c = this.CreateManualSubscriberProbe<string>();

Expand All @@ -127,14 +127,14 @@ await this.AssertAllStagesStoppedAsync(async() => {
public async Task A_UnfoldResourceSource_must_close_and_open_stream_again_when_strategy_is_restart()
{
await this.AssertAllStagesStoppedAsync(async() => {
var p = Source.UnfoldResource(_open, reader =>
{
var s = reader.ReadLine();
if (s != null && s.Contains("b"))
throw new TestException("");
return s ?? Option<string>.None;
}, Close)
.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.RestartingDecider))
var p = Source.UnfoldResource(_open, reader =>
{
var s = reader.ReadLine();
if (s != null && s.Contains('b'))
throw new TestException("");
return s ?? Option<string>.None;
}, Close)
.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.RestartingDecider))
.RunWith(Sink.AsPublisher<string>(false), Materializer);
var c = this.CreateManualSubscriberProbe<string>();

Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Streams.Tests/Dsl/WithContextUsageSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Context_propagation_used_for_committing_offsets_must_only_commit_fil
{
var input = GenInput(0, 10);

Func<Record, bool> f = record => record.Key.EndsWith("2");
Func<Record, bool> f = record => record.Key.EndsWith('2');

var expectedOffsets = input.Where(cm => f(cm.Record)).Select(cm => new Offset(cm.Offset.Offset)).ToArray();
expectedOffsets = expectedOffsets.Take(expectedOffsets.Length - 1).ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/ActorPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override int GetHashCode()
/// <returns>TBD</returns>
public static bool IsValidPathElement(string s)
{
return !string.IsNullOrEmpty(s) && !s.StartsWith("$") && Validate(s);
return !string.IsNullOrEmpty(s) && !s.StartsWith('$') && Validate(s);
}

private static bool IsValidChar(char c) => (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka/Actor/ActorSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public ActorSelection(IActorRef anchor, IEnumerable<string> elements)
case null:
case "":
break;
case "**":
case "**":
list.Add(SelectChildRecursive.Instance);
hasDoubleWildcard = true;
break;
case string e when e.Contains("?") || e.Contains("*"):
case string e when e.Contains('?') || e.Contains('*'):
list.Add(new SelectChildPattern(e));
break;
case string and "..":
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public static IEnumerable<string> Unapply(string addr)
if (!isRelative) return null;

var finalAddr = addr;
if (!addr.StartsWith("/"))
if (!addr.StartsWith('/'))
{
//hack to cause the URI not to explode when we're only given an actor name
finalAddr = "/" + addr;
Expand Down
3 changes: 3 additions & 0 deletions src/core/Akka/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
[assembly: InternalsVisibleTo("Akka.TestKit")]
[assembly: InternalsVisibleTo("Akka.TestKit.Tests")]
[assembly: InternalsVisibleTo("Akka.Remote")]
[assembly: InternalsVisibleTo("Akka.Remote.TestKit")]
[assembly: InternalsVisibleTo("Akka.Remote.Tests")]
[assembly: InternalsVisibleTo("Akka.Remote.Tests.MultiNode")]
[assembly: InternalsVisibleTo("Akka.Remote.TestKit.Tests")]
Expand All @@ -43,6 +44,8 @@
[assembly: InternalsVisibleTo("Akka.Cluster.Tools")]
[assembly: InternalsVisibleTo("Akka.DistributedData")]
[assembly: InternalsVisibleTo("Akka.Persistence")]
[assembly: InternalsVisibleTo("Akka.Persistence.Sql.TestKit")]
[assembly: InternalsVisibleTo("Akka.Persistence.Tests")]
[assembly: InternalsVisibleTo("Akka.Streams")]
[assembly: InternalsVisibleTo("Akka.Streams.Tests")]
[assembly: InternalsVisibleTo("Akka.Benchmarks")]
Expand Down
2 changes: 1 addition & 1 deletion src/examples/Chat/ChatClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void Main(string[] args)
while (true)
{
var input = Console.ReadLine();
if (input.StartsWith("/"))
if (input.StartsWith('/'))
{
var parts = input.Split(' ');
var cmd = parts[0].ToLowerInvariant();
Expand Down

0 comments on commit 15ab3b1

Please sign in to comment.