Skip to content

Commit 33fc3f0

Browse files
Deprecate JournalOptions.Adapters property in favor of callback API (#669)
* Deprecate JournalOptions.Adapters property in favor of callback API Fixes #665 The Adapters property created confusion by providing two competing patterns for configuring event adapters. This deprecates the property in favor of the unified callback pattern introduced in PR #662. Changes: - Mark JournalOptions.Adapters as [Obsolete] with clear migration message - Remove internal usage of the property (Adapters.AppendAdapters call) - Add regression test DeprecatedAdaptersPropertySpec that verifies: * Deprecated property is ignored and does not configure adapters * Callback pattern continues to work correctly * Uses #pragma warning disable to test deprecated API Benefits: - Single, consistent pattern for configuring adapters and health checks - Cleaner API surface with options containing only configuration data - Clear migration path with deprecation warning Migration: Before (deprecated): var options = new JournalOptions(); options.Adapters.AddWriteEventAdapter<Foo>(...); builder.WithJournal(options); After (recommended): var options = new JournalOptions(); builder.WithJournal(options, journal => journal.AddWriteEventAdapter<Foo>(...)); All 17 tests pass. * added API approvals
1 parent a99fa79 commit 33fc3f0

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

src/Akka.Hosting.API.Tests/verify/CoreApiSpec.ApprovePersistence.verified.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ namespace Akka.Persistence.Hosting
4343
public abstract class JournalOptions
4444
{
4545
protected JournalOptions(bool isDefault) { }
46+
[System.Obsolete("Use the configureBuilder callback parameter in WithJournal() instead. This proper" +
47+
"ty will be removed in v1.6.0. See https://github.com/akkadotnet/Akka.Hosting/iss" +
48+
"ues/665")]
4649
public Akka.Persistence.Hosting.AkkaPersistenceJournalBuilder Adapters { get; set; }
4750
public bool AutoInitialize { get; set; }
4851
public Akka.Configuration.Config DefaultConfig { get; }

src/Akka.Persistence.Hosting.Tests/EventAdapterSpecs.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,79 @@ public void Should_use_correct_EventAdapter_bindings()
129129
sqlPersistenceJournal.GetString("event-adapters.combo").Should().Be(typeof(ComboAdapter).TypeQualifiedName());
130130
sqlPersistenceJournal.GetString("event-adapters.tagger").Should().Be(typeof(Tagger).TypeQualifiedName());
131131
}
132+
}
133+
134+
/// <summary>
135+
/// Regression test for https://github.com/akkadotnet/Akka.Hosting/issues/665
136+
/// Verifies that the deprecated Adapters property is ignored and does not configure event adapters
137+
/// </summary>
138+
public class DeprecatedAdaptersPropertySpec : Akka.Hosting.TestKit.TestKit
139+
{
140+
private sealed class TestJournalOptions : JournalOptions
141+
{
142+
public TestJournalOptions() : base(isDefault: true)
143+
{
144+
Identifier = "test-journal";
145+
}
146+
147+
public override string Identifier { get; set; }
148+
149+
protected override Config InternalDefaultConfig =>
150+
ConfigurationFactory.ParseString(@"
151+
class = ""Akka.Persistence.Journal.MemoryJournal, Akka.Persistence""
152+
plugin-dispatcher = ""akka.actor.default-dispatcher""
153+
");
154+
}
155+
156+
public sealed class DeprecatedAdapter : IWriteEventAdapter
157+
{
158+
public string Manifest(object evt) => string.Empty;
159+
public object ToJournal(object evt) => evt;
160+
}
161+
162+
public sealed class CallbackAdapter : IWriteEventAdapter
163+
{
164+
public string Manifest(object evt) => string.Empty;
165+
public object ToJournal(object evt) => evt;
166+
}
167+
168+
protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
169+
{
170+
var journalOptions = new TestJournalOptions();
171+
172+
#pragma warning disable 618, 619
173+
// Attempt to use the deprecated Adapters property
174+
journalOptions.Adapters = new AkkaPersistenceJournalBuilder("test-journal", builder);
175+
journalOptions.Adapters.AddWriteEventAdapter<DeprecatedAdapter>("deprecated-adapter",
176+
new[] { typeof(string) });
177+
#pragma warning restore 618, 619
178+
179+
// Use the callback pattern (the correct way)
180+
builder.WithJournal(journalOptions, journal =>
181+
journal.AddWriteEventAdapter<CallbackAdapter>("callback-adapter",
182+
new[] { typeof(int) }));
183+
}
184+
185+
[Fact]
186+
public void Deprecated_Adapters_property_should_be_ignored()
187+
{
188+
var config = Sys.Settings.Config;
189+
var journalConfig = config.GetConfig("akka.persistence.journal.test-journal");
190+
191+
// The deprecated adapter should NOT be registered
192+
journalConfig.HasPath("event-adapters.deprecated-adapter").Should().BeFalse(
193+
"adapters configured via the deprecated Adapters property should be ignored");
194+
195+
// The callback adapter SHOULD be registered
196+
journalConfig.HasPath("event-adapters.callback-adapter").Should().BeTrue(
197+
"adapters configured via the callback pattern should work");
198+
journalConfig.GetString("event-adapters.callback-adapter")
199+
.Should().Be(typeof(CallbackAdapter).TypeQualifiedName());
200+
201+
// Verify bindings
202+
journalConfig.HasPath($"event-adapter-bindings.\"{typeof(string).TypeQualifiedName()}\"")
203+
.Should().BeFalse("deprecated adapter bindings should not exist");
204+
journalConfig.GetStringList($"event-adapter-bindings.\"{typeof(int).TypeQualifiedName()}\"")
205+
.Should().BeEquivalentTo(new[] { "callback-adapter" }, "callback adapter bindings should exist");
206+
}
132207
}

src/Akka.Persistence.Hosting/JournalOptions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ protected JournalOptions(bool isDefault)
7575
/// The journal adapter builder, use this builder to add custom journal
7676
/// <see cref="IEventAdapter"/>, <see cref="IWriteEventAdapter"/>, or <see cref="IReadEventAdapter"/>
7777
/// </summary>
78+
[Obsolete("Use the configureBuilder callback parameter in WithJournal() instead. This property will be removed in v1.6.0. See https://github.com/akkadotnet/Akka.Hosting/issues/665")]
7879
public AkkaPersistenceJournalBuilder Adapters { get; set; } = new ("", null!);
7980

8081
public string PluginId => $"akka.persistence.journal.{Identifier}";
@@ -102,7 +103,8 @@ protected virtual StringBuilder Build(StringBuilder sb)
102103
sb.Insert(0, $"{PluginId} {{{Environment.NewLine}");
103104
sb.AppendLine($"auto-initialize = {AutoInitialize.ToHocon()}");
104105
sb.AppendLine($"serializer = {Serializer.ToHocon()}");
105-
Adapters.AppendAdapters(sb);
106+
// Adapters property is deprecated - use the callback pattern in WithJournal() instead
107+
// See https://github.com/akkadotnet/Akka.Hosting/issues/665
106108
sb.AppendLine("}");
107109

108110
if (IsDefaultPlugin)

0 commit comments

Comments
 (0)