Skip to content

TestCluster Methods

A host class for local testing with Orleans using in-process silos. Runs a Primary and optionally secondary silos in separate app domains, and client in the main app domain. Additional silos can also be started in-process on demand if required for particular test cases.

DeactivateAsync(GrainId)

View source
public Task DeactivateAsync(GrainId grainId)
Deactivates the current activation of the specified grain and waits for deactivation to complete.

Parameters

grainIdGrainId
The ID of the grain to deactivate.

Returns

A task that completes when the grain has been deactivated.

Examples

await cluster.DeactivateAsync(grain.GetGrainId());

DeactivateAsync(IAddressable)

View source
public Task DeactivateAsync(IAddressable grain)
Deactivates the current activation of the specified grain and waits for deactivation to complete.

Parameters

grainIAddressable
The grain to deactivate.

Returns

A task that completes when the grain has been deactivated.

Examples

await cluster.DeactivateAsync(grain.GetGrainId());

Deploy

View source
public void Deploy()
Deploys the cluster using the specified configuration and starts the client in-process. It will start the number of silos defined in TestClusterOptions.

DeployAsync

View source
public Task DeployAsync()
Deploys the cluster using the specified configuration and starts the client in-process.

Dispose

View source
public void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

DisposeAsync

View source
public ValueTask DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

Returns

A task that represents the asynchronous dispose operation.

GetActiveSilos

View source
public IEnumerable<SiloHandle> GetActiveSilos()
Get the list of current active silos.

Returns

List of current silos.

GetLivenessStabilizationTime(ClusterMembershipOptions, bool)

static
View source
public static TimeSpan GetLivenessStabilizationTime(ClusterMembershipOptions clusterMembershipOptions, bool didKill = false)
Get the timeout value to use to wait for the silo liveness sub-system to detect and act on any recent cluster membership changes.

Parameters

clusterMembershipOptionsClusterMembershipOptions
didKillbool

GetSiloForAddress(SiloAddress)

View source
public SiloHandle? GetSiloForAddress(SiloAddress siloAddress)
Find the silo handle for the specified silo address.

Parameters

siloAddressSiloAddress
Silo address to be found.

Returns

SiloHandle of the appropriate silo, or null if not found.

GetSiloServiceProvider(SiloAddress)

View source
public IServiceProvider GetSiloServiceProvider(SiloAddress silo = null)
Returns the System.IServiceProvider associated with the given silo.

Parameters

siloSiloAddress
The silo process to the the service provider for.

MigrateAsync(GrainId, SiloAddress?)

View source
public Task MigrateAsync(GrainId grainId, SiloAddress? targetSilo = null)
Migrates the current activation of the specified grain to a different silo and waits for migration to complete. If targetSilo is specified, a placement hint is set to guide migration to that silo.

Parameters

grainIdGrainId
The ID of the grain to migrate.
targetSiloSiloAddress?
The target silo address, or null to let the placement director choose.

Returns

A task that completes when the grain has been migrated (deactivated on the source silo).

Examples

var targetSilo = cluster.GetActiveSilos().First(s => s.SiloAddress != originalHost).SiloAddress;
await cluster.MigrateAsync(grain.GetGrainId(), targetSilo);

MigrateAsync(IAddressable, SiloAddress?)

View source
public Task MigrateAsync(IAddressable grain, SiloAddress? targetSilo = null)
Migrates the current activation of the specified grain to a different silo and waits for migration to complete. If targetSilo is specified, a placement hint is set to guide migration to that silo.

Parameters

grainIAddressable
The grain to migrate.
targetSiloSiloAddress?
The target silo address, or null to let the placement director choose.

Returns

A task that completes when the grain has been migrated (deactivated on the source silo).

Examples

var targetSilo = cluster.GetActiveSilos().First(s => s.SiloAddress != originalHost).SiloAddress;
await cluster.MigrateAsync(grain.GetGrainId(), targetSilo);

RestartSiloAsync(SiloHandle)

View source
public Task<SiloHandle?> RestartSiloAsync(SiloHandle instance)
Do a Stop or Kill of the specified silo, followed by a restart.

Parameters

instanceSiloHandle
Silo to be restarted.

StartAdditionalSilo(bool)

View source
public SiloHandle StartAdditionalSilo(bool startAdditionalSiloOnNewPort = false)
Start an additional silo, so that it joins the existing cluster.

Parameters

startAdditionalSiloOnNewPortbool

Returns

SiloHandle for the newly started silo.

StartAdditionalSiloAsync(bool)

View source
public Task<SiloHandle> StartAdditionalSiloAsync(bool startAdditionalSiloOnNewPort = false)
Start an additional silo, so that it joins the existing cluster.

Parameters

startAdditionalSiloOnNewPortbool

Returns

SiloHandle for the newly started silo.

StartAdditionalSilosAsync(int, bool)

View source
public Task<List<SiloHandle>> StartAdditionalSilosAsync(int silosToStart, bool startAdditionalSiloOnNewPort = false)
Start a number of additional silo, so that they join the existing cluster.

Parameters

silosToStartint
Number of silos to start.
startAdditionalSiloOnNewPortbool

Returns

List of SiloHandles for the newly started silos.

StartSiloAsync(int, TestClusterOptions, IReadOnlyList<IConfigurationSource>, bool)

View source
public Task<SiloHandle> StartSiloAsync(int instanceNumber, TestClusterOptions clusterOptions, IReadOnlyList<IConfigurationSource>? configurationOverrides = null, bool startSiloOnNewPort = false)
Starts a new silo.

Parameters

instanceNumberint
The instance number to deploy
clusterOptionsTestClusterOptions
The options to use.
configurationOverridesIReadOnlyList<IConfigurationSource>
Configuration overrides.
startSiloOnNewPortbool
Whether we start this silo on a new port, instead of the default one

Returns

A handle to the deployed silo.

StartSiloAsync(TestCluster, int, TestClusterOptions, IReadOnlyList<IConfigurationSource>, bool)

static
View source
public static Task<SiloHandle> StartSiloAsync(TestCluster cluster, int instanceNumber, TestClusterOptions clusterOptions, IReadOnlyList<IConfigurationSource>? configurationOverrides = null, bool startSiloOnNewPort = false)
Start a new silo in the target cluster

Parameters

clusterTestCluster
The TestCluster in which the silo should be deployed
instanceNumberint
The instance number to deploy
clusterOptionsTestClusterOptions
The options to use.
configurationOverridesIReadOnlyList<IConfigurationSource>
Configuration overrides.
startSiloOnNewPortbool
Whether we start this silo on a new port, instead of the default one

Returns

A handle to the silo deployed

StopClusterClientAsync

View source
public Task StopClusterClientAsync()
Stop cluster client as an asynchronous operation.

Returns

A System.Threading.Tasks.Task representing the asynchronous operation.

TryGetGrainContext(GrainId, IGrainContext?)

View source
public bool TryGetGrainContext(GrainId grainId, out IGrainContext? grainContext)
Attempts to find the IGrainContext for the grain with the specified grainId by searching all silos in the cluster.

Parameters

grainIdGrainId
The ID of the grain to find.
grainContextIGrainContext?
When this method returns, contains the grain context if found; otherwise, null.

Returns

true if the grain was found in one of the silos; otherwise, false.

WaitForClusterManifestToStabilizeAsync(bool)

View source
public Task WaitForClusterManifestToStabilizeAsync(bool didKill = false)
Wait for active silos to observe cluster manifest updates for all active silos.

Parameters

didKillbool
Whether recent membership changes were done by graceful Stop.

WaitForDeactivationAsync(GrainId)

View source
public Task WaitForDeactivationAsync(GrainId grainId)
Gets a System.Threading.Tasks.Task that completes when the current activation of the specified grain finishes deactivating. If the grain is not currently activated, returns System.Threading.Tasks.Task.CompletedTask.

Parameters

grainIdGrainId
The ID of the grain to observe.

Returns

A task that completes when the grain's current activation has deactivated.

Examples

var deactivated = cluster.WaitForDeactivationAsync(grain.GetGrainId());
await grain.DoDeactivate();
await deactivated;

WaitForDeactivationAsync(IAddressable)

View source
public Task WaitForDeactivationAsync(IAddressable grain)
Gets a System.Threading.Tasks.Task that completes when the current activation of the specified grain finishes deactivating. If the grain is not currently activated, returns System.Threading.Tasks.Task.CompletedTask.

Parameters

grainIAddressable
The grain to observe.

Returns

A task that completes when the grain's current activation has deactivated.

Examples

var deactivated = cluster.WaitForDeactivationAsync(grain.GetGrainId());
await grain.DoDeactivate();
await deactivated;

WaitForLivenessToStabilizeAsync(bool)

View source
public Task WaitForLivenessToStabilizeAsync(bool didKill = false)
Wait for the silo liveness sub-system to detect and act on any recent cluster membership changes.

Parameters

didKillbool
Whether recent membership changes we done by graceful Stop.