Ejemplo n.º 1
0
 /// <summary>
 /// Registers the identity actors.
 /// </summary>
 /// <param name="actorRuntime">The actor runtime.</param>
 /// <param name="eventPublisher">
 /// The event publisher used to send events on the domain integration bus.
 /// </param>
 /// <param name="eventStore">The event store</param>
 public static void RegisterRoleActors(this ActorRuntime actorRuntime, Func <IEventPublisher> eventPublisher, Func <string, IEventStore> eventStore)
 {
     if (actorRuntime == null)
     {
         throw new ArgumentNullException(nameof(actorRuntime));
     }
     actorRuntime.RegisterActor <RoleActor>(information
                                            => new ActorService(information, (service, id)
                                                                => new RoleActor(
                                                                    service,
                                                                    id,
                                                                    eventPublisher(),
                                                                    eventStore(id.GetId())
                                                                    )
                                                                ));
     actorRuntime.RegisterActor <RoleNameRegistryActor>(information
                                                        => new ActorService(information, (service, id)
                                                                            => new RoleNameRegistryActor(
                                                                                service,
                                                                                id,
                                                                                eventPublisher(),
                                                                                eventStore(id.GetId())
                                                                                )
                                                                            ));
 }
Ejemplo n.º 2
0
        public void TestRegisterOtherTypeAtRuntime()
        {
            var actorType    = typeof(ActorRuntimeTests);
            var actorRuntime = new ActorRuntime();

            actorRuntime.RegisterActor(actorType);

            Assert.DoesNotContain(actorType.Name, actorRuntime.RegisteredActorTypes, StringComparer.InvariantCulture);
        }
Ejemplo n.º 3
0
        public void TestInferredActorType()
        {
            var actorType    = typeof(TestActor);
            var actorRuntime = new ActorRuntime();

            Assert.Empty(actorRuntime.RegisteredActorTypes);

            actorRuntime.RegisterActor <TestActor>();

            Assert.Contains(actorType.Name, actorRuntime.RegisteredActorTypes, StringComparer.InvariantCulture);
        }
Ejemplo n.º 4
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());
        }
Ejemplo n.º 5
0
        public void TestExplicitActorType()
        {
            var actorType    = typeof(RenamedActor);
            var actorRuntime = new ActorRuntime();

            Assert.NotEqual(RenamedActorTypeName, actorType.Name);

            Assert.Empty(actorRuntime.RegisteredActorTypes);

            actorRuntime.RegisterActor <RenamedActor>();

            Assert.Contains(RenamedActorTypeName, actorRuntime.RegisteredActorTypes, StringComparer.InvariantCulture);
        }
Ejemplo n.º 6
0
        public async Task NoActivateMessageFromRuntime()
        {
            var actorType = typeof(MyActor);

            var runtime = new ActorRuntime();

            runtime.RegisterActor <MyActor>();

            var output = new MemoryStream();
            await runtime.DispatchWithoutRemotingAsync("MyActor", "abc", "MyMethod", new MemoryStream(), output);

            string s = Encoding.UTF8.GetString(output.ToArray());

            Assert.Equal("\"hi\"", s);
            Assert.Contains(actorType.Name, runtime.RegisteredActorTypes, StringComparer.InvariantCulture);
            Console.WriteLine("done");
        }