Aaronontheweb on dev
Made cleanup call thread-safe (… (compare)
dependabot-preview[bot] on nuget
Bump System.Data.SqlClient from… (compare)
Aaronontheweb on dev
Added async API to Akka.TestKit… (compare)
@Horusiath - thanks, yeah, it sems pretty clear ideally the actor should be the sole interface to the underlying DB record. And that is with me. I just wont be able to seel converting our date purely to live within the actor state persistence store but I can se;; this.
The idea is that if, in the future, we need to interface with the data in some other way or move to another technology the data is not deeply tied to the actor implementation chosen.
This is the code:
public class ModulesActor : ReceiveActor
{
private Dictionary<string, Tuple<Props, ModuleState>> _moduleRecipes;
public ModulesActor()
{
Ready();
}
public override void AroundPreStart()
{
_moduleRecipes = new Dictionary<string, Tuple<Props, ModuleState>>();
}
public override void AroundPostStop()
{
_moduleRecipes = null;
}
protected void Ready()
{
Receive<LoadModules>(modules => Load());
Receive<ModulesLoaded>(c =>
{
_moduleRecipes = c.Modules;
});
Receive<GetModuleMeta>(whois =>
{
Sender.Tell(GetModuleMeta(whois.ModuleName));
});
Receive<CheckModuleState>(state =>
{
Sender.Tell(GetModuleState(state.ModuleName));
});
}
private ModuleState GetModuleState(string moduleName)
{
if (!_moduleRecipes.ContainsKey(moduleName))
return ModuleState.NOT_IMPLEMENTED;
return _moduleRecipes[moduleName].Item2;
}
protected override SupervisorStrategy SupervisorStrategy()
{
return new OneForOneStrategy(1,
// maxNumberOfRetries
TimeSpan.FromSeconds(30),
// withinTimeRange
exception => // localOnlyDecider
{
//Error that we cannot recover from, stop the failing actor
if (exception is NotSupportedException) return Directive.Stop;
// Error related to configuration setting
if (exception is ConfigurationErrorsException) {
return Directive.Escalate;
}
//In all other cases, just stop the failing actor
return Directive.Stop;
});
}
private ModuleMeta GetModuleMeta(string moduleName)
{
if (!_moduleRecipes.ContainsKey(moduleName)) return null;
var moduleMeta = new ModuleMeta(_moduleRecipes[moduleName].Item1,
_moduleRecipes[moduleName].Item2);
return moduleMeta;
}
private static void Load()
{
var loader = Context.ActorOf(Props.Create(() => new ModulesLoadingActor()));
loader.Forward(new LoadModules());
}
}
This is the test I am running:
public void ModulesLoaderActorShouldReturnALoadedModule()
{
ActorSystemRefs.ActorSystem = Sys;
var actorSystem = ActorSystemRefs.ActorSystem;
var moduleManager = actorSystem.ActorOf(Props.Create(() => new ModulesActor()));
moduleManager.Tell(new LoadModules());
var result = ExpectMsg<ModulesLoaded>();
Assert.NotNull(result);
moduleManager.Tell(new CheckModuleState("mtn-gh"));
var moduleMeta = ExpectMsg<ModuleMeta>();
Assert.NotNull(moduleMeta);
Assert.True(moduleMeta.State == ModuleState.ONLINE);
}
The issue I am facing is that the moduleMeta.State does not return the expected value. The first assertion works smoothly.
ActorSystemRefs.ActorSystem = Sys;
var actorSystem = ActorSystemRefs.ActorSystem;
var moduleManager = actorSystem.ActorOf(Props.Create(() => new ModulesActor()));
moduleManager.Tell(new LoadModules());
moduleManager.Tell(new CheckModuleState("mtn-gh"));
var moduleMeta = ExpectMsg<ModuleMeta>();
Assert.NotNull(moduleMeta);
Assert.True(moduleMeta.State == ModuleState.ONLINE);