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

[Breaking Change] remove default HoconAddMode from HOCON builders #135

Merged
merged 5 commits into from
Nov 21, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Akka.Cluster.Hosting.Tests/DistributedPubSubSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task InitializeAsync()
.AddAkka("TestSys", (configurationBuilder, _) =>
{
configurationBuilder
.AddHocon(TestKit.Xunit2.TestKit.DefaultConfig)
.AddHocon(TestKit.Xunit2.TestKit.DefaultConfig, HoconAddMode.Append)
.WithRemoting("localhost", 0)
.WithClustering(_clusterOptions)
.WithActors((system, _) =>
Expand Down
4 changes: 2 additions & 2 deletions src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static AkkaConfigurationBuilder BuildClusterHocon(
return builder.AddHocon(ClusterSharding.DefaultConfig()
.WithFallback(ClusterSingletonManager.DefaultConfig())
.WithFallback(DistributedPubSub.DefaultConfig())
.WithFallback(ClusterClientReceptionist.DefaultConfig()));
.WithFallback(ClusterClientReceptionist.DefaultConfig()), HoconAddMode.Append);
}

/// <summary>
Expand Down Expand Up @@ -305,7 +305,7 @@ public static AkkaConfigurationBuilder WithShardRegionProxy<TKey>(this AkkaConfi
public static AkkaConfigurationBuilder WithDistributedPubSub(this AkkaConfigurationBuilder builder,
string role)
{
var middle = builder.AddHocon(DistributedPubSub.DefaultConfig());
var middle = builder.AddHocon(DistributedPubSub.DefaultConfig(), HoconAddMode.Append);
if (!string.IsNullOrEmpty(role)) // add role config
{
middle = middle.AddHocon($"akka.cluster.pub-sub.role = \"{role}\"", HoconAddMode.Prepend);
Expand Down
4 changes: 2 additions & 2 deletions src/Akka.Hosting.Tests/ExtensionsSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task ShouldNotOverrideHocon()
{
using var host = await StartHost((builder, _) =>
{
builder.AddHocon("akka.extensions = [\"Akka.Hosting.Tests.ExtensionsSpecs+FakeExtensionOneProvider, Akka.Hosting.Tests\"]");
builder.AddHocon("akka.extensions = [\"Akka.Hosting.Tests.ExtensionsSpecs+FakeExtensionOneProvider, Akka.Hosting.Tests\"]", HoconAddMode.Append);
builder.WithExtensions(typeof(FakeExtensionTwoProvider));
});

Expand Down Expand Up @@ -89,7 +89,7 @@ public async Task WithExtensionShouldNotOverrideHocon()
{
using var host = await StartHost((builder, _) =>
{
builder.AddHocon("akka.extensions = [\"Akka.Hosting.Tests.ExtensionsSpecs+FakeExtensionOneProvider, Akka.Hosting.Tests\"]");
builder.AddHocon("akka.extensions = [\"Akka.Hosting.Tests.ExtensionsSpecs+FakeExtensionOneProvider, Akka.Hosting.Tests\"]", HoconAddMode.Append);
builder.WithExtension<FakeExtensionTwoProvider>();
});

Expand Down
2 changes: 1 addition & 1 deletion src/Akka.Hosting.Tests/HoconSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task Should_load_HOCON_from_file()
// arrange
using var host = await StartHost(collection => collection.AddAkka("Test", builder =>
{
builder.AddHoconFile("test.hocon");
builder.AddHoconFile("test.hocon", HoconAddMode.Append);
}));

// act
Expand Down
19 changes: 7 additions & 12 deletions src/Akka.Hosting/AkkaConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,15 @@ internal AkkaConfigurationBuilder AddHoconConfiguration(HoconConfigurator config
return this;
}

internal AkkaConfigurationBuilder AddHoconConfiguration(Config newHocon,
HoconAddMode addMode = HoconAddMode.Append)
internal AkkaConfigurationBuilder AddHoconConfiguration(Config newHocon, HoconAddMode addMode)
{
switch (addMode)
return addMode switch
{
case HoconAddMode.Append:
return AddHoconConfiguration((config, add) => config.WithFallback(add), newHocon);
case HoconAddMode.Prepend:
return AddHoconConfiguration((config, add) => add.WithFallback(config), newHocon);
case HoconAddMode.Replace:
return AddHoconConfiguration((config, add) => add.WithFallback(config), newHocon);
default:
throw new ArgumentOutOfRangeException(nameof(addMode), addMode, null);
}
HoconAddMode.Append => AddHoconConfiguration((config, add) => config.WithFallback(add), newHocon),
HoconAddMode.Prepend => AddHoconConfiguration((config, add) => add.WithFallback(config), newHocon),
HoconAddMode.Replace => AddHoconConfiguration((config, add) => add.WithFallback(config), newHocon),
_ => throw new ArgumentOutOfRangeException(nameof(addMode), addMode, null)
};
}

private static ActorStarter ToAsyncStarter(Action<ActorSystem, IActorRegistry> nonAsyncStarter)
Expand Down
6 changes: 2 additions & 4 deletions src/Akka.Hosting/AkkaHostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public static AkkaConfigurationBuilder AddSetup(this AkkaConfigurationBuilder bu
/// <param name="hocon">The HOCON to add.</param>
/// <param name="addMode">The <see cref="HoconAddMode"/> - defaults to appending this HOCON as a fallback.</param>
/// <returns>The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in.</returns>
public static AkkaConfigurationBuilder AddHocon(this AkkaConfigurationBuilder builder, Config hocon,
HoconAddMode addMode = HoconAddMode.Append)
public static AkkaConfigurationBuilder AddHocon(this AkkaConfigurationBuilder builder, Config hocon, HoconAddMode addMode)
{
return builder.AddHoconConfiguration(hocon, addMode);
}
Expand All @@ -100,8 +99,7 @@ public static AkkaConfigurationBuilder AddHocon(this AkkaConfigurationBuilder bu
/// <param name="hoconFilePath">The path to the HOCON file. Can be relative or absolute.</param>
/// <param name="addMode">The <see cref="HoconAddMode"/> - defaults to appending this HOCON as a fallback.</param>
/// <returns>The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in.</returns>
public static AkkaConfigurationBuilder AddHoconFile(this AkkaConfigurationBuilder builder, string hoconFilePath,
HoconAddMode addMode = HoconAddMode.Append)
public static AkkaConfigurationBuilder AddHoconFile(this AkkaConfigurationBuilder builder, string hoconFilePath, HoconAddMode addMode)
{
var hoconText = ConfigurationFactory.ParseString(File.ReadAllText(hoconFilePath));
return AddHocon(builder, hoconText, addMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class = ""Akka.Persistence.PostgreSql.Snapshot.PostgreSqlSnapshotStore, Akka.Per
builder.WithJournal("postgresql", configurator);
}

return builder.AddHocon(finalConfig.WithFallback(PostgreSqlPersistence.DefaultConfiguration()));
return builder.AddHocon(finalConfig.WithFallback(PostgreSqlPersistence.DefaultConfiguration()), HoconAddMode.Append);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ private static AkkaConfigurationBuilder WithSqlServerPersistence(
case PersistenceMode.Both:
builder.AddHocon(journalConfiguration, HoconAddMode.Prepend);
builder.AddHocon(snapshotStoreConfig, HoconAddMode.Prepend);
builder.AddHocon(SqlReadJournal.DefaultConfiguration());
builder.AddHocon(SqlReadJournal.DefaultConfiguration(), HoconAddMode.Append);
break;

case PersistenceMode.Journal:
builder.AddHocon(journalConfiguration, HoconAddMode.Prepend);
builder.AddHocon(SqlReadJournal.DefaultConfiguration());
builder.AddHocon(SqlReadJournal.DefaultConfiguration(), HoconAddMode.Append);
break;

case PersistenceMode.SnapshotStore:
Expand All @@ -183,7 +183,7 @@ private static AkkaConfigurationBuilder WithSqlServerPersistence(
builder.WithJournal("sql-server", configurator);
}

return builder.AddHocon(SqlServerPersistence.DefaultConfiguration());
return builder.AddHocon(SqlServerPersistence.DefaultConfiguration(), HoconAddMode.Append);
}
}
}