Пример #1
0
        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));
        }
Пример #2
0
        public void TestActorSettings()
        {
            var actorType    = typeof(TestActor);
            var actorRuntime = new ActorRuntime();

            Assert.Empty(actorRuntime.RegisteredActorTypes);

            actorRuntime.ConfigureActorSettings(a =>
            {
                a.ActorIdleTimeout        = TimeSpan.FromSeconds(33);
                a.ActorScanInterval       = TimeSpan.FromSeconds(44);
                a.DrainOngoingCallTimeout = TimeSpan.FromSeconds(55);
                a.DrainRebalancedActors   = true;
            });

            actorRuntime.RegisterActor <TestActor>();

            Assert.Contains(actorType.Name, actorRuntime.RegisteredActorTypes, StringComparer.InvariantCulture);

            ArrayBufferWriter <byte> writer = new ArrayBufferWriter <byte>();

            actorRuntime.SerializeSettingsAndRegisteredTypes(writer).GetAwaiter().GetResult();

            // 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());
        }
        public void DaprFormat_TimeSpan_Parsing(string daprFormatTimeSpanJsonString, TimeSpan expectedDeserializedValue)
        {
            using var textReader     = new StringReader(daprFormatTimeSpanJsonString);
            using var jsonTextReader = new JsonTextReader(textReader);

            while (jsonTextReader.TokenType != JsonToken.String)
            {
                jsonTextReader.Read();
            }

            var timespanString       = (string)jsonTextReader.Value;
            var deserializedTimeSpan = ConverterUtils.ConvertTimeSpanFromDaprFormat(timespanString);

            Assert.Equal(expectedDeserializedValue, deserializedTimeSpan);
        }