Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source generated actor clients #1165

Merged
merged 48 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e4fdc80
Sketch source generators.
philliphoff Oct 4, 2023
eaffdcc
Create interface implementation skeleton.
philliphoff Oct 5, 2023
468fb59
Sketch skeletons of method implementations.
philliphoff Oct 5, 2023
8d7b620
Sketch method parameters.
philliphoff Oct 5, 2023
27b34f5
Sketch implementations for all parameter/return combinations.
philliphoff Oct 5, 2023
ee85ac4
Move generator to src/.
philliphoff Oct 5, 2023
587629c
Make generation opt-in.
philliphoff Oct 5, 2023
997ce6a
Enable explicit client naming.
philliphoff Oct 5, 2023
037497c
Support internal and non-actor interfaces.
philliphoff Oct 5, 2023
ac1c42d
Enable mapping to "actual" method names.
philliphoff Oct 5, 2023
d6c63c5
Sketch initial generators unit test.
philliphoff Oct 6, 2023
a8255b6
Add second test.
philliphoff Oct 6, 2023
1aff78f
Complete basic four args/return cases.
philliphoff Oct 6, 2023
d7fd160
Sketch test for cancellation tokens.
philliphoff Oct 10, 2023
9a3d4c3
Simplify method generation scenarios.
philliphoff Oct 10, 2023
639bd6d
Sketch return of diagnostics.
philliphoff Oct 10, 2023
a14a026
Validate cancellation token ordering.
philliphoff Oct 10, 2023
c931282
Suppport default cancellation tokens.
philliphoff Oct 10, 2023
91a1410
Test attribute variations.
philliphoff Oct 10, 2023
90140c2
Scaffold generators E2E.
philliphoff Oct 10, 2023
b30fd9a
Sketch start of E2E test.
philliphoff Oct 11, 2023
507771f
Add wait for Dapr sidecar start.
philliphoff Oct 11, 2023
1a3b64f
Sketch client test code.
philliphoff Oct 11, 2023
9309d6a
Add wait for actor readiness.
philliphoff Oct 11, 2023
3f85075
Cleanup test project.
philliphoff Oct 11, 2023
03435e8
Add new E2E test project to workflow.
philliphoff Oct 11, 2023
a98dc9a
Attempt to log generator test output.
philliphoff Oct 11, 2023
44a5d1b
Try logging tweaks.
philliphoff Oct 11, 2023
770c1bf
Start cleanup of sample project.
philliphoff Oct 11, 2023
50ab98f
Update sample README.
philliphoff Oct 12, 2023
83f0ce5
Update generators project.
philliphoff Oct 12, 2023
dca76b9
Tweak NuGet package creation.
philliphoff Oct 12, 2023
8af14b9
Add copyright headers.
philliphoff Oct 12, 2023
7ef13ea
Update package reference instructions.
philliphoff Oct 12, 2023
f34c0dd
Merge branch 'master' into philliphoff-generated-actors
halspang Nov 29, 2023
5e1cb7d
Resolve build issue after merge.
philliphoff Dec 1, 2023
fb7a18e
Reset target frameworks.
philliphoff Dec 1, 2023
ae24725
Strip common settings out of project files.
philliphoff Dec 1, 2023
8333c56
Retry build.
philliphoff Dec 4, 2023
fab8e9d
Retry build (again).
philliphoff Dec 4, 2023
8d9e00a
Update reference assemblies for .NET 8.
philliphoff Dec 4, 2023
96fe90c
Add breathing room to timer test.
philliphoff Dec 4, 2023
ea54e96
Bump tests.
philliphoff Dec 4, 2023
a30e710
Merge branch 'master' into philliphoff-generated-actors
philliphoff Feb 14, 2024
eca89da
Merge branch 'master' into philliphoff-generated-actors
philliphoff Feb 14, 2024
15ca8c7
Use .NET 6 for examples.
philliphoff Feb 14, 2024
b907c9b
Merge branch 'master' into philliphoff-generated-actors
philliphoff Feb 16, 2024
cb28b7e
Merge branch 'master' into philliphoff-generated-actors
halspang Feb 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .github/workflows/itests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
- name: Build
# disable deterministic builds, just for test run. Deterministic builds break coverage for some reason
run: dotnet build --configuration release /p:GITHUB_ACTIONS=false
- name: Run Test
- name: Run General Tests
id: tests
continue-on-error: true # proceed if tests fail, the report step will report the failure with more details.
run: |
Expand All @@ -128,8 +128,24 @@ jobs:
/p:CollectCoverage=true \
/p:CoverletOutputFormat=opencover \
/p:GITHUB_ACTIONS=false
- name: Run Generators Tests
id: generator-tests
continue-on-error: true # proceed if tests fail, the report step will report the failure with more details.
run: |
dotnet test ${{ github.workspace }}/test/Dapr.E2E.Test.Actors.Generators/Dapr.E2E.Test.Actors.Generators.csproj \
--configuration Release \
--framework ${{ matrix.framework }} \
--no-build \
--no-restore \
--logger "trx;LogFilePrefix=${{ matrix.prefix }}" \
--logger "GitHubActions;report-warnings=false" \
--logger "console;verbosity=detailed" \
--results-directory "${{ github.workspace }}/TestResults" \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=opencover \
/p:GITHUB_ACTIONS=false
- name: Check test failure in PR
if: github.event_name == 'pull_request' && steps.tests.outcome != 'success'
if: github.event_name == 'pull_request' && (steps.tests.outcome != 'success' || steps.generator-tests.outcome != 'success')
run: exit 1
- name: Upload test coverage
uses: codecov/codecov-action@v1
Expand Down
44 changes: 44 additions & 0 deletions all.sln
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BulkPublishEventExample", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowUnitTest", "examples\Workflow\WorkflowUnitTest\WorkflowUnitTest.csproj", "{8CA09061-2BEF-4506-A763-07062D2BD6AC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GeneratedActor", "GeneratedActor", "{7592AFA4-426B-42F3-AE82-957C86814482}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActorClient", "examples\GeneratedActor\ActorClient\ActorClient.csproj", "{61C24126-F39D-4BEA-96DC-FC87BA730554}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActorCommon", "examples\GeneratedActor\ActorCommon\ActorCommon.csproj", "{CB903D21-4869-42EF-BDD6-5B1CFF674337}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.Actors.Generators", "src\Dapr.Actors.Generators\Dapr.Actors.Generators.csproj", "{980B5FD8-0107-41F7-8FAD-E4E8BAE8A625}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActorService", "examples\GeneratedActor\ActorService\ActorService.csproj", "{7C06FE2D-6C62-48F5-A505-F0D715C554DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.Actors.Generators.Test", "test\Dapr.Actors.Generators.Test\Dapr.Actors.Generators.Test.csproj", "{AF89083D-4715-42E6-93E9-38497D12A8A6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.E2E.Test.Actors.Generators", "test\Dapr.E2E.Test.Actors.Generators\Dapr.E2E.Test.Actors.Generators.csproj", "{B5CDB0DC-B26D-48F1-B934-FE5C1C991940}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cryptography", "examples\Client\Cryptography\Cryptography.csproj", "{C74FBA78-13E8-407F-A173-4555AEE41FF3}"
EndProject
Global
Expand Down Expand Up @@ -250,6 +263,30 @@ Global
{DDC41278-FB60-403A-B969-2AEBD7C2D83C}.Release|Any CPU.Build.0 = Release|Any CPU
{8CA09061-2BEF-4506-A763-07062D2BD6AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CA09061-2BEF-4506-A763-07062D2BD6AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61C24126-F39D-4BEA-96DC-FC87BA730554}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61C24126-F39D-4BEA-96DC-FC87BA730554}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61C24126-F39D-4BEA-96DC-FC87BA730554}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61C24126-F39D-4BEA-96DC-FC87BA730554}.Release|Any CPU.Build.0 = Release|Any CPU
{CB903D21-4869-42EF-BDD6-5B1CFF674337}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB903D21-4869-42EF-BDD6-5B1CFF674337}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB903D21-4869-42EF-BDD6-5B1CFF674337}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB903D21-4869-42EF-BDD6-5B1CFF674337}.Release|Any CPU.Build.0 = Release|Any CPU
{980B5FD8-0107-41F7-8FAD-E4E8BAE8A625}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{980B5FD8-0107-41F7-8FAD-E4E8BAE8A625}.Debug|Any CPU.Build.0 = Debug|Any CPU
{980B5FD8-0107-41F7-8FAD-E4E8BAE8A625}.Release|Any CPU.ActiveCfg = Release|Any CPU
{980B5FD8-0107-41F7-8FAD-E4E8BAE8A625}.Release|Any CPU.Build.0 = Release|Any CPU
{7C06FE2D-6C62-48F5-A505-F0D715C554DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C06FE2D-6C62-48F5-A505-F0D715C554DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C06FE2D-6C62-48F5-A505-F0D715C554DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C06FE2D-6C62-48F5-A505-F0D715C554DE}.Release|Any CPU.Build.0 = Release|Any CPU
{AF89083D-4715-42E6-93E9-38497D12A8A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF89083D-4715-42E6-93E9-38497D12A8A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF89083D-4715-42E6-93E9-38497D12A8A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF89083D-4715-42E6-93E9-38497D12A8A6}.Release|Any CPU.Build.0 = Release|Any CPU
{B5CDB0DC-B26D-48F1-B934-FE5C1C991940}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5CDB0DC-B26D-48F1-B934-FE5C1C991940}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5CDB0DC-B26D-48F1-B934-FE5C1C991940}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5CDB0DC-B26D-48F1-B934-FE5C1C991940}.Release|Any CPU.Build.0 = Release|Any CPU
{C74FBA78-13E8-407F-A173-4555AEE41FF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C74FBA78-13E8-407F-A173-4555AEE41FF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C74FBA78-13E8-407F-A173-4555AEE41FF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -303,6 +340,13 @@ Global
{4A175C27-EAFE-47E7-90F6-873B37863656} = {0EF6EA64-D7C3-420D-9890-EAE8D54A57E6}
{DDC41278-FB60-403A-B969-2AEBD7C2D83C} = {0EF6EA64-D7C3-420D-9890-EAE8D54A57E6}
{8CA09061-2BEF-4506-A763-07062D2BD6AC} = {BF3ED6BF-ADF3-4D25-8E89-02FB8D945CA9}
{7592AFA4-426B-42F3-AE82-957C86814482} = {D687DDC4-66C5-4667-9E3A-FD8B78ECAA78}
{61C24126-F39D-4BEA-96DC-FC87BA730554} = {7592AFA4-426B-42F3-AE82-957C86814482}
{CB903D21-4869-42EF-BDD6-5B1CFF674337} = {7592AFA4-426B-42F3-AE82-957C86814482}
{980B5FD8-0107-41F7-8FAD-E4E8BAE8A625} = {7592AFA4-426B-42F3-AE82-957C86814482}
{7C06FE2D-6C62-48F5-A505-F0D715C554DE} = {7592AFA4-426B-42F3-AE82-957C86814482}
{AF89083D-4715-42E6-93E9-38497D12A8A6} = {DD020B34-460F-455F-8D17-CF4A949F100B}
{B5CDB0DC-B26D-48F1-B934-FE5C1C991940} = {DD020B34-460F-455F-8D17-CF4A949F100B}
{C74FBA78-13E8-407F-A173-4555AEE41FF3} = {A7F41094-8648-446B-AECD-DCC2CC871F73}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
22 changes: 22 additions & 0 deletions examples/GeneratedActor/ActorClient/ActorClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6</TargetFramework>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ActorCommon\ActorCommon.csproj" />
<ProjectReference Include="..\..\..\src\Dapr.Actors\Dapr.Actors.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Dapr.Actors.Generators\Dapr.Actors.Generators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions examples/GeneratedActor/ActorClient/IClientActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ------------------------------------------------------------------------
// Copyright 2023 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------

using Dapr.Actors.Generators;

namespace GeneratedActor;

internal sealed record ClientState(string Value);

[GenerateActorClient]
internal interface IClientActor
{
[ActorMethod(Name = "GetState")]
Task<ClientState> GetStateAsync(CancellationToken cancellationToken = default);

[ActorMethod(Name = "SetState")]
Task SetStateAsync(ClientState state, CancellationToken cancellationToken = default);
}
30 changes: 30 additions & 0 deletions examples/GeneratedActor/ActorClient/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ------------------------------------------------------------------------
// Copyright 2023 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------

using Dapr.Actors;
using Dapr.Actors.Client;
using GeneratedActor;

Console.WriteLine("Testing generated client...");

var proxy = ActorProxy.Create(ActorId.CreateRandom(), "RemoteActor");

using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));

var client = new ClientActorClient(proxy);

var state = await client.GetStateAsync(cancellationTokenSource.Token);

await client.SetStateAsync(new ClientState("Hello, World!"), cancellationTokenSource.Token);

Console.WriteLine("Done!");
14 changes: 14 additions & 0 deletions examples/GeneratedActor/ActorCommon/ActorCommon.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Dapr.Actors\Dapr.Actors.csproj" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions examples/GeneratedActor/ActorCommon/IRemoteActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ------------------------------------------------------------------------
// Copyright 2023 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------

using Dapr.Actors;

namespace GeneratedActor;

public sealed record RemoteState(string Value);

public interface IRemoteActor : IActor
{
Task<RemoteState> GetState();

Task SetState(RemoteState state);
}
15 changes: 15 additions & 0 deletions examples/GeneratedActor/ActorService/ActorService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ActorCommon\ActorCommon.csproj" />
<ProjectReference Include="..\..\..\src\Dapr.Actors.AspNetCore\Dapr.Actors.AspNetCore.csproj" />
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions examples/GeneratedActor/ActorService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ------------------------------------------------------------------------
// Copyright 2023 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------

using GeneratedActor;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddActors(
options =>
{
options.UseJsonSerialization = true;
options.Actors.RegisterActor<RemoteActor>();
});

var app = builder.Build();

app.UseRouting();

#pragma warning disable ASP0014
app.UseEndpoints(
endpoints =>
{
endpoints.MapActorsHandlers();
});

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:56372",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5226",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
45 changes: 45 additions & 0 deletions examples/GeneratedActor/ActorService/RemoteActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ------------------------------------------------------------------------
// Copyright 2023 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------

using Dapr.Actors.Runtime;

namespace GeneratedActor;

internal sealed class RemoteActor : Actor, IRemoteActor
{
private readonly ILogger<RemoteActor> logger;

private RemoteState currentState = new("default");

public RemoteActor(ActorHost host, ILogger<RemoteActor> logger)
: base(host)
{
this.logger = logger;
}

public Task<RemoteState> GetState()
{
this.logger.LogInformation("GetStateAsync called.");

return Task.FromResult(this.currentState);
}

public Task SetState(RemoteState state)
{
this.logger.LogInformation("SetStateAsync called.");

this.currentState = state;

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions examples/GeneratedActor/ActorService/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Loading
Loading