Skip to content

Commit

Permalink
Use marker interface IDiscoveryOptions instead the more generic IHoco…
Browse files Browse the repository at this point in the history
…nOptions
  • Loading branch information
Arkatufus committed Jul 29, 2024
1 parent a478b56 commit b9920a6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 35 deletions.
21 changes: 1 addition & 20 deletions src/Akka.Cluster.Hosting.Tests/ClusterClientDiscoverySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ public void ClusterClientDiscoverySettingsSpec()
[Fact(DisplayName = "ClusterClientDiscoverySettings with invalid values should throw")]
public void ClusterClientDiscoveryInvalidSettingsSpec()
{
Invoking(() => new ClusterClientDiscoveryOptions
{
DiscoveryOptions = new InvalidServiceDiscoveryOptions()
}.ToString())
.Should().ThrowExactly<ArgumentException>()
.WithMessage("Discovery options must be of Type KubernetesDiscoveryOptions*");

Invoking(() => new ClusterClientDiscoveryOptions
{
DiscoveryOptions = new ConfigServiceDiscoveryOptions(),
Expand Down Expand Up @@ -162,19 +155,7 @@ public void ClusterClientDiscoveryInvalidSettingsSpec()

}

private class InvalidServiceDiscoveryOptions: IHoconOption
{
public string ConfigPath { get; set; } = "invalid";
public Type Class { get; } = typeof(ConfigServiceDiscovery);
public bool IsDefaultPlugin { get; set; } = true;

public void Apply(AkkaConfigurationBuilder builder, Setup? setup = null)
{
throw new NotImplementedException();
}
}

private class ConfigServiceDiscoveryOptions: IHoconOption
private class ConfigServiceDiscoveryOptions: IDiscoveryOptions
{
internal const string DefaultPath = "config";
internal const string DefaultConfigPath = "akka.discovery." + DefaultPath;
Expand Down
2 changes: 1 addition & 1 deletion src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ internal static ClusterClientSettings CreateClusterClientSettings(Config config,
public static AkkaConfigurationBuilder WithClusterClientDiscovery<TKey>(
this AkkaConfigurationBuilder builder,
string serviceName,
IHoconOption discoveryOptions,
IDiscoveryOptions discoveryOptions,
string? portName = null,
TimeSpan? retryInterval = null,
TimeSpan? timeout = null,
Expand Down
13 changes: 1 addition & 12 deletions src/Akka.Cluster.Hosting/ClusterClientDiscoveryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class ClusterClientDiscoveryOptions
/// <see cref="ClusterClientDiscovery"/> to work, you <b>will need</b> to set
/// <c>DiscoveryOptions.IsDefaultPlugin</c> to <c>false</c>
/// </summary>
public IHoconOption DiscoveryOptions { get; set; } = null!;
public IDiscoveryOptions DiscoveryOptions { get; set; } = null!;

/// <summary>
/// The service name that are being discovered. This setting is not optional.
Expand Down Expand Up @@ -75,17 +75,6 @@ public override string ToString()

private void Validate()
{
var type = DiscoveryOptions.GetType().Name;
if(!(type.Contains("ConfigServiceDiscoveryOptions")
|| type.Contains("KubernetesDiscoveryOptions")
|| type.Contains("AkkaDiscoveryOptions")
|| type.Contains("Ec2ServiceDiscoveryOptions")
|| type.Contains("EcsServiceDiscoveryOptions")))
throw new ArgumentException(
"Discovery options must be of Type KubernetesDiscoveryOptions, AkkaDiscoveryOptions, " +
"Ec2ServiceDiscoveryOptions, EcsServiceDiscoveryOptions, or ConfigServiceDiscoveryOptions",
nameof(DiscoveryOptions));

if (string.IsNullOrWhiteSpace(ServiceName))
throw new ArgumentException("Service name must be provided", nameof(ServiceName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Akka.Cluster.Hosting
public static Akka.Hosting.AkkaConfigurationBuilder WithClusterClient<TKey>(this Akka.Hosting.AkkaConfigurationBuilder builder, System.Collections.Generic.IEnumerable<Akka.Actor.Address> initialContactAddresses, string receptionistActorName = "receptionist") { }
public static Akka.Hosting.AkkaConfigurationBuilder WithClusterClientDiscovery<TKey>(this Akka.Hosting.AkkaConfigurationBuilder builder, Akka.Cluster.Hosting.ClusterClientDiscoveryOptions options) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithClusterClientDiscovery<TKey>(this Akka.Hosting.AkkaConfigurationBuilder builder, System.Action<Akka.Cluster.Hosting.ClusterClientDiscoveryOptions> configure) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithClusterClientDiscovery<TKey>(this Akka.Hosting.AkkaConfigurationBuilder builder, string serviceName, Akka.Hosting.IHoconOption discoveryOptions, string? portName = null, System.TimeSpan? retryInterval = default, System.TimeSpan? timeout = default, int? numberOfContacts = default, string? clientActorName = null) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithClusterClientDiscovery<TKey>(this Akka.Hosting.AkkaConfigurationBuilder builder, string serviceName, Akka.Hosting.IDiscoveryOptions discoveryOptions, string? portName = null, System.TimeSpan? retryInterval = default, System.TimeSpan? timeout = default, int? numberOfContacts = default, string? clientActorName = null) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithClusterClientReceptionist(this Akka.Hosting.AkkaConfigurationBuilder builder, string name = "receptionist", string? role = null) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithClustering(this Akka.Hosting.AkkaConfigurationBuilder builder, Akka.Cluster.Hosting.ClusterOptions? options = null) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithDistributedData(this Akka.Hosting.AkkaConfigurationBuilder builder, Akka.Cluster.Hosting.DDataOptions options) { }
Expand Down Expand Up @@ -40,7 +40,7 @@ namespace Akka.Cluster.Hosting
{
public ClusterClientDiscoveryOptions() { }
public string? ClientActorName { get; set; }
public Akka.Hosting.IHoconOption DiscoveryOptions { get; set; }
public Akka.Hosting.IDiscoveryOptions DiscoveryOptions { get; set; }
public int? NumberOfContacts { get; set; }
public string? PortName { get; set; }
public System.TimeSpan? RetryInterval { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ namespace Akka.Hosting
bool TryRegister(System.Type key, Akka.Actor.IActorRef actor, bool overwrite = false);
bool TryRegister<TKey>(Akka.Actor.IActorRef actor, bool overwrite = false);
}
public interface IDiscoveryOptions : Akka.Hosting.IHoconOption { }
public interface IHoconOption
{
System.Type Class { get; }
Expand Down
5 changes: 5 additions & 0 deletions src/Akka.Hosting/IDiscoveryOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Akka.Hosting;

public interface IDiscoveryOptions: IHoconOption
{
}

0 comments on commit b9920a6

Please sign in to comment.