/// <summary> /// Loads from embedded resources actor system persistence configuration with <see cref="TestJournal"/> and /// <see cref="TestSnapshotStore"/> configured as default persistence plugins. /// </summary> /// <param name="customConfig">Custom configuration that was passed in the constructor.</param> /// <returns>Actor system configuration object.</returns> /// <seealso cref="Config"/> private static ActorSystemSetup GetConfig(ActorSystemSetup customConfig) { var bootstrapSetup = customConfig.Get <BootstrapSetup>(); var config = bootstrapSetup.FlatSelect(x => x.Config); var actorProvider = bootstrapSetup.FlatSelect(x => x.ActorRefProvider); var newSetup = BootstrapSetup.Create(); if (config.HasValue) { newSetup = newSetup.WithConfig(GetConfig(config.Value)); } else { newSetup = newSetup.WithConfig(GetConfig(Config.Empty)); } if (actorProvider.HasValue) { newSetup = newSetup.WithActorRefProvider(actorProvider.Value); } return(customConfig.WithSetup(newSetup)); }
/// <summary> /// Initializes the <see cref="TestState"/> for a new spec. /// </summary> /// <param name="system">The actor system this test will use. Can be null.</param> /// <param name="config">The configuration that <paramref name="system"/> will use if it's null.</param> /// <param name="actorSystemName">The name that <paramref name="system"/> will use if it's null.</param> /// <param name="testActorName">The name of the test actor. Can be null.</param> protected void InitializeTest(ActorSystem system, ActorSystemSetup config, string actorSystemName, string testActorName) { _testState = new TestState(); if (system == null) { var bootstrap = config.Get <BootstrapSetup>(); var configWithDefaultFallback = bootstrap.HasValue ? bootstrap.Value.Config.Select(c => c == _defaultConfig ? c : c.WithFallback(_defaultConfig)) : _defaultConfig; var newBootstrap = BootstrapSetup.Create().WithConfig( configWithDefaultFallback.HasValue ? configWithDefaultFallback.Value : _defaultConfig); if (bootstrap.FlatSelect(x => x.ActorRefProvider).HasValue) { newBootstrap = newBootstrap.WithActorRefProvider(bootstrap.FlatSelect(x => x.ActorRefProvider).Value); } system = ActorSystem.Create(actorSystemName ?? "test", config.WithSetup(newBootstrap)); } _testState.System = system; system.RegisterExtension(new TestKitExtension()); system.RegisterExtension(new TestKitAssertionsExtension(_assertions)); _testState.TestKitSettings = TestKitExtension.For(_testState.System); _testState.Queue = new BlockingQueue <MessageEnvelope>(); _testState.Log = Logging.GetLogger(system, GetType()); _testState.EventFilterFactory = new EventFilterFactory(this); //register the CallingThreadDispatcherConfigurator _testState.System.Dispatchers.RegisterConfigurator(CallingThreadDispatcher.Id, new CallingThreadDispatcherConfigurator(_testState.System.Settings.Config, _testState.System.Dispatchers.Prerequisites)); if (string.IsNullOrEmpty(testActorName)) { testActorName = "testActor" + _testActorId.IncrementAndGet(); } var testActor = CreateTestActor(system, testActorName); //Wait for the testactor to start // Calling sync version here, since .Wait() causes deadlock AwaitCondition(() => { return(!(testActor is IRepointableRef repRef) || repRef.IsStarted); }, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(10)); if (!(this is INoImplicitSender)) { InternalCurrentActorCellKeeper.Current = (ActorCell)((ActorRefWithCell)testActor).Underlying; } else if (!(this is TestProbe)) //HACK: we need to clear the current context when running a No Implicit Sender test as sender from an async test may leak //but we should not clear the current context when creating a testprobe from a test { InternalCurrentActorCellKeeper.Current = null; } SynchronizationContext.SetSynchronizationContext( new ActorCellKeepingSynchronizationContext(InternalCurrentActorCellKeeper.Current)); _testState.TestActor = testActor; }