Skip to content

Commit

Permalink
Make ManagementGrain a reentrant, stateless worker (#8394)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond authored Apr 18, 2023
1 parent 698e860 commit f16bcd0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IManagementGrain : IGrainWithIntegerKey, IVersionManager
/// Perform a run of the .NET garbage collector in the specified silos.
/// </summary>
/// <param name="hostsIds">List of silos this command is to be sent to.</param>
/// <returns>A <see cref="Task"/> represesnting the work performed.</returns>
/// <returns>A <see cref="Task"/> representing the work performed.</returns>
Task ForceGarbageCollection(SiloAddress[] hostsIds);

/// <summary>Perform a run of the Orleans activation collector in the specified silos.</summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Orleans.Runtime/Core/ManagementGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Orleans.Concurrency;
using Orleans.Metadata;
using Orleans.Runtime.GrainDirectory;
using Orleans.Runtime.MembershipService;
Expand All @@ -15,6 +16,7 @@ namespace Orleans.Runtime.Management
/// <summary>
/// Implementation class for the Orleans management grain.
/// </summary>
[StatelessWorker, Reentrant]
internal class ManagementGrain : Grain, IManagementGrain
{
private readonly IInternalGrainFactory internalGrainFactory;
Expand Down
61 changes: 61 additions & 0 deletions test/DefaultCluster.Tests/ManagementGrainTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Orleans.Concurrency;
using Orleans.Runtime;
using TestExtensions;
using Xunit;

namespace UnitTests.OrleansRuntime
{
public class ManagementGrainTests : HostedTestClusterEnsureDefaultStarted
{
public ManagementGrainTests(DefaultClusterFixture fixture) : base(fixture)
{
}

[Fact]
[TestCategory("BVT")]
public async Task GetActivationAddressTest()
{
var managementGrain = this.Fixture.Client.GetGrain<IManagementGrain>(0);
var grain1 = this.Fixture.Client.GetGrain<IDumbGrain>(Guid.NewGuid());
var grain2 = this.Fixture.Client.GetGrain<IDumbGrain>(Guid.NewGuid());

var grain1Address = await managementGrain.GetActivationAddress(grain1);
Assert.Null(grain1Address);

await grain1.DoNothing();
grain1Address = await managementGrain.GetActivationAddress(grain1);
Assert.NotNull(grain1Address);
var grain2Address = await managementGrain.GetActivationAddress(grain2);
Assert.Null(grain2Address);

await grain2.DoNothing();
var grain1Address2 = await managementGrain.GetActivationAddress(grain1);
Assert.NotNull(grain1Address2);
Assert.True(grain1Address.Equals(grain1Address2));

var worker = this.Fixture.Client.GetGrain<IDumbWorker>(0);
await Assert.ThrowsAnyAsync<InvalidOperationException>(async () => await managementGrain.GetActivationAddress(worker));
}
}

public interface IDumbWorker : IGrainWithIntegerKey
{
Task DoNothing();
}

[StatelessWorker(1)]
public class DumbWorker : Grain, IDumbWorker
{
public Task DoNothing() => Task.CompletedTask;
}

public interface IDumbGrain : IGrainWithGuidKey
{
Task DoNothing();
}

public class DumbGrain : Grain, IDumbGrain
{
public Task DoNothing() => Task.CompletedTask;
}
}
60 changes: 0 additions & 60 deletions test/TesterInternal/OrleansRuntime/ManagementGrainTests.cs

This file was deleted.

0 comments on commit f16bcd0

Please sign in to comment.