public Fixture(IServiceProvider services = null) { var proxifier = new Func <AbstractKey, IGrain>( key => (IGrain)GrainProxy.Proxify(this, key)); //just needs dispatcher and serializer Exceptions = new ExceptionSink(); Scheduler = new FixtureScheduler(Exceptions); Serializer = new FakeSerializer(proxifier); Types = new TypeMap(); GrainFactory = new FakeGrainFactory(Types, proxifier); Requests = new RequestRunner(Scheduler, Exceptions); Services = new ServiceRegistry(services); Stores = new StorageRegistry(Serializer); Providers = new ProviderRegistry(() => new ProviderRuntimeAdaptor(GrainFactory, Services, null)); Reminders = new ReminderRegistry(this); Placer = new Placer(Types.GetConcreteType); Activations = null; var activationHub = new ActivationHub(place => { var actSite = new ActivationSite(p => new Activation_New(this, p).Dispatcher); //!!! actSite.Init(place); return(actSite); }); Placer = new Placer(Types.GetConcreteType); Dispatcher = new Dispatcher(Placer.Place, activationHub); Streams = new StreamRegistry(activationHub, Exceptions, Types); }
public async Task RecreatesDispatcherWhenDeactivatedFound() //does ActivationSite really need the acivation itself, or just its dispatcher? { var expectedReturnVal = Guid.NewGuid(); var placement = new Placement(new AbstractKey(typeof(ITestGrain), Guid.NewGuid()), typeof(TestGrain)); var deadDisp = Substitute.For <IActivationDispatcher>(); deadDisp.When(x => x.Perform(Arg.Is(_fn))) .Do(_ => { throw new DeactivatedException(); }); var goodDisp = Substitute.For <IActivationDispatcher>(); goodDisp.Perform(Arg.Is(_fn)).Returns(expectedReturnVal); var dispCreator = Substitute.For <Func <Placement, IActivationDispatcher> >(); dispCreator(Arg.Is(placement)).Returns(deadDisp, goodDisp); var site = new ActivationSite(dispCreator); site.Init(placement); var result = await site.Dispatch(_fn); Assert.That(result, Is.EqualTo(expectedReturnVal)); }
public async Task DispatchesToActivationDispatcher() { var guid = Guid.NewGuid(); var disp = Substitute.For <IActivationDispatcher>(); disp.Perform(Arg.Is(_fn)).Returns(guid); var site = new ActivationSite(_ => disp); //in reality, passed factory would summon entire activation var result = await site.Dispatch(_fn); Assert.That(result, Is.EqualTo(guid)); }
public async Task SameDispatcherUsedIfGood() { var actCreator = new Func <Placement, IActivationDispatcher>(p => { var act = Substitute.For <IActivationDispatcher>(); act.Perform(Arg.Is(_fn)).Returns(Guid.NewGuid()); return(act); }); var site = new ActivationSite(actCreator); var result1 = await site.Dispatch(_fn); var result2 = await site.Dispatch(_fn); Assert.That(result1, Is.EqualTo(result2)); }
public async Task ReactivatesOneAtATimeViaLock() { var dispCreator = new Func <Placement, IActivationDispatcher>(p => { var act = Substitute.For <IActivationDispatcher>(); act.Perform(Arg.Is(_fn)).Returns(Guid.NewGuid()); return(act); }); var site = new ActivationSite(dispCreator); var results = await Enumerable.Range(0, 1000) .Select(async _ => { await Task.Delay(15); return(await site.Dispatch(_fn)); }) .WhenAll(); Assert.That(results, Is.All.EqualTo(results.First())); }