Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaned up internal ActorCell and TestKit methods #5091

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/core/Akka.TestKit/CallingThreadDispatcher.cs
Expand Up @@ -12,7 +12,7 @@
namespace Akka.TestKit
{
/// <summary>
/// TBD
/// INTERNAL API
/// </summary>
public class CallingThreadDispatcherConfigurator : MessageDispatcherConfigurator
{
Expand All @@ -36,7 +36,9 @@ public override MessageDispatcher Dispatcher()
}

/// <summary>
/// TBD
/// INTERNAL API
///
/// Used to run an actor on the foreground thread.
/// </summary>
public class CallingThreadDispatcher : MessageDispatcher
{
Expand Down
11 changes: 4 additions & 7 deletions src/core/Akka.TestKit/Internal/InternalTestActorRef.cs
Expand Up @@ -172,21 +172,18 @@ public static InternalTestActorRef Create(ActorSystem system, Props props, IActo

var dispatcher = system.Dispatchers.Lookup(props.Deploy.Dispatcher);

var supervisorLocal = supervisor as LocalActorRef;
if (supervisorLocal != null)
if (supervisor is LocalActorRef supervisorLocal)
{
supervisorLocal.Cell.ReserveChild(name);
}
else
{
var supervisorRep = supervisor as RepointableActorRef;
if (supervisorRep != null)
if (supervisor is RepointableActorRef supervisorRep)
{
var repUnderlying = supervisorRep.Underlying;
if (repUnderlying is UnstartedCell)
throw new IllegalStateException("Cannot attach a TestActor to an unstarted top-level actor, ensure that it is started by sending a message and observing the reply");
var cellUnderlying = repUnderlying as ActorCell;
if (cellUnderlying != null)
if (repUnderlying is ActorCell cellUnderlying)
{
cellUnderlying.ReserveChild(name);
}
Expand All @@ -197,7 +194,7 @@ public static InternalTestActorRef Create(ActorSystem system, Props props, IActo
}
}

MailboxType mailbox = system.Mailboxes.GetMailboxType(props, dispatcher.Configurator.Config);
var mailbox = system.Mailboxes.GetMailboxType(props, dispatcher.Configurator.Config);
var testActorRef = new InternalTestActorRef((ActorSystemImpl)system, props, dispatcher, mailbox, (IInternalActorRef)supervisor, supervisor.Path / name);

// we need to start ourselves since the creation of an actor has been split into initialization and starting
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.TestKit/TestKitBase.cs
Expand Up @@ -170,8 +170,7 @@ protected void InitializeTest(ActorSystem system, ActorSystemSetup config, strin
// Calling sync version here, since .Wait() causes deadlock
AwaitCondition(() =>
{
var repRef = testActor as IRepointableRef;
return repRef == null || repRef.IsStarted;
return !(testActor is IRepointableRef repRef) || repRef.IsStarted;
}, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(10));

if (!(this is INoImplicitSender))
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/ActorCell.cs
Expand Up @@ -315,7 +315,7 @@ void IUntypedActorContext.BecomeStacked(UntypedReceive receive)
BecomeStacked(m => { receive(m); return true; });
}

private long NewUid()
private static long NewUid()
{
// Note that this uid is also used as hashCode in ActorRef, so be careful
// to not break hashing if you change the way uid is generated
Expand Down
6 changes: 3 additions & 3 deletions src/core/Akka/Dispatch/Dispatchers.cs
Expand Up @@ -507,13 +507,13 @@ private Config Config(string id, Config appConfig)
var simpleName = id.Substring(id.LastIndexOf('.') + 1);
return IdConfig(id)
.WithFallback(appConfig)
.WithFallback(ConfigurationFactory.ParseString(string.Format("name: {0}", simpleName)))
.WithFallback(ConfigurationFactory.ParseString($"name: {simpleName}"))
.WithFallback(DefaultDispatcherConfig);
}

private Config IdConfig(string id)
private static Config IdConfig(string id)
{
return ConfigurationFactory.ParseString(string.Format("id: {0}", id));
return ConfigurationFactory.ParseString($"id: {id}");
}


Expand Down