OrleansTestKit icon indicating copy to clipboard operation
OrleansTestKit copied to clipboard

TestKit support for JournaledGrains

Open marcosikkens opened this issue 4 years ago • 2 comments

I was looking at the different examples but I couldn't find an example of a journaled grain that is being tested. Is this supported? I just want to call a method an verify that the "Raise event" is being called.

My grain is a journaled grain with a [LogConsistencyProvider(ProviderName = "EventStorage")] and when activating this grain it would just crash with the following exception:

   at Orleans.EventSourcing.JournaledGrain`2.OnActivateAsync()
   at Orleans.Grain.<Participate>b__31_0(CancellationToken ct)
   at Orleans.LifecycleExtensions.Observer.OnStart(CancellationToken ct)
   at Orleans.TestKit.TestGrainLifecycle.<>c.<TriggerStartAsync>b__2_1(ValueTuple`2 x)
   at System.Linq.Enumerable.SelectIPartitionIterator`2.PreallocatingToArray(Int32 count)
   at System.Linq.Enumerable.SelectIPartitionIterator`2.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Orleans.TestKit.TestGrainLifecycle.TriggerStartAsync()
   at Orleans.TestKit.TestKitSilo.<CreateGrainAsync>d__31`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Translink.Vbn.Aggregates.Tests.CompanyAggregateRootContext.<Execute>d__6.MoveNext() 

So something doesnt work in the OnActivate. This exception occurs when calling the CreateGrainAsync method

        Grain = await Silo.CreateGrainAsync<CompanyAggregateRoot>(CompanyId);

When I directly use the grain factory i do not get any DI which this grain needs (and the version property is not set). Are there better ways to test journaled grains? Or do I just not test them (which feels kinda strange).

marcosikkens avatar Jan 09 '21 20:01 marcosikkens

I think the TestKit simply lacks support for JournaledGrain.

I previously implemented ICustomStorageInterface in a project, and iirc the JournaledGrain hooks into several pieces of the Orleans activation/context/internals. I would expect us needing some new mocking/infrastructure to support JournaledGrain.

seniorquico avatar Jan 10 '21 00:01 seniorquico

I have been starting to use Orleans Journaled grains at work and I would like to help contribute to this feature.

I do not have a lot of knowledge about the inner workings of Orleans, could you point me in the right direction? What interfaces do you expect to need a mock implementation?

ebeuker avatar Mar 13 '21 22:03 ebeuker