mirror of https://github.com/dapr/dotnet-sdk.git
Configurable actor reminder storage patitions
This commit is contained in:
parent
1f7f200179
commit
8eee12a7ff
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ namespace Dapr.Actors.Runtime
|
|||
private bool drainRebalancedActors;
|
||||
private JsonSerializerOptions jsonSerializerOptions = JsonSerializerDefaults.Web;
|
||||
private string daprApiToken = null;
|
||||
private int? remindersStoragePartitions = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of <see cref="ActorRegistration" /> instances.
|
||||
|
|
@ -162,6 +163,27 @@ namespace Dapr.Actors.Runtime
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An int used to determine how many partitions to use for reminders storage.
|
||||
/// </summary>
|
||||
public int? RemindersStoragePartitions
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.remindersStoragePartitions;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(remindersStoragePartitions), remindersStoragePartitions, "must be positive");
|
||||
}
|
||||
|
||||
this.remindersStoragePartitions = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP endpoint URI used to communicate with the Dapr sidecar.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -113,5 +113,14 @@ namespace Dapr.Actors.Test.Runtime
|
|||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingRemindersStoragePartitionsToLessThanZero_Fails()
|
||||
{
|
||||
var options = new ActorRuntimeOptions();
|
||||
Action action = () => options.RemindersStoragePartitions = -1;
|
||||
|
||||
action.Should().Throw<ArgumentOutOfRangeException>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<KeyNotFoundException>(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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());
|
||||
|
||||
}
|
||||
|
||||
private sealed class TestActor : Actor, ITestActor
|
||||
|
|
|
|||
Loading…
Reference in New Issue