Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.DistributedData;
using Akka.Hosting;
using Akka.Remote.Hosting;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Cluster.Hosting.Tests;

public class ClusterShardingDistributedDataSpecs: Akka.Hosting.TestKit.TestKit
{
private const string ReplicatorName = "dDataReplicator";

public ClusterShardingDistributedDataSpecs(ITestOutputHelper output): base(output: output)
{
}

protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
{
builder
.WithRemoting()
.WithClustering()
.WithDistributedData(opt =>
{
opt.Name = ReplicatorName;
});
}

[Fact(DisplayName = "WithDistributedData should start DistributedData extension automatically")]
public async Task WithDistributedDataStartsAutomaticallyTest()
{
var cluster = Cluster.Get(Sys);
await cluster.JoinAsync(cluster.SelfAddress);
cluster.State.Members.Count(m => m.Status == MemberStatus.Up).Should().Be(1);

var settings = ReplicatorSettings.Create(Sys);
var coordinatorName = settings.RestartReplicatorOnFailure ? $"{ReplicatorName}Supervisor" : ReplicatorName;

var actorSelection = Sys.ActorSelection(new RootActorPath(cluster.SelfAddress) / "user" / coordinatorName);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replicator is started under user guardian, is this correct?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really should be under the /system guardian but if we're stuck with /user for now then that's a separate bug that'll need fixing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is an Akka core issue, not Akka.Hosting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please file a bug for that?

That might also be an ugly one to chase down if replicators are all currently hard-coded to look for /user/ paths for chatting. Might have to move that to a v1.6 issue if it ends up being a breaking behavioral change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue to track this created here: akkadotnet/akka.net#7606


await AwaitAssertAsync(async () =>
{
actorSelection.Tell(new Identify("coordinator"), TestActor);
var identity = await ExpectMsgAsync<ActorIdentity>(TimeSpan.FromSeconds(3));

// The DData replicator should be running
// * This actor is created inside DistributedData extension .ctor
// * Marks that the extension is running
// * We can't use DistributedData.Get() because that defeats the purpose.
identity.Subject.Should().NotBeNull();
});
}
}
2 changes: 2 additions & 0 deletions src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Akka.Coordination;
using Akka.DependencyInjection;
using Akka.Discovery;
using Akka.DistributedData;
using Akka.Hosting;
using Akka.Hosting.Coordination;
using Akka.Persistence.Hosting;
Expand Down Expand Up @@ -691,6 +692,7 @@ public static AkkaConfigurationBuilder WithDistributedData(
{
options.Apply(builder);
builder.AddHocon(DistributedData.DistributedData.DefaultConfig(), HoconAddMode.Append);
builder.WithExtension<DistributedDataProvider>();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual fix, add the extension to the auto-start list.

return builder;
}

Expand Down