Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IAddressable.GetPrimary(Type)Key throws ArgumentException #100

Closed
oising opened this issue Oct 29, 2020 · 2 comments
Closed

IAddressable.GetPrimary(Type)Key throws ArgumentException #100

oising opened this issue Oct 29, 2020 · 2 comments
Labels

Comments

@oising
Copy link

oising commented Oct 29, 2020

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();
        }
    }
@seniorquico
Copy link
Collaborator

seniorquico commented Oct 29, 2020

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants