-
Notifications
You must be signed in to change notification settings - Fork 16
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
added AddHoconFile
method
#58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
using static Akka.Hosting.Tests.TestHelpers; | ||
|
||
namespace Akka.Hosting.Tests; | ||
|
||
public class HoconSpecs | ||
{ | ||
[Fact] | ||
public async Task Should_load_HOCON_from_file() | ||
{ | ||
// arrange | ||
using var host = await StartHost(collection => collection.AddAkka("Test", builder => | ||
{ | ||
builder.AddHoconFile("test.hocon"); | ||
})); | ||
|
||
// act | ||
var sys = host.Services.GetRequiredService<ActorSystem>(); | ||
var hocon = sys.Settings.Config; | ||
|
||
// assert | ||
hocon.HasPath("petabridge.cmd").Should().BeTrue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a custom HOCON section in the |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Akka.Hosting.Tests; | ||
|
||
public static class TestHelpers | ||
{ | ||
public static async Task<IHost> StartHost(Action<IServiceCollection> testSetup) | ||
{ | ||
var host = new HostBuilder() | ||
.ConfigureServices(services => | ||
{ | ||
services.AddSingleton<DiSanityCheckSpecs.IMySingletonInterface, DiSanityCheckSpecs.MySingletonImpl>(); | ||
testSetup(services); | ||
}).Build(); | ||
|
||
await host.StartAsync(); | ||
return host; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# See petabridge.cmd configuration options here: https://cmd.petabridge.com/articles/install/host-configuration.html | ||
petabridge.cmd{ | ||
# default IP address used to listen for incoming petabridge.cmd client connections | ||
# should be a safe default as it listens on "all network interfaces". | ||
host = "0.0.0.0" | ||
|
||
# default port number used to listen for incoming petabridge.cmd client connections | ||
port = 9110 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using System.IO; | ||
using Akka.Actor; | ||
using Akka.Actor.Setup; | ||
using Akka.Configuration; | ||
|
@@ -90,6 +91,21 @@ public static AkkaConfigurationBuilder AddHocon(this AkkaConfigurationBuilder bu | |
return builder.AddHoconConfiguration(hocon, addMode); | ||
} | ||
|
||
/// <summary> | ||
/// Automatically loads the given HOCON file from <see cref="hoconFilePath"/> | ||
/// and inserts it into the <see cref="ActorSystem"/>s' configuration. | ||
/// </summary> | ||
/// <param name="builder">The builder instance being configured.</param> | ||
/// <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) | ||
{ | ||
var hoconText = ConfigurationFactory.ParseString(File.ReadAllText(hoconFilePath)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parses the file synchronously - this will throw an exception if the file is not found, which is to be expected. |
||
return AddHocon(builder, hoconText, addMode); | ||
} | ||
|
||
/// <summary> | ||
/// Configures the <see cref="ProviderSelection"/> for this <see cref="ActorSystem"/>. Can be used to | ||
/// configure whether or not Akka, Akka.Remote, or Akka.Cluster starts. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this to a separate
TestHelpers
class so it can be re-used across multiple tests