public async Task MultipleComputationsUsingSameMethodSameActivation(int randomoffset) { int NumComputations = 100; var grain = GrainFactory.GetGrain <IMyOtherReactiveGrain>(randomoffset); List <IReactiveComputation <string> > ReactComps = new List <IReactiveComputation <string> >(); for (var i = 0; i < NumComputations; i++) { ReactComps.Add(GrainFactory.StartReactiveComputation(() => grain.GetValue() )); } var Its = ReactComps.Select((Rc) => Rc.GetResultEnumerator()).ToList(); // await all first results var Results1 = await Task.WhenAll(Its.Select(It => It.NextResultAsync() ).ToList()); foreach (var result1 in Results1) { Assert.Equal(result1, "foo"); } // update the dependency await grain.SetValue("bar"); // await all second results var Results2 = await Task.WhenAll(Its.Select(It => It.NextResultAsync())); foreach (var result2 in Results2) { Assert.Equal(result2, "bar"); } foreach (var Rc in ReactComps) { Rc.Dispose(); } }
public async Task MultipleComputationsUsingSameMethodDifferentActivation(int randomoffset) { int NumComputations = 1000; List <IReactiveComputation <string> > ReactComps = new List <IReactiveComputation <string> >(); for (var i = 0; i < NumComputations; i++) { var grain = GrainFactory.GetGrain <IMyOtherReactiveGrain>(randomoffset + i); ReactComps.Add(GrainFactory.StartReactiveComputation(() => grain.GetValue())); } var Its = ReactComps.Select((Rc) => Rc.GetResultEnumerator()).ToList(); var Results1 = await Task.WhenAll(Its.Select(It => It.NextResultAsync())); foreach (var result1 in Results1) { Assert.Equal(result1, "foo"); } for (var j = 0; j < NumComputations; j++) { await GrainFactory.GetGrain <IMyOtherReactiveGrain>(randomoffset + j).SetValue("bar" + j); } var Results2 = await Task.WhenAll(Its.Select(It => It.NextResultAsync())); var k = 0; foreach (var result2 in Results2) { Assert.Equal(result2, "bar" + k++); } foreach (var Rc in ReactComps) { Rc.Dispose(); } }