diff --git a/src/core/Akka.Persistence.Tests/Akka.Persistence.Tests.csproj b/src/core/Akka.Persistence.Tests/Akka.Persistence.Tests.csproj index 9cb5794521f..f7ea2170601 100644 --- a/src/core/Akka.Persistence.Tests/Akka.Persistence.Tests.csproj +++ b/src/core/Akka.Persistence.Tests/Akka.Persistence.Tests.csproj @@ -100,6 +100,7 @@ + diff --git a/src/core/Akka.Persistence.Tests/PersistenceConfigAutoStartSpec.cs b/src/core/Akka.Persistence.Tests/PersistenceConfigAutoStartSpec.cs new file mode 100644 index 00000000000..ec121c0ca57 --- /dev/null +++ b/src/core/Akka.Persistence.Tests/PersistenceConfigAutoStartSpec.cs @@ -0,0 +1,107 @@ +//----------------------------------------------------------------------- +// +// Copyright (C) 2009-2016 Lightbend Inc. +// Copyright (C) 2013-2016 Akka.NET project +// +//----------------------------------------------------------------------- + +using Akka.Actor; +using Akka.Configuration; +using Akka.Persistence.Journal; +using Akka.Persistence.Snapshot; +using Akka.TestKit; +using Xunit; +using Xunit.Abstractions; + +namespace Akka.Persistence.Tests +{ + public class PersistenceConfigAutoStartSpec : AkkaSpec + { + #region internal classes + + private sealed class TestRequest + { + public static readonly TestRequest Instance = new TestRequest(); + + private TestRequest() + { + } + } + + public class TestJournal : MemoryJournal + { + private readonly string _testValue; + + public TestJournal(Config config) + { + _testValue = config.GetString("test-value"); + } + + protected override bool AroundReceive(Receive receive, object message) + { + if (message is TestRequest) + { + Sender.Tell(_testValue); + return true; + } + else return base.AroundReceive(receive, message); + } + } + + public class TestSnapshotStore : LocalSnapshotStore + { + private readonly string _testValue; + + public TestSnapshotStore(Config config) + { + _testValue = config.GetString("test-value"); + } + + protected override bool AroundReceive(Receive receive, object message) + { + if (message is TestRequest) + { + Sender.Tell(_testValue); + return true; + } + else return base.AroundReceive(receive, message); + } + } + + #endregion + + private static readonly Config AutoStartConfig = ConfigurationFactory.ParseString(@" + akka.loglevel = INFO + akka.persistence.journal { + test { + class = ""Akka.Persistence.Tests.PersistenceConfigAutoStartSpec+TestJournal, Akka.Persistence.Tests"" + plugin-dispatcher = ""akka.actor.default-dispatcher"" + test-value = ""A"" + } + auto-start-journals = [akka.persistence.journal.test] + } + akka.persistence.snapshot-store { + test { + class = ""Akka.Persistence.Tests.PersistenceConfigAutoStartSpec+TestSnapshotStore, Akka.Persistence.Tests"" + plugin-dispatcher = ""akka.actor.default-dispatcher"" + test-value = ""C"" + } + auto-start-snapshot-stores = [akka.persistence.snapshot-store.test] + } + "); + + public PersistenceConfigAutoStartSpec(ITestOutputHelper output = null) : base(AutoStartConfig, output) + { + } + + [Fact] + public void Persistence_should_auto_start_journal_and_snapshotstore_when_specified() + { + EventFilter.Info(message: "Auto-starting journal plugin `akka.persistence.journal.test`") + .And.Info(message: "Auto-starting snapshot store `akka.persistence.snapshot-store.test`").Expect(2, () => + { + var persistence = Persistence.Instance.Apply(Sys); + }); + } + } +} diff --git a/src/core/Akka.Persistence/Persistence.cs b/src/core/Akka.Persistence/Persistence.cs index 53ebdc813c7..3475528e4f8 100644 --- a/src/core/Akka.Persistence/Persistence.cs +++ b/src/core/Akka.Persistence/Persistence.cs @@ -34,7 +34,7 @@ public PluginHolder(IActorRef @ref, EventAdapters adapters, Config config) } /// - /// TBD + /// Launches the Akka.Persistence runtime /// public class PersistenceExtension : IExtension { @@ -55,12 +55,15 @@ public class PersistenceExtension : IExtension private const string SnapshotStoreFallbackConfigPath = "akka.persistence.snapshot-store-plugin-fallback"; /// - /// TBD + /// Creates a new Akka.Persistence extension. /// - /// TBD - /// TBD + /// The ActorSystem that will be using Akka.Persistence + /// /// This exception is thrown when the default journal plugin, journal.plugin is not configured. /// + /// + /// DO NOT CALL DIRECTLY. Will be instantiated automatically be Akka.Persistence actors. + /// public PersistenceExtension(ExtendedActorSystem system) { _system = system; @@ -106,7 +109,7 @@ public PersistenceExtension(ExtendedActorSystem system) JournalFor(id); }); - _config.GetStringList("journal.auto-start-snapshot-stores").ForEach(id => + _config.GetStringList("snapshot-store.auto-start-snapshot-stores").ForEach(id => { if (_log.IsInfoEnabled) _log.Info("Auto-starting snapshot store `{0}`", id); @@ -120,7 +123,7 @@ public PersistenceExtension(ExtendedActorSystem system) public IStashOverflowStrategy DefaultInternalStashOverflowStrategy => _defaultInternalStashOverflowStrategy.Value; /// - /// TBD + /// The Akka.Persistence settings for the journal and snapshot store /// public PersistenceSettings Settings { get; }