From a907ae1c6bfc8324400c2b726f51cd1f252cf1c8 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Mon, 23 Sep 2024 20:26:46 -0700 Subject: [PATCH] WIP: add & use in-process test cluster --- src/Orleans.Runtime/Silo/SiloControl.cs | 2 - .../RebalancerFixture.cs | 33 +++++++++++++ .../RebalancingTestBase.cs | 48 +++---------------- .../StatePreservationRebalancingTests.cs | 17 +++---- 4 files changed, 45 insertions(+), 55 deletions(-) create mode 100644 test/TesterInternal/ActivationRebalancingTests/RebalancerFixture.cs diff --git a/src/Orleans.Runtime/Silo/SiloControl.cs b/src/Orleans.Runtime/Silo/SiloControl.cs index 7370efb8802..8ac3041442e 100644 --- a/src/Orleans.Runtime/Silo/SiloControl.cs +++ b/src/Orleans.Runtime/Silo/SiloControl.cs @@ -11,7 +11,6 @@ using Orleans.Providers; using Orleans.Runtime.GrainDirectory; using Orleans.Runtime.Placement; -using Orleans.Runtime.GrainDirectory; using Orleans.Runtime.Versions; using Orleans.Runtime.Versions.Compatibility; using Orleans.Runtime.Versions.Selector; @@ -20,7 +19,6 @@ using Orleans.Versions.Compatibility; using Orleans.Versions.Selector; - namespace Orleans.Runtime { internal class SiloControl : SystemTarget, ISiloControl diff --git a/test/TesterInternal/ActivationRebalancingTests/RebalancerFixture.cs b/test/TesterInternal/ActivationRebalancingTests/RebalancerFixture.cs new file mode 100644 index 00000000000..94e70861d47 --- /dev/null +++ b/test/TesterInternal/ActivationRebalancingTests/RebalancerFixture.cs @@ -0,0 +1,33 @@ +using TestExtensions; +using Orleans.Configuration; +using Orleans.TestingHost; +using Microsoft.Extensions.DependencyInjection; + +namespace UnitTests.ActivationRebalancingTests; + +public class RebalancerFixture : BaseInProcessTestClusterFixture +{ + public static readonly TimeSpan RebalancerDueTime = TimeSpan.FromSeconds(5); + public static readonly TimeSpan SessionCyclePeriod = TimeSpan.FromSeconds(3); + + protected override void ConfigureTestCluster(InProcessTestClusterBuilder builder) + { + builder.Options.InitialSilosCount = 4; + builder.Options.UseRealEnvironmentStatistics = true; + builder.ConfigureSilo((options, siloBuilder) +#pragma warning disable ORLEANSEXP002 + => siloBuilder + .Configure(o => + { + o.AssumeHomogenousSilosForTesting = true; + o.ClientGatewayShutdownNotificationTimeout = default; + }) + .Configure(o => + { + o.RebalancerDueTime = RebalancerDueTime; + o.SessionCyclePeriod = SessionCyclePeriod; + }) + .AddActivationRebalancer()); +#pragma warning restore ORLEANSEXP002 + } +} diff --git a/test/TesterInternal/ActivationRebalancingTests/RebalancingTestBase.cs b/test/TesterInternal/ActivationRebalancingTests/RebalancingTestBase.cs index 14ec9a6438e..71513e954e4 100644 --- a/test/TesterInternal/ActivationRebalancingTests/RebalancingTestBase.cs +++ b/test/TesterInternal/ActivationRebalancingTests/RebalancingTestBase.cs @@ -1,16 +1,14 @@ using TestExtensions; using Xunit.Abstractions; -using Orleans.Configuration; using Orleans.TestingHost; using Orleans.Runtime.Placement; -using Microsoft.Extensions.DependencyInjection; namespace UnitTests.ActivationRebalancingTests; -public abstract class RebalancingTestBase : BaseTestClusterFixture - where TFixture : BaseTestClusterFixture +public abstract class RebalancingTestBase + where TFixture : BaseInProcessTestClusterFixture { - protected TestCluster Cluster { get; } + protected InProcessTestCluster Cluster { get; } protected SiloAddress Silo1 { get; } protected SiloAddress Silo2 { get; } @@ -18,7 +16,7 @@ public abstract class RebalancingTestBase : BaseTestClusterFixture protected SiloAddress Silo4 { get; } internal ITestOutputHelper OutputHelper { get; } - internal new IInternalGrainFactory GrainFactory { get; } + internal IInternalGrainFactory GrainFactory { get; } internal IManagementGrain MgmtGrain { get; } protected RebalancingTestBase(TFixture fixture, ITestOutputHelper output) @@ -32,7 +30,7 @@ protected RebalancingTestBase(TFixture fixture, ITestOutputHelper output) Cluster = fixture.HostedCluster; OutputHelper = output; - GrainFactory = fixture.HostedCluster.InternalGrainFactory; + GrainFactory = (IInternalGrainFactory)fixture.HostedCluster.Client; MgmtGrain = GrainFactory.GetGrain(0); } @@ -57,45 +55,11 @@ protected static int CalculateVariance(int[] values) return (int)variance; } - public override async Task InitializeAsync() + public async Task InitializeAsync() { await GrainFactory .GetGrain(0) .ForceActivationCollection(TimeSpan.Zero); - - await base.InitializeAsync(); - } -} - -public class RebalancerFixture : BaseTestClusterFixture -{ - public static readonly TimeSpan RebalancerDueTime = TimeSpan.FromSeconds(5); - public static readonly TimeSpan SessionCyclePeriod = TimeSpan.FromSeconds(3); - - protected override void ConfigureTestCluster(TestClusterBuilder builder) - { - builder.Options.InitialSilosCount = 4; - builder.Options.UseRealEnvironmentStatistics = true; - builder.AddSiloBuilderConfigurator(); - } - - private class SiloConfigurator : ISiloConfigurator - { - public void Configure(ISiloBuilder siloBuilder) -#pragma warning disable ORLEANSEXP002 - => siloBuilder - .Configure(o => - { - o.AssumeHomogenousSilosForTesting = true; - o.ClientGatewayShutdownNotificationTimeout = default; - }) - .Configure(o => - { - o.RebalancerDueTime = RebalancerDueTime; - o.SessionCyclePeriod = SessionCyclePeriod; - }) - .AddActivationRebalancer(); -#pragma warning restore ORLEANSEXP002 } } diff --git a/test/TesterInternal/ActivationRebalancingTests/StatePreservationRebalancingTests.cs b/test/TesterInternal/ActivationRebalancingTests/StatePreservationRebalancingTests.cs index 0dc13831f00..3ec178a79e8 100644 --- a/test/TesterInternal/ActivationRebalancingTests/StatePreservationRebalancingTests.cs +++ b/test/TesterInternal/ActivationRebalancingTests/StatePreservationRebalancingTests.cs @@ -29,7 +29,7 @@ public async Task Should_Migrate_And_Preserve_State_When_Hosting_Silo_Dies() // Move the rebalancer to the first secondary silo, since we will stop it later and we cannot stop // the primary in this test setup. - RequestContext.Set(IPlacementDirector.PlacementHintKey, Cluster.SecondarySilos[0].SiloAddress); + RequestContext.Set(IPlacementDirector.PlacementHintKey, Cluster.Silos[1].SiloAddress); await Cluster.Client.GetGrain(0).Cast().MigrateOnIdle(); RequestContext.Set(IPlacementDirector.PlacementHintKey, null); @@ -70,7 +70,7 @@ public async Task Should_Migrate_And_Preserve_State_When_Hosting_Silo_Dies() OutputHelper.WriteLine($"Cycle {index}: Now stopping Silo{rebalancerHostNum}, which is the host of the rebalancer\n"); - Assert.NotEqual(rebalancerHost, Cluster.Primary.SiloAddress); + Assert.NotEqual(rebalancerHost, Cluster.Silos[0].SiloAddress); await Cluster.StopSiloAsync(Cluster.Silos.First(x => x.SiloAddress.Equals(rebalancerHost))); } @@ -177,21 +177,16 @@ public async Task Should_Migrate_And_Preserve_State_When_Hosting_Silo_Dies() return new(SiloAddress.Zero, 0); } - public class StatePreservationFixture : BaseTestClusterFixture + public class StatePreservationFixture : BaseInProcessTestClusterFixture { public static readonly TimeSpan RebalancerDueTime = TimeSpan.FromSeconds(5); public static readonly TimeSpan SessionCyclePeriod = TimeSpan.FromSeconds(3); - protected override void ConfigureTestCluster(TestClusterBuilder builder) + protected override void ConfigureTestCluster(InProcessTestClusterBuilder builder) { builder.Options.InitialSilosCount = 4; builder.Options.UseRealEnvironmentStatistics = true; - builder.AddSiloBuilderConfigurator(); - } - - private class Configurator : ISiloConfigurator - { - public void Configure(ISiloBuilder siloBuilder) + builder.ConfigureSilo((options, siloBuilder) #pragma warning disable ORLEANSEXP002 => siloBuilder .Configure(o => @@ -205,7 +200,7 @@ public void Configure(ISiloBuilder siloBuilder) o.RebalancerDueTime = RebalancerDueTime; o.SessionCyclePeriod = SessionCyclePeriod; }) - .AddActivationRebalancer(); + .AddActivationRebalancer()); #pragma warning restore ORLEANSEXP002 } }