OrleansTestKit icon indicating copy to clipboard operation
OrleansTestKit copied to clipboard

IAddressable.GetPrimary(Type)Key throws ArgumentException

Open oising opened this issue 5 years ago • 1 comments

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();
        }
    }

oising avatar Oct 29 '20 17:10 oising

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.

seniorquico avatar Oct 29 '20 19:10 seniorquico

This is supported in TestKit v4.0.0 and above. See the tests in BasicGrainTests.cs for examples.

seniorquico avatar Jan 07 '24 06:01 seniorquico