diff --git a/src/Dapr.Actors.AspNetCore/DaprActorSetupFilter.cs b/src/Dapr.Actors.AspNetCore/DaprActorSetupFilter.cs index af5c61e4..d4c3b3ca 100644 --- a/src/Dapr.Actors.AspNetCore/DaprActorSetupFilter.cs +++ b/src/Dapr.Actors.AspNetCore/DaprActorSetupFilter.cs @@ -26,8 +26,7 @@ namespace Dapr.Actors.AspNetCore app.UseEndpoints(endpoints => { endpoints.MapHealthChecks("/healthz"); - endpoints.AddDaprConfigRoute(); - endpoints.AddActorActivationRoute(); + endpoints.AddDaprConfigRoute(); endpoints.AddActorDeactivationRoute(); endpoints.AddActorMethodRoute(); endpoints.AddReminderRoute(); diff --git a/src/Dapr.Actors.AspNetCore/EndpointRouteBuilderExtensions.cs b/src/Dapr.Actors.AspNetCore/EndpointRouteBuilderExtensions.cs index d87e218e..a488fdc0 100644 --- a/src/Dapr.Actors.AspNetCore/EndpointRouteBuilderExtensions.cs +++ b/src/Dapr.Actors.AspNetCore/EndpointRouteBuilderExtensions.cs @@ -20,18 +20,7 @@ namespace Dapr.Actors.AspNetCore context.Response.ContentType = "application/json"; await ActorRuntime.Instance.SerializeSettingsAndRegisteredTypes(context.Response.BodyWriter); }); - } - - public static IEndpointConventionBuilder AddActorActivationRoute(this IEndpointRouteBuilder endpoints) - { - return endpoints.MapPost("actors/{actorTypeName}/{actorId}", async context => - { - var routeValues = context.Request.RouteValues; - var actorTypeName = (string)routeValues["actorTypeName"]; - var actorId = (string)routeValues["actorId"]; - await ActorRuntime.ActivateAsync(actorTypeName, actorId); - }); - } + } public static IEndpointConventionBuilder AddActorDeactivationRoute(this IEndpointRouteBuilder endpoints) { diff --git a/src/Dapr.Actors/Runtime/ActorManager.cs b/src/Dapr.Actors/Runtime/ActorManager.cs index 0c2565fa..1b4c2498 100644 --- a/src/Dapr.Actors/Runtime/ActorManager.cs +++ b/src/Dapr.Actors/Runtime/ActorManager.cs @@ -226,9 +226,13 @@ namespace Dapr.Actors.Runtime private async Task DispatchInternalAsync(ActorId actorId, ActorMethodContext actorMethodContext, Func> actorFunc, CancellationToken cancellationToken) { - if (!this.activeActors.TryGetValue(actorId, out var actor)) + if (!this.activeActors.ContainsKey(actorId)) { - // This should never happen, as "Dapr" runtime activates the actor first. if it ever it would mean a bug in "Dapr" runtime. + await this.ActivateActor(actorId); + } + + if (!this.activeActors.TryGetValue(actorId, out var actor)) + { var errorMsg = $"Actor {actorId} is not yet activated."; ActorTrace.Instance.WriteError(TraceType, errorMsg); throw new InvalidOperationException(errorMsg); diff --git a/src/Dapr.Actors/Runtime/ActorRuntime.cs b/src/Dapr.Actors/Runtime/ActorRuntime.cs index 37777967..55da6af5 100644 --- a/src/Dapr.Actors/Runtime/ActorRuntime.cs +++ b/src/Dapr.Actors/Runtime/ActorRuntime.cs @@ -118,17 +118,6 @@ namespace Dapr.Actors.Runtime return writer.FlushAsync(); } - /// - /// Activates an actor for an actor type with given actor id. - /// - /// Actor type name to activate the actor for. - /// Actor id for the actor to be activated. - /// A representing the result of the asynchronous operation. - internal static async Task ActivateAsync(string actorTypeName, string actorId) - { - await Instance.GetActorManager(actorTypeName).ActivateActor(new ActorId(actorId)); - } - /// /// Deactivates an actor for an actor type with given actor id. /// @@ -201,7 +190,7 @@ namespace Dapr.Actors.Runtime { if (!this.actorManagers.TryGetValue(actorTypeName, out var actorManager)) { - var errorMsg = $"Actor type {actorTypeName} is not registerd with Actor runtime."; + var errorMsg = $"Actor type {actorTypeName} is not registered with Actor runtime."; ActorTrace.Instance.WriteError(TraceType, errorMsg); throw new InvalidOperationException(errorMsg); } diff --git a/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs b/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs index 6ee97e79..3e220a34 100644 --- a/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs +++ b/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs @@ -7,8 +7,11 @@ namespace Dapr.Actors.Test { using System; using System.Buffers; + using System.Collections.Generic; + using System.IO; using System.Text; using System.Text.Json; + using System.Threading.Tasks; using Dapr.Actors; using Dapr.Actors.Runtime; using Xunit; @@ -49,6 +52,23 @@ namespace Dapr.Actors.Test Assert.Contains(RenamedActorTypeName, actorRuntime.RegisteredActorTypes, StringComparer.InvariantCulture); } + // This tests the change that removed the Activate message from Dapr runtime -> app. + [Fact] + public void NoActivateMessageFromRuntime() + { + var actorType = typeof(MyActor); + + ActorRuntime.Instance.RegisterActor(); + + var output = new MemoryStream(); + ActorRuntime.DispatchWithoutRemotingAsync("MyActor", "abc", "MyMethod", new MemoryStream(), output).GetAwaiter().GetResult(); + string s = Encoding.UTF8.GetString(output.ToArray()); + + Assert.Equal("\"hi\"", s); + Assert.Contains(actorType.Name, ActorRuntime.Instance.RegisteredActorTypes, StringComparer.InvariantCulture); + Console.WriteLine("done"); + } + [Fact] public void TestActorSettings() { @@ -117,5 +137,23 @@ namespace Dapr.Actors.Test { } } + + private interface IAnotherActor : IActor + { + public Task MyMethod(); + } + + private sealed class MyActor : Actor, IAnotherActor + { + public MyActor(ActorService actorService, ActorId actorId) + : base(actorService, actorId) + { + } + + public Task MyMethod() + { + return Task.FromResult("hi"); + } + } } }