public void SettingActorScanIntervalToLessThanZero_Fails() { var options = new ActorRuntimeOptions(); Action action = () => options.ActorScanInterval = TimeSpan.FromSeconds(-1); action.Should().Throw <ArgumentOutOfRangeException>(); }
public void SettingDrainOngoingCallTimeoutToLessThanZero_Fails() { var options = new ActorRuntimeOptions(); Action action = () => options.DrainOngoingCallTimeout = TimeSpan.FromSeconds(-1); action.Should().Throw <ArgumentOutOfRangeException>(); }
public void SettingJsonSerializerOptionsToNull_Fails() { var options = new ActorRuntimeOptions(); Action action = () => options.JsonSerializerOptions = null; action.Should().Throw <ArgumentNullException>(); }
public async Task Actor_UsesCustomActivator() { var activator = new TestActivator(); var actorType = typeof(MyActor); var options = new ActorRuntimeOptions(); options.Actors.RegisterActor <MyActor>(options => { options.Activator = activator; }); var runtime = new ActorRuntime(options, loggerFactory, activatorFactory, proxyFactory); Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); var output = new MemoryStream(); await runtime.DispatchWithoutRemotingAsync(actorType.Name, "abc", nameof(MyActor.MyMethod), new MemoryStream(), output); var text = Encoding.UTF8.GetString(output.ToArray()); Assert.Equal("\"hi\"", text); await runtime.DeactivateAsync(actorType.Name, "abc"); Assert.Equal(1, activator.CreateCallCount); Assert.Equal(1, activator.DeleteCallCount); }
public void SettingRemindersStoragePartitionsToLessThanZero_Fails() { var options = new ActorRuntimeOptions(); Action action = () => options.RemindersStoragePartitions = -1; action.Should().Throw <ArgumentOutOfRangeException>(); }
public void SettingActorScanInterval_Succeeds() { var options = new ActorRuntimeOptions(); options.ActorScanInterval = TimeSpan.FromSeconds(1); Assert.Equal(TimeSpan.FromSeconds(1), options.ActorScanInterval); }
public void SettingActorIdleTimeout_Succeeds() { var options = new ActorRuntimeOptions(); options.ActorIdleTimeout = TimeSpan.FromSeconds(1); Assert.Equal(TimeSpan.FromSeconds(1), options.ActorIdleTimeout); }
public void SettingDrainOngoingCallTimeout_Succeeds() { var options = new ActorRuntimeOptions(); options.DrainOngoingCallTimeout = TimeSpan.FromSeconds(1); Assert.Equal(TimeSpan.FromSeconds(1), options.DrainOngoingCallTimeout); }
public async Task TestActorSettings() { var actorType = typeof(TestActor); var options = new ActorRuntimeOptions(); options.Actors.RegisterActor <TestActor>(); options.ActorIdleTimeout = TimeSpan.FromSeconds(33); options.ActorScanInterval = TimeSpan.FromSeconds(44); options.DrainOngoingCallTimeout = TimeSpan.FromSeconds(55); options.DrainRebalancedActors = true; var runtime = new ActorRuntime(options, loggerFactory, activatorFactory, proxyFactory); Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); ArrayBufferWriter <byte> writer = new ArrayBufferWriter <byte>(); await runtime.SerializeSettingsAndRegisteredTypes(writer); // read back the serialized json var array = writer.WrittenSpan.ToArray(); string s = Encoding.UTF8.GetString(array, 0, array.Length); JsonDocument document = JsonDocument.Parse(s); JsonElement root = document.RootElement; // parse out the entities array JsonElement element = root.GetProperty("entities"); Assert.Equal(1, element.GetArrayLength()); JsonElement arrayElement = element[0]; string actor = arrayElement.GetString(); Assert.Equal("TestActor", actor); // validate the other properties have expected values element = root.GetProperty("actorIdleTimeout"); Assert.Equal(TimeSpan.FromSeconds(33), ConverterUtils.ConvertTimeSpanFromDaprFormat(element.GetString())); element = root.GetProperty("actorScanInterval"); Assert.Equal(TimeSpan.FromSeconds(44), ConverterUtils.ConvertTimeSpanFromDaprFormat(element.GetString())); element = root.GetProperty("drainOngoingCallTimeout"); Assert.Equal(TimeSpan.FromSeconds(55), ConverterUtils.ConvertTimeSpanFromDaprFormat(element.GetString())); element = root.GetProperty("drainRebalancedActors"); Assert.True(element.GetBoolean()); bool found = root.TryGetProperty("remindersStoragePartitions", out element); Assert.False(found, "remindersStoragePartitions should not be serialized"); JsonElement jsonValue; Assert.False(root.GetProperty("reentrancy").TryGetProperty("maxStackDepth", out jsonValue)); }
public void SettingReentrancyConfigWithoutMaxStackDepth_Succeeds() { var options = new ActorRuntimeOptions(); options.ReentrancyConfig.Enabled = true; Assert.True(options.ReentrancyConfig.Enabled); Assert.Null(options.ReentrancyConfig.MaxStackDepth); }
public void SettingJsonSerializerOptions_Succeeds() { var serializerOptions = new System.Text.Json.JsonSerializerOptions(); var options = new ActorRuntimeOptions(); options.JsonSerializerOptions = serializerOptions; Assert.Same(serializerOptions, options.JsonSerializerOptions); }
public void TestExplicitActorTypeAsParamShouldOverrideInferred() { var actorType = typeof(TestActor); var options = new ActorRuntimeOptions(); options.Actors.RegisterActor <TestActor>(ParamActorTypeName); var runtime = new ActorRuntime(options, loggerFactory, activatorFactory, proxyFactory); Assert.NotEqual(ParamActorTypeName, actorType.Name); Assert.Contains(ParamActorTypeName, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); }
public void TestInferredActorType() { var actorType = typeof(TestActor); var options = new ActorRuntimeOptions(); options.Actors.RegisterActor <TestActor>(); var runtime = new ActorRuntime(options, loggerFactory, activatorFactory, proxyFactory); Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); }
public static ActorRuntimeOptions AddClaptrapDesign(this ActorRuntimeOptions options, IClaptrapDesignStore store) { foreach (var claptrapDesign in store) { var actorTypeInformation = ActorTypeInformation.Get(claptrapDesign.ClaptrapBoxImplementationType); options.Actors.Add( new ActorRegistration( actorTypeInformation)); } return(options); }
public void TestRegisterActor_SavesActorServiceFactory() { var actorType = typeof(TestActor); var actorTypeInformation = ActorTypeInformation.Get(actorType); var actorService = new ActorService(actorTypeInformation, new LoggerFactory()); Func <ActorTypeInformation, ActorService> actorServiceFactory = (actorTypeInfo) => NewActorServiceFactory(actorTypeInfo); Func <ActorService, ActorId, TestActor> actorFactory = (service, id) => new TestActor(service, id, null); var actorRuntimeOptions = new ActorRuntimeOptions(); actorRuntimeOptions.RegisterActor <TestActor>(actorServiceFactory); Assert.True(actorRuntimeOptions.actorServicesFunc.Count.Equals(1)); var key = actorRuntimeOptions.actorServicesFunc.Keys.First(); Assert.True(key.ActorTypeName.Equals(ActorTypeInformation.Get(actorType).ActorTypeName)); }
public async Task NoActivateMessageFromRuntime() { var actorType = typeof(MyActor); var options = new ActorRuntimeOptions(); options.Actors.RegisterActor <MyActor>(); var runtime = new ActorRuntime(options, loggerFactory, activatorFactory); Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); var output = new MemoryStream(); await runtime.DispatchWithoutRemotingAsync(actorType.Name, "abc", nameof(MyActor.MyMethod), new MemoryStream(), output); var text = Encoding.UTF8.GetString(output.ToArray()); Assert.Equal("\"hi\"", text); Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); }
public async Task TestActorSettingsWithReentrancy() { var actorType = typeof(TestActor); var options = new ActorRuntimeOptions(); options.Actors.RegisterActor <TestActor>(); options.ActorIdleTimeout = TimeSpan.FromSeconds(33); options.ActorScanInterval = TimeSpan.FromSeconds(44); options.DrainOngoingCallTimeout = TimeSpan.FromSeconds(55); options.DrainRebalancedActors = true; options.ReentrancyConfig.Enabled = true; options.ReentrancyConfig.MaxStackDepth = 64; var runtime = new ActorRuntime(options, loggerFactory, activatorFactory, proxyFactory); Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); ArrayBufferWriter <byte> writer = new ArrayBufferWriter <byte>(); await runtime.SerializeSettingsAndRegisteredTypes(writer); // read back the serialized json var array = writer.WrittenSpan.ToArray(); string s = Encoding.UTF8.GetString(array, 0, array.Length); JsonDocument document = JsonDocument.Parse(s); JsonElement root = document.RootElement; // parse out the entities array JsonElement element = root.GetProperty("entities"); Assert.Equal(1, element.GetArrayLength()); element = root.GetProperty("reentrancy").GetProperty("enabled"); Assert.True(element.GetBoolean()); element = root.GetProperty("reentrancy").GetProperty("maxStackDepth"); Assert.Equal(64, element.GetInt32()); }
public async Task TestActorSettingsWithRemindersStoragePartitions() { var actorType = typeof(TestActor); var options = new ActorRuntimeOptions(); options.Actors.RegisterActor <TestActor>(); options.RemindersStoragePartitions = 12; var runtime = new ActorRuntime(options, loggerFactory, activatorFactory, proxyFactory); Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); ArrayBufferWriter <byte> writer = new ArrayBufferWriter <byte>(); await runtime.SerializeSettingsAndRegisteredTypes(writer); // read back the serialized json var array = writer.WrittenSpan.ToArray(); string s = Encoding.UTF8.GetString(array, 0, array.Length); JsonDocument document = JsonDocument.Parse(s); JsonElement root = document.RootElement; // parse out the entities array JsonElement element = root.GetProperty("entities"); Assert.Equal(1, element.GetArrayLength()); JsonElement arrayElement = element[0]; string actor = arrayElement.GetString(); Assert.Equal("TestActor", actor); element = root.GetProperty("remindersStoragePartitions"); Assert.Equal(12, element.GetInt64()); }
public void TestRegisterActor_SavesActivator() { var actorType = typeof(TestActor); var actorTypeInformation = ActorTypeInformation.Get(actorType); var host = ActorHost.CreateForTest <TestActor>(); var actor = new TestActor(host); var activator = Mock.Of <ActorActivator>(); var actorRuntimeOptions = new ActorRuntimeOptions(); actorRuntimeOptions.Actors.RegisterActor <TestActor>(registration => { registration.Activator = activator; }); Assert.Collection( actorRuntimeOptions.Actors, registration => { Assert.Same(actorTypeInformation.ImplementationType, registration.Type.ImplementationType); Assert.Same(activator, registration.Activator); }); }
public void TestRegisterActor_SavesActivator() { var actorType = typeof(TestActor); var actorTypeInformation = ActorTypeInformation.Get(actorType); var host = new ActorHost(actorTypeInformation, ActorId.CreateRandom(), JsonSerializerDefaults.Web, new LoggerFactory()); var actor = new TestActor(host); var activator = Mock.Of <ActorActivator>(); var actorRuntimeOptions = new ActorRuntimeOptions(); actorRuntimeOptions.Actors.RegisterActor <TestActor>(registration => { registration.Activator = activator; }); Assert.Collection( actorRuntimeOptions.Actors, registration => { Assert.Same(actorTypeInformation.ImplementationType, registration.Type.ImplementationType); Assert.Same(activator, registration.Activator); }); }