OrleansTestKit
OrleansTestKit copied to clipboard
IAddressable.GetPrimary(Type)Key throws ArgumentException
This pattern works fine at runtime in Orleans, but fails in the test kit.
namespace Tests
{
public class BaseGrain : Grain
{
// IAddressable.GetPrimaryKeyString()
protected string MyGrainKey => this.GetPrimaryKeyString();
}
public class DumbGrain : BaseGrain, IDumb
{
public Task<string> Duh()
{
// IGrainWithStringKey.GetPrimaryKeyString()
return Task.FromResult(this.GetPrimaryKeyString());
}
public Task<string> Doh()
{
return Task.FromResult(MyGrainKey);
}
}
public interface IDumb : IGrainWithStringKey
{
Task<string> Duh();
Task<string> Doh();
}
public class BasicGrainTests : TestKitBase
{
[Fact]
public async Task TestDumbGrain()
{
IDumb grain = await Silo.CreateGrainAsync<DumbGrain>("foo");
// OK
await grain.Duh();
/*
System.ArgumentException
Passing a half baked grain as an argument. It is possible that you instantiated a grain class explicitly, as a regular object and not via Orleans runtime or via proper test mocking (Parameter 'grain')
at Orleans.GrainExtensions.GetGrainId(IAddressable grain)
at Orleans.GrainExtensions.GetPrimaryKeyString(IAddressable grain)
*/
await grain.Doh();
}
}
Yes, this is a known limitation. See #47 for additional information.
There are some big grain ID changes in the works (in Orleans), and I'm hopeful that we might be able to find a solution once those are wrapped up.
This is supported in TestKit v4.0.0 and above. See the tests in BasicGrainTests.cs for examples.