public PersonActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func <ActorService, ActorId, ActorBase> actorFactory = null, Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings) { _serviceLoggerFactory = () => new ServiceDomainLogger(this, ServiceRequestContext.Current); _communicationLoggerFactory = () => new CommunicationLogger(this); }
public MockActorService( ICodePackageActivationContext codePackageActivationContext, IServiceProxyFactory serviceProxyFactory, IActorProxyFactory actorProxyFactory, NodeContext nodeContext, StatefulServiceContext statefulServiceContext, ActorTypeInformation actorTypeInfo, Func <ActorService, ActorId, ActorBase> actorFactory = null, Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null ) : base( context: statefulServiceContext, actorTypeInfo: actorTypeInfo, actorFactory: actorFactory, stateManagerFactory: stateManagerFactory, stateProvider: stateProvider, settings: settings) { _codePackageActivationContext = codePackageActivationContext; _serviceProxyFactory = serviceProxyFactory; _actorProxyFactory = actorProxyFactory; _nodeContext = nodeContext; }
private static void LoadActors(Assembly inputAssembly, IList <string> actorFilters, IList <ActorTypeInformation> actorTypes) { var actorTypeInfoTable = new Dictionary <Type, ActorTypeInformation>(); foreach (var t in inputAssembly.GetTypes()) { if (!t.IsActor()) { continue; } var actorTypeInformation = ActorTypeInformation.Get(t); if (actorTypeInformation.IsAbstract) { continue; } CheckForDuplicateFabricServiceName(actorTypeInfoTable, actorTypeInformation); if (actorFilters != null) { if (RemoveFrom(actorFilters, t.FullName, StringComparison.OrdinalIgnoreCase)) { actorTypes.Add(actorTypeInformation); } } else { actorTypes.Add(actorTypeInformation); } } }
public void TestInferredActorType() { var actorType = typeof(TestActor); var actorTypeInformation = ActorTypeInformation.Get(actorType); Assert.Equal(actorType.Name, actorTypeInformation.ActorTypeName); }
public void TestMethod_SetStateAsync() { //Arrange var callbackStateInfo = new StateData() { AnotherStringProperty = "Supreme kai", FirstName = "Goku", StringProperty = "Prince Vegeta" }; var actorTypeInformation = ActorTypeInformation.Get(typeof(SampleActor)); var actorStateManager = new Mock <IActorStateManager>(); actorStateManager.Setup(manager => manager.SetStateAsync("callbackstate", callbackStateInfo, CancellationToken.None)).Verifiable(); Func <ActorService, ActorId, SampleActor> actorFactory = (service, id) => new SampleActor(service, id, "value1", "value1" , new Mock <IRemindableWrapper>().Object , actorStateManager.Object ); var actorService = new ActorService(actorTypeInformation, actorFactory); var agentCallbackActor = actorFactory.Invoke(actorService, ActorId.CreateRandom()); //Act var apiResponseModel = agentCallbackActor.SaveStateData(callbackStateInfo).GetAwaiter().GetResult(); //Assert apiResponseModel.IsError.Should().BeTrue(); apiResponseModel.Message.Should().Be("success"); actorStateManager.VerifyAll(); }
public static ActorTypeInformation GetActorTypeInfo( this Type actorType) { if (!actorType.IsActor()) { throw new ArgumentException( string.Format("The type '{0}' is not an Actor. An actor type must derive from '{1}'.", actorType.FullName, typeof(Actor).FullName), nameof(actorType)); } Type[] actorInterfaces = actorType.GetActorInterfaces(); if (actorInterfaces.Length == 0 && !actorType.GetTypeInfo().IsAbstract) { throw new ArgumentException( string.Format("The actor type '{0}' does not implement any actor interfaces or one of the interfaces implemented is not an actor interface." + " All interfaces(including its parent interface) implemented by actor type must be actor interface. " + "An actor interface is the one that ultimately derives from '{1}' type.", actorType.FullName, typeof(IActor).FullName), nameof(actorType)); } var actorTypeInfo = ActorTypeInformation.Get(actorType); var remoteServiceAttr = actorType.GetRemoteServiceAttribute(); if (remoteServiceAttr != null && !string.Equals(actorTypeInfo.ActorTypeName, remoteServiceAttr.Name)) { typeof(ActorTypeInformation) .GetProperty(nameof(ActorTypeInformation.ActorTypeName), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) ?.SetValue(actorTypeInfo, remoteServiceAttr.Name); } return(actorTypeInfo); }
public void CanRegisterActorsInMultipleCalls() { var builder = new WebHostBuilder(); builder.UseActors(options => { options.Actors.RegisterActor <TestActor1>(); }); builder.UseActors(options => { options.Actors.RegisterActor <TestActor2>(); }); // Configuring the HTTP pipeline is required. It's ok if it's empty. builder.Configure(_ => {}); var host = builder.Build(); var runtime = host.Services.GetRequiredService <ActorRuntime>(); Assert.Collection( runtime.RegisteredActors.Select(r => r.Type.ActorTypeName).OrderBy(t => t), t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor1)).ActorTypeName, t), t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor2)).ActorTypeName, t)); }
public void ResolveTest() { using (var container = new WindsorContainer()) { var resolver = new ActorServiceResolver(container.Kernel, typeof(TestActorService)) { }; var context = MockStatefulServiceContextFactory.Default; var typeInfo = ActorTypeInformation.Get(typeof(TestActor)); Assert.Throws <ComponentNotFoundException>(() => resolver.Resolve(context, typeInfo)); container.Register(Component.For <TestActorService>().LifestyleTransient()); var service = resolver.Resolve(context, typeInfo); Assert.NotNull(service); var testService = Assert.IsType <TestActorService>(service); Assert.Null(testService.StateManagerFactory); Assert.Null(testService.ActorFactory); Assert.Null(testService.StateProvider); Assert.Null(testService.Settings); Assert.Same(typeInfo, testService.ActorTypeInfo); Assert.Same(context, testService.Context); // ReSharper disable once ConvertToLocalFunction -- Local function doesn't equal a realized Func<> Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactoryMock = (actor, provider) => new MockActorStateManager(); // ReSharper disable once ConvertToLocalFunction -- Local function doesn't equal a realized Func<> Func <ActorService, ActorId, ActorBase> actorFactoryMock = (s, id) => new TestActor(s, id); var stateProviderMock = new Mock <IActorStateProvider>(); var settings = new ActorServiceSettings(); resolver = new ActorServiceResolver(container.Kernel, typeof(TestActorService)) { StateManagerFactory = stateManagerFactoryMock, ActorFactory = actorFactoryMock, StateProvider = stateProviderMock.Object, Settings = settings }; service = resolver.Resolve(context, typeInfo); Assert.NotNull(service); testService = Assert.IsType <TestActorService>(service); Assert.Same(stateManagerFactoryMock, testService.StateManagerFactory); Assert.Same(actorFactoryMock, testService.ActorFactory); Assert.Same(stateProviderMock.Object, testService.StateProvider); Assert.Same(settings, testService.Settings); Assert.Same(typeInfo, testService.ActorTypeInfo); Assert.Same(context, testService.Context); } }
private async Task <TActorInterface> Create <TActorInterface>(ActorId actorId) where TActorInterface : IActor { var actorRegistration = _actorRegistrations.FirstOrDefault(ar => ar.InterfaceType == typeof(TActorInterface)); if (actorRegistration == null) { throw new ArgumentException($"Expected a MockableActorRegistration for the type {typeof(TActorInterface).Name}"); } if (actorRegistration.ImplementationType != null && actorRegistration.ImplementationType.IsSubclassOf(typeof(Actor))) { var actorServiceName = $"{actorRegistration.ImplementationType.Name}Service"; var createStateProvider = actorRegistration.CreateStateProvider ?? (() => (IActorStateProvider) new MockActorStateProvider(_fabricRuntime)); var actorStateProvider = GetOrCreateActorStateProvider(actorRegistration.ImplementationType, () => createStateProvider()); var actorTypeInformation = ActorTypeInformation.Get(actorRegistration.ImplementationType); var statefulServiceContext = _fabricRuntime.BuildStatefulServiceContext(actorServiceName); var stateManagerFactory = actorRegistration.CreateStateManager != null ? (Func <ActorBase, IActorStateProvider, IActorStateManager>)( (actor, stateProvider) => actorRegistration.CreateStateManager(actor, stateProvider)) : null; var actorServiceFactory = actorRegistration.CreateActorService ?? GetMockActorService; var actorService = actorServiceFactory(statefulServiceContext, actorTypeInformation, actorStateProvider, stateManagerFactory); if (actorService is FG.ServiceFabric.Actors.Runtime.ActorService) { actorService.SetPrivateField("_serviceProxyFactory", _fabricRuntime.ServiceProxyFactory); actorService.SetPrivateField("_actorProxyFactory", _fabricRuntime.ActorProxyFactory); actorService.SetPrivateField("_applicationUriBuilder", _fabricRuntime.ApplicationUriBuilder); } var target = actorRegistration.Activator(actorService, actorId); var mockableTarget = (FG.ServiceFabric.Actors.Runtime.ActorBase)(target as FG.ServiceFabric.Actors.Runtime.ActorBase); if (mockableTarget != null) { mockableTarget.SetPrivateField("_serviceProxyFactory", _fabricRuntime.ServiceProxyFactory); mockableTarget.SetPrivateField("_actorProxyFactory", _fabricRuntime.ActorProxyFactory); mockableTarget.SetPrivateField("_applicationUriBuilder", _fabricRuntime.ApplicationUriBuilder); } target.CallPrivateMethod("OnActivateAsync"); await actorStateProvider.ActorActivatedAsync(actorId); var serviceUri = _fabricRuntime.ApplicationUriBuilder.Build(actorServiceName).ToUri(); var actorProxy = new MockActorProxy(actorId, serviceUri, ServicePartitionKey.Singleton, TargetReplicaSelector.Default, "", null); var proxy = /*TryCreateDynamicProxy(typeof(TActorInterface), target, actorProxy);*/ CreateDynamicProxy <TActorInterface>(target, actorProxy); _actorProxies.Add(proxy.GetHashCode(), target); return((TActorInterface)proxy); } else { var target = actorRegistration.Activator(null, actorId); return((TActorInterface)target); } }
public TestObservableObserverActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func <ActorBase> actorFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateProvider, settings) { }
internal EventSourceProvider(ServiceContext serviceContext, ActorTypeInformation actorTypeInformation) { this.serviceContext = serviceContext; this.actorTypeInformation = actorTypeInformation; this.actorType = actorTypeInformation.ImplementationType.ToString(); this.writer = ActorFrameworkEventSource.Writer; }
public ContainerAggregatorActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo) : base(context, actorTypeInfo) { this.LoadLiveCounterSettings(); this.containerLivenessCounter = new LivenessCounter <string>(expirationIntervalInSeconds, fuzzIntervalInSeconds); this.ignoreOtherUpdatesEntries = new ConcurrentDictionary <string, Timer>(); this.updateLogQueue = new Queue <KeyValuePair <string, string> >(MaxUpdateLogEntriesToKeep); }
public DeviceActorService( StatefulServiceContext context, ActorTypeInformation typeInfo, Func <ActorBase> actorFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, typeInfo, actorFactory, stateProvider, settings) { // Read settings from the DeviceActorServiceConfig section in the Settings.xml file ICodePackageActivationContext activationContext = context.CodePackageActivationContext; ConfigurationPackage config = activationContext.GetConfigurationPackageObject(ConfigurationPackage); ConfigurationSection section = config.Settings.Sections[ConfigurationSection]; // Read the ServiceBusConnectionString setting from the Settings.xml file ConfigurationProperty parameter = section.Parameters[ServiceBusConnectionStringParameter]; if (!string.IsNullOrWhiteSpace(parameter?.Value)) { this.ServiceBusConnectionString = parameter.Value; } else { throw new ArgumentException( string.Format(ParameterCannotBeNullFormat, ServiceBusConnectionStringParameter), ServiceBusConnectionStringParameter); } // Read the EventHubName setting from the Settings.xml file parameter = section.Parameters[EventHubNameParameter]; if (!string.IsNullOrWhiteSpace(parameter?.Value)) { this.EventHubName = parameter.Value; } else { throw new ArgumentException( string.Format(ParameterCannotBeNullFormat, EventHubNameParameter), EventHubNameParameter); } // Read the QueueLength setting from the Settings.xml file parameter = section.Parameters[QueueLengthParameter]; if (!string.IsNullOrWhiteSpace(parameter?.Value)) { this.QueueLength = DefaultQueueLength; int queueLength; if (int.TryParse(parameter.Value, out queueLength)) { this.QueueLength = queueLength; } } else { throw new ArgumentException( string.Format(ParameterCannotBeNullFormat, QueueLengthParameter), QueueLengthParameter); } }
protected ObservableObserverActorServiceBase(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func <ActorBase> actorFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateProvider, settings) { ConfigurationHelper.Initialize(this.Context); }
public ActorBaseService( StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func <ActorService, ActorId, ActorBase> actorFactory, Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings) { }
internal static ActorService GetActorService <T>() where T : Actor { return(new ActorService( GetMockStatefulServiceContext(), ActorTypeInformation.Get(typeof(T)), null, null, GetMockActorStateProvider())); }
public void TestExplicitActorTypeAsParam(Type actorType) { Assert.NotEqual(ParamActorTypeName, actorType.Name); Assert.NotEqual(ParamActorTypeName, actorType.GetCustomAttribute <ActorAttribute>()?.TypeName); var actorTypeInformation = ActorTypeInformation.Get(actorType, ParamActorTypeName); Assert.Equal(ParamActorTypeName, actorTypeInformation.ActorTypeName); }
public ActorDemoActorService( StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func <ActorService, ActorId, Actors.Runtime.ActorBase> actorFactory = null, Func <Microsoft.ServiceFabric.Actors.Runtime.ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings) { }
object GetInstance(MessageHeaders headers, Type actorType) { ActorId id = ActorIdHelper.Get(headers); ServiceContext context = ServiceContextHelper.Get(headers); ActorService service = (context == null) ? new ActorService(null, ActorTypeInformation.Get(actorType)) : new ActorService(new StatefulServiceContext(context.ServiceName), ActorTypeInformation.Get(actorType)); object instance = Activator.CreateInstance(actorType, service, id); return(instance); }
/// <summary> /// On my test code I want to pass the mock statemanager all the time. /// </summary> /// <param name="actorStateManager">Mock StateManager.</param> /// <returns>TestActor.</returns> private TestActor CreateTestDemoActor(IActorStateManager actorStateManager) { var actorTypeInformation = ActorTypeInformation.Get(typeof(TestActor)); var loggerFactory = new LoggerFactory(); var host = new ActorHost(actorTypeInformation, ActorId.CreateRandom(), loggerFactory); var testActor = new TestActor(host, actorStateManager); return(testActor); }
/// <summary> /// On my test code I want to pass the mock statemanager all the time. /// </summary> /// <param name="actorStateManager">Mock StateManager.</param> /// <returns>TestActor.</returns> private TestActor CreateTestDemoActor(IActorStateManager actorStateManager) { var actorTypeInformation = ActorTypeInformation.Get(typeof(TestActor)); var loggerFactory = new LoggerFactory(); var host = new ActorHost(actorTypeInformation, ActorId.CreateRandom(), JsonSerializerDefaults.Web, loggerFactory, ActorProxy.DefaultProxyFactory, new DaprHttpInteractor()); var testActor = new TestActor(host, actorStateManager); return(testActor); }
public void TestDefault() { var instance = MockActorServiceFactory.CreateActorServiceForActor <MockActor>(); Assert.IsInstanceOfType(instance, typeof(MockActorService <MockActor>)); Assert.AreEqual(MockStatefulServiceContextFactory.Default, instance.Context); Assert.AreEqual(ActorTypeInformation.Get(typeof(MockActor)).ImplementationType, instance.ActorTypeInformation.ImplementationType); Assert.IsNotNull(instance.StateProvider); Assert.IsNotNull(instance.Settings); }
private DemoActor CreateTestDemoActor(IRemindableWrapper remindableWrapper, IActorStateManager actorStateManager, IHelloDaprWorld daprWorld = null) { var actorTypeInformation = ActorTypeInformation.Get(typeof(DemoActor)); Func <ActorService, ActorId, DemoActor> actorFactory = (service, id) => new DemoActor(service, id, daprWorld, remindableWrapper, actorStateManager); var actorService = new ActorService(actorTypeInformation, actorFactory); var demoActor = actorFactory.Invoke(actorService, ActorId.CreateRandom()); return(demoActor); }
public MockActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func <ActorService, ActorId, ActorBase> actorFactory = null, Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings) { _actorFactory = actorFactory ?? ((svc, id) => { var ctor = actorTypeInfo.ImplementationType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(ActorService), typeof(ActorId) }, null); return((ActorBase)ctor.Invoke(new object[] { svc, id })); }); }
public ActorServiceEapBase(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, DiagnosticPipeline diagnosticPipeline, Func <ActorService, ActorId, ActorBase> actorFactory = null, Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings) { CreateSerilog(diagnosticPipeline); }
public void TestExplicitActorType() { var actorType = typeof(RenamedActor); Assert.NotEqual(RenamedActorTypeName, actorType.Name); var actorTypeInformation = ActorTypeInformation.Get(actorType); Assert.Equal(RenamedActorTypeName, actorTypeInformation.ActorTypeName); }
public ActorMethodDispatcherMap(ActorTypeInformation actorTypeInformation) { this.map = new Dictionary <int, ActorMethodDispatcherBase>(); foreach (var actorInterfaceType in actorTypeInformation.InterfaceTypes) { var methodDispatcher = ActorCodeBuilder.GetOrCreateMethodDispatcher(actorInterfaceType); this.map.Add(methodDispatcher.InterfaceId, methodDispatcher); } }
public NodeManagerService( StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func <ActorService, ActorId, ActorBase> actorFactory = null, Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings) { this.nodeManagerSettings = new NodeManagerSettings(context.CodePackageActivationContext.GetConfigurationPackageObject(this.configurationPackageName).Settings); }
public CommonActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, ILoggerFactory loggerFactory, LoggerConfiguration loggerConfiguration = null, Func <ActorService, ActorId, ActorBase> actorFactory = null, Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings) { Logger = loggerFactory.CreateLogger(GetType()); }
public static AutoMock CreateAutoMock(this IClaptrapDesign claptrapDesign, string id, IStateData stateData, Action <ContainerBuilder, ActorHost>?builderAction = default, Func <AutoMock>?autoMockFunc = default) { var claptrapIdentity = new ClaptrapIdentity(id, claptrapDesign.ClaptrapTypeCode); var actorTypeInformation = ActorTypeInformation.Get(claptrapDesign.ClaptrapBoxImplementationType); var actorHost = new ActorHost(actorTypeInformation, new ActorId(id),
public DeviceActorService(StatefulServiceContext context, ActorTypeInformation typeInfo, Func<ActorBase> actorFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, typeInfo, actorFactory, stateProvider, settings) { // Read settings from the DeviceActorServiceConfig section in the Settings.xml file var activationContext = Context.CodePackageActivationContext; var config = activationContext.GetConfigurationPackageObject(ConfigurationPackage); var section = config.Settings.Sections[ConfigurationSection]; // Read the ServiceBusConnectionString setting from the Settings.xml file var parameter = section.Parameters[ServiceBusConnectionStringParameter]; if (!string.IsNullOrWhiteSpace(parameter?.Value)) { ServiceBusConnectionString = parameter.Value; } else { throw new ArgumentException( string.Format(ParameterCannotBeNullFormat, ServiceBusConnectionStringParameter), ServiceBusConnectionStringParameter); } // Read the EventHubName setting from the Settings.xml file parameter = section.Parameters[EventHubNameParameter]; if (!string.IsNullOrWhiteSpace(parameter?.Value)) { EventHubName = parameter.Value; } else { throw new ArgumentException(string.Format(ParameterCannotBeNullFormat, EventHubNameParameter), EventHubNameParameter); } // Read the QueueLength setting from the Settings.xml file parameter = section.Parameters[QueueLengthParameter]; if (!string.IsNullOrWhiteSpace(parameter?.Value)) { QueueLength = DefaultQueueLength; int queueLength; if (int.TryParse(parameter.Value, out queueLength)) { QueueLength = queueLength; } } else { throw new ArgumentException(string.Format(ParameterCannotBeNullFormat, QueueLengthParameter), QueueLengthParameter); } }
public TelemetryEnabledActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func<ActorBase> actorFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateProvider, settings) {}