diff --git a/src/Dapr.Actors/Runtime/ActorRuntime.cs b/src/Dapr.Actors/Runtime/ActorRuntime.cs index a41ab7bd..8e83a856 100644 --- a/src/Dapr.Actors/Runtime/ActorRuntime.cs +++ b/src/Dapr.Actors/Runtime/ActorRuntime.cs @@ -93,6 +93,12 @@ namespace Dapr.Actors.Runtime writer.WriteBoolean("drainRebalancedActors", (this.options.DrainRebalancedActors)); } + // default is null, don't write it if default + if (this.options.RemindersStoragePartitions != null) + { + writer.WriteNumber("remindersStoragePartitions", this.options.RemindersStoragePartitions.Value); + } + writer.WriteEndObject(); return writer.FlushAsync(); } diff --git a/src/Dapr.Actors/Runtime/ActorRuntimeOptions.cs b/src/Dapr.Actors/Runtime/ActorRuntimeOptions.cs index 724d6e2b..4951f98d 100644 --- a/src/Dapr.Actors/Runtime/ActorRuntimeOptions.cs +++ b/src/Dapr.Actors/Runtime/ActorRuntimeOptions.cs @@ -22,6 +22,7 @@ namespace Dapr.Actors.Runtime private bool drainRebalancedActors; private JsonSerializerOptions jsonSerializerOptions = JsonSerializerDefaults.Web; private string daprApiToken = null; + private int? remindersStoragePartitions = null; /// /// Gets the collection of instances. @@ -162,6 +163,27 @@ namespace Dapr.Actors.Runtime } } + /// + /// An int used to determine how many partitions to use for reminders storage. + /// + public int? RemindersStoragePartitions + { + get + { + return this.remindersStoragePartitions; + } + + set + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(remindersStoragePartitions), remindersStoragePartitions, "must be positive"); + } + + this.remindersStoragePartitions = value; + } + } + /// /// Gets or sets the HTTP endpoint URI used to communicate with the Dapr sidecar. /// diff --git a/test/Dapr.Actors.Test/Runtime/ActorRuntimeOptionsTests.cs b/test/Dapr.Actors.Test/Runtime/ActorRuntimeOptionsTests.cs index 4082243b..99535a41 100644 --- a/test/Dapr.Actors.Test/Runtime/ActorRuntimeOptionsTests.cs +++ b/test/Dapr.Actors.Test/Runtime/ActorRuntimeOptionsTests.cs @@ -113,5 +113,14 @@ namespace Dapr.Actors.Test.Runtime action.Should().Throw(); } + + [Fact] + public void SettingRemindersStoragePartitionsToLessThanZero_Fails() + { + var options = new ActorRuntimeOptions(); + Action action = () => options.RemindersStoragePartitions = -1; + + action.Should().Throw(); + } } } diff --git a/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs b/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs index 0671879b..33418c90 100644 --- a/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs +++ b/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs @@ -7,6 +7,7 @@ namespace Dapr.Actors.Test { using System; using System.Buffers; + using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; @@ -144,6 +145,51 @@ namespace Dapr.Actors.Test element = root.GetProperty("drainRebalancedActors"); Assert.True(element.GetBoolean()); + + try { + element = root.GetProperty("remindersStoragePartitions"); + Assert.False(true, "remindersStoragePartitions should not be serialized"); + } + catch (Exception ex) { + Assert.IsType(ex); + } + + } + + [Fact] + public async Task TestActorSettingsWithRemindersStoragePartitions() + { + var actorType = typeof(TestActor); + + var options = new ActorRuntimeOptions(); + options.Actors.RegisterActor(); + 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 writer = new ArrayBufferWriter(); + 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()); + } private sealed class TestActor : Actor, ITestActor