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); }
private async Task <T> CreateGrainAsync <T>(IGrainIdentity identity) where T : Grain { if (_isGrainCreated) { throw new Exception( "A grain has already been created in this silo. Only 1 grain per test silo should every be created. Add grain probes for supporting grains."); } _isGrainCreated = true; Grain grain; var grainContext = new TestGrainActivationContext { ActivationServices = ServiceProvider, GrainIdentity = identity, GrainType = typeof(T), ObservableLifecycle = _grainLifecycle, }; //Create a stateless grain grain = _grainCreator.CreateGrainInstance(grainContext) as T; if (grain == null) { throw new Exception($"Unable to instantiate grain {typeof(T)} properly"); } //Check if there are any reminders for this grain var remindable = grain as IRemindable; //Set the reminder target if (remindable != null) { ReminderRegistry.SetGrainTarget(remindable); } //Trigger the lifecycle hook that will get the grain's state from the runtime await _grainLifecycle.TriggerStartAsync(); return(grain as T); }
private async Task <T> CreateGrainAsync <T>(IGrainIdentity identity) where T : Grain { if (_isGrainCreated) { throw new Exception("A grain has already been created in this silo. Only 1 grain per test silo should ever be created. Add grain probes for supporting grains."); } // Add state attribute mapping for storage facets this.AddService <IAttributeToFactoryMapper <PersistentStateAttribute> >(StorageManager.stateAttributeFactoryMapper); _isGrainCreated = true; Grain grain; var grainContext = new TestGrainActivationContext { ActivationServices = ServiceProvider, GrainIdentity = identity, GrainType = typeof(T), ObservableLifecycle = _grainLifecycle, }; //Create a stateless grain grain = _grainCreator.CreateGrainInstance(grainContext) as T; if (grain == null) { throw new Exception($"Unable to instantiate grain {typeof(T)} properly"); } //Check if there are any reminders for this grain and set the reminder target if (grain is IRemindable remindable) { ReminderRegistry.SetGrainTarget(remindable); } //Trigger the lifecycle hook that will get the grain's state from the runtime await _grainLifecycle.TriggerStartAsync().ConfigureAwait(false); return(grain as T); }
private T CreateGrain <T>(IGrainIdentity identity) where T : Grain { if (_isGrainCreated) { throw new Exception( "A grain has already been created in this silo. Only 1 grain per test silo should every be created. Add grain probes for supporting grains."); } _isGrainCreated = true; Grain grain; var grainContext = new TestGrainActivationContext() { ActivationServices = ServiceProvider, GrainIdentity = identity, GrainType = typeof(T), }; //Check to see if the grain is stateful if (typeof(T).IsSubclassOfRawGeneric(typeof(Grain <>))) { var grainGenericArgs = typeof(T).BaseType?.GenericTypeArguments; if (grainGenericArgs == null || grainGenericArgs.Length == 0) { throw new Exception($"Unable to get grain state type info for {typeof(T)}"); } //Get the state type var stateType = grainGenericArgs[0]; var storage = _storageManager.AddStorage <T>(identity); //Create a new stateful grain grain = _grainCreator.CreateGrainInstance(grainContext, stateType, storage); if (grain == null) { throw new Exception($"Unable to instantiate stateful grain {typeof(T)} properly"); } var stateProperty = TypeHelper.GetProperty(typeof(T), "State"); var state = stateProperty?.GetValue(grain); _grainStateManager.AddState(grain, state); } else { //Create a stateless grain grain = _grainCreator.CreateGrainInstance(grainContext) as T; if (grain == null) { throw new Exception($"Unable to instantiate grain {typeof(T)} properly"); } } //Check if there are any reminders for this grain var remindable = grain as IRemindable; //Set the reminder target if (remindable != null) { ReminderRegistry.SetGrainTarget(remindable); } //Emulate the grain's lifecycle grain.OnActivateAsync().Wait(1000); return(grain as T); }
public Task FireAllReminders(TickStatus tickStatus = new TickStatus()) => ReminderRegistry.FireAllReminders(tickStatus);
public Task FireReminder(string reminderName, TickStatus tickStatus = new TickStatus()) => ReminderRegistry.FireReminder(reminderName, tickStatus);