From 680c3d0e29f3777c39b33f988c71e74fd9d89617 Mon Sep 17 00:00:00 2001 From: Kosta Petan Date: Fri, 6 Dec 2024 13:59:36 +0100 Subject: [PATCH] configure surrogates for Orleans tests --- .../GrpcGateway.cs | 4 +- .../GrpcGatewayServiceTests.cs | 2 +- .../Helpers/Orleans/ClusterFixture.cs | 10 +++- .../Orleans/SiloBuilderConfigurator.cs | 18 +++++++ .../Orleans/Surrogates/AgentIdSurrogate.cs | 35 ++++++++++++ .../Orleans/Surrogates/AgentStateSurrogate.cs | 53 ++++++++++++++++++ .../Orleans/Surrogates/CloudEventSurrogate.cs | 46 ++++++++++++++++ .../RegisterAgentTypeRequestSurrogate.cs | 41 ++++++++++++++ .../RegisterAgentTypeResponseSurrogate.cs | 41 ++++++++++++++ .../Orleans/Surrogates/RpcRequestSurrogate.cs | 54 +++++++++++++++++++ .../Surrogates/RpcResponseSurrogate.cs | 46 ++++++++++++++++ 11 files changed, 345 insertions(+), 5 deletions(-) create mode 100644 dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/SiloBuilderConfigurator.cs create mode 100644 dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/AgentIdSurrogate.cs create mode 100644 dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/AgentStateSurrogate.cs create mode 100644 dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/CloudEventSurrogate.cs create mode 100644 dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RegisterAgentTypeRequestSurrogate.cs create mode 100644 dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RegisterAgentTypeResponseSurrogate.cs create mode 100644 dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RpcRequestSurrogate.cs create mode 100644 dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RpcResponseSurrogate.cs diff --git a/dotnet/src/Microsoft.AutoGen/Microsoft.AutoGen.Runtime.Grpc/GrpcGateway.cs b/dotnet/src/Microsoft.AutoGen/Microsoft.AutoGen.Runtime.Grpc/GrpcGateway.cs index ed2b2ed3b3bd..980be774198f 100644 --- a/dotnet/src/Microsoft.AutoGen/Microsoft.AutoGen.Runtime.Grpc/GrpcGateway.cs +++ b/dotnet/src/Microsoft.AutoGen/Microsoft.AutoGen.Runtime.Grpc/GrpcGateway.cs @@ -233,9 +233,9 @@ public async ValueTask InvokeRequest(RpcRequest request, Cancellati return response; } - public ValueTask RegisterAgentTypeAsync(RegisterAgentTypeRequest request) + public async ValueTask RegisterAgentTypeAsync(RegisterAgentTypeRequest request) { - throw new NotImplementedException(); + return new RegisterAgentTypeResponse(); } public ValueTask InvokeRequest(RpcRequest request) diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/GrpcGatewayServiceTests.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/GrpcGatewayServiceTests.cs index 773440a65146..6b496d58c409 100644 --- a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/GrpcGatewayServiceTests.cs +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/GrpcGatewayServiceTests.cs @@ -49,7 +49,7 @@ public async Task Test_SaveState() var service = new GrpcGatewayService(gateway); var callContext = TestServerCallContext.Create(); - var response = await service.SaveState(new AgentState { }, callContext); + var response = await service.SaveState(new AgentState { AgentId = new AgentId { Key = "", Type = "" } }, callContext); response.Should().NotBeNull(); } diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/ClusterFixture.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/ClusterFixture.cs index 494814bfd324..9db2f7f654d4 100644 --- a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/ClusterFixture.cs +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/ClusterFixture.cs @@ -7,9 +7,15 @@ namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans; public sealed class ClusterFixture : IDisposable { - public TestCluster Cluster { get; } = new TestClusterBuilder().Build(); + public ClusterFixture() + { + var builder = new TestClusterBuilder(); + builder.AddSiloBuilderConfigurator(); + Cluster = builder.Build(); + Cluster.Deploy(); - public ClusterFixture() => Cluster.Deploy(); + } + public TestCluster Cluster { get; } void IDisposable.Dispose() => Cluster.StopAllSilos(); } diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/SiloBuilderConfigurator.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/SiloBuilderConfigurator.cs new file mode 100644 index 000000000000..84d404e1f6bc --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/SiloBuilderConfigurator.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SiloBuilderConfigurator.cs + +using Orleans.Serialization; +using Orleans.TestingHost; + +namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans; + +public class SiloBuilderConfigurator : ISiloConfigurator +{ + public void Configure(ISiloBuilder siloBuilder) + { + siloBuilder.ConfigureServices(services => + { + services.AddSerializer(a=> a.AddProtobufSerializer()); + }); + } +} diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/AgentIdSurrogate.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/AgentIdSurrogate.cs new file mode 100644 index 000000000000..50f73ab36bd0 --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/AgentIdSurrogate.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// AgentIdSurrogate.cs +using Microsoft.AutoGen.Abstractions; + +namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates; + +[GenerateSerializer] +public struct AgentIdSurrogate +{ + [Id(0)] + public string Key; + [Id(1)] + public string Type; +} + +[RegisterConverter] +public sealed class AgentIdSurrogateConverter : + IConverter +{ + public AgentId ConvertFromSurrogate( + in AgentIdSurrogate surrogate) => + new AgentId + { + Key = surrogate.Key, + Type = surrogate.Type + }; + + public AgentIdSurrogate ConvertToSurrogate( + in AgentId value) => + new AgentIdSurrogate + { + Key = value.Key, + Type = value.Type + }; +} diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/AgentStateSurrogate.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/AgentStateSurrogate.cs new file mode 100644 index 000000000000..31aa7cc5670a --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/AgentStateSurrogate.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// AgentStateSurrogate.cs + +using Google.Protobuf; +using Google.Protobuf.WellKnownTypes; +using Microsoft.AutoGen.Abstractions; + +namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates; + +[GenerateSerializer] +public struct AgentStateSurrogate +{ + [Id(0)] + public string Id; + [Id(1)] + public string TextData; + [Id(2)] + public ByteString BinaryData; + [Id(3)] + public AgentId AgentId; + [Id(4)] + public string Etag; + [Id(5)] + public Any ProtoData; +} + +[RegisterConverter] +public sealed class AgentStateSurrogateConverter : + IConverter +{ + public AgentState ConvertFromSurrogate( + in AgentStateSurrogate surrogate) => + new AgentState + { + TextData = surrogate.TextData, + BinaryData = surrogate.BinaryData, + AgentId = surrogate.AgentId, + ProtoData = surrogate.ProtoData, + ETag = surrogate.Etag + }; + + public AgentStateSurrogate ConvertToSurrogate( + in AgentState value) => + new AgentStateSurrogate + { + AgentId = value.AgentId, + BinaryData = value.BinaryData, + TextData = value.TextData, + Etag = value.ETag, + ProtoData = value.ProtoData + }; +} + diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/CloudEventSurrogate.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/CloudEventSurrogate.cs new file mode 100644 index 000000000000..62e65c4091f8 --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/CloudEventSurrogate.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// CloudEventSurrogate.cs + +using Google.Protobuf; +using Google.Protobuf.WellKnownTypes; +using Microsoft.AutoGen.Abstractions; + +namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates; + +// TODO: Add the rest of the properties +[GenerateSerializer] +public struct CloudEventSurrogate +{ + [Id(0)] + public string Id; + [Id(1)] + public string TextData; + [Id(2)] + public ByteString BinaryData; + [Id(3)] + public Any ProtoData; +} + +[RegisterConverter] +public sealed class CloudEventSurrogateConverter : + IConverter +{ + public CloudEvent ConvertFromSurrogate( + in CloudEventSurrogate surrogate) => + new CloudEvent + { + TextData = surrogate.TextData, + BinaryData = surrogate.BinaryData , + Id = surrogate.Id + }; + + public CloudEventSurrogate ConvertToSurrogate( + in CloudEvent value) => + new CloudEventSurrogate + { + TextData = value.TextData, + BinaryData = value.BinaryData, + Id = value.Id, + ProtoData = value.ProtoData + }; +} diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RegisterAgentTypeRequestSurrogate.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RegisterAgentTypeRequestSurrogate.cs new file mode 100644 index 000000000000..89a83a3d3214 --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RegisterAgentTypeRequestSurrogate.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// RegisterAgentTypeRequestSurrogate.cs + +using Google.Protobuf.Collections; +using Microsoft.AutoGen.Abstractions; + +namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates; + +[GenerateSerializer] +public struct RegisterAgentTypeRequestSurrogate +{ + [Id(0)] + public string RequestId; + [Id(1)] + public string Type; + [Id(2)] + public RepeatedField Events; +} + +[RegisterConverter] +public sealed class RegisterAgentTypeRequestSurrogateConverter : + IConverter +{ + public RegisterAgentTypeRequest ConvertFromSurrogate( + in RegisterAgentTypeRequestSurrogate surrogate) => + new RegisterAgentTypeRequest() + { + RequestId = surrogate.RequestId, + Type = surrogate.Type, + // TODO : Map Events + }; + + public RegisterAgentTypeRequestSurrogate ConvertToSurrogate( + in RegisterAgentTypeRequest value) => + new RegisterAgentTypeRequestSurrogate + { + RequestId = value.RequestId, + Type = value.Type, + Events = value.Events + }; +} diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RegisterAgentTypeResponseSurrogate.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RegisterAgentTypeResponseSurrogate.cs new file mode 100644 index 000000000000..012a2bf5d8eb --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RegisterAgentTypeResponseSurrogate.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// RegisterAgentTypeResponseSurrogate.cs + +using Microsoft.AutoGen.Abstractions; + +namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates; + +[GenerateSerializer] +public struct RegisterAgentTypeResponseSurrogate +{ + [Id(0)] + public string RequestId; + [Id(1)] + public bool Success; + [Id(2)] + public string Error; +} + +[RegisterConverter] +public sealed class RegisterAgentTypeResponseSurrogateConverter : + IConverter +{ + public RegisterAgentTypeResponse ConvertFromSurrogate( + in RegisterAgentTypeResponseSurrogate surrogate) => + new RegisterAgentTypeResponse + { + RequestId = surrogate.RequestId, + Success = surrogate.Success, + Error = surrogate.Error + }; + + public RegisterAgentTypeResponseSurrogate ConvertToSurrogate( + in RegisterAgentTypeResponse value) => + new RegisterAgentTypeResponseSurrogate + { + RequestId = value.RequestId, + Success = value.Success, + Error = value.Error + }; +} + diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RpcRequestSurrogate.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RpcRequestSurrogate.cs new file mode 100644 index 000000000000..a1ff802197b1 --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RpcRequestSurrogate.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// RpcRequestSurrogate.cs + +using Google.Protobuf.Collections; +using Microsoft.AutoGen.Abstractions; + +namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates; + +[GenerateSerializer] +public struct RpcRequestSurrogate +{ + [Id(0)] + public string RequestId; + [Id(1)] + public AgentId Source; + [Id(2)] + public AgentId Target; + [Id(3)] + public string Method; + [Id(4)] + public Payload Payload; + [Id(5)] + public MapField Metadata; +} + +[RegisterConverter] +public sealed class RpcRequestSurrogateConverter : + IConverter +{ + public RpcRequest ConvertFromSurrogate( + in RpcRequestSurrogate surrogate) => + new RpcRequest + { + RequestId = surrogate.RequestId, + Source = surrogate.Source, + Target = surrogate.Target, + Method = surrogate.Method, + Payload = surrogate.Payload, + // TODO: Add Metadata Metadata = surrogate.Metadata + }; + + public RpcRequestSurrogate ConvertToSurrogate( + in RpcRequest value) => + new RpcRequestSurrogate + { + RequestId = value.RequestId, + Source = value.Source, + Target = value.Target, + Method = value.Method, + Payload = value.Payload, + Metadata = value.Metadata + }; +} + diff --git a/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RpcResponseSurrogate.cs b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RpcResponseSurrogate.cs new file mode 100644 index 000000000000..f873482819f1 --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/Surrogates/RpcResponseSurrogate.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// RpcResponseSurrogate.cs + +using Google.Protobuf.Collections; +using Microsoft.AutoGen.Abstractions; + +namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates; + +[GenerateSerializer] +public struct RpcResponseSurrogate +{ + [Id(0)] + public string RequestId; + [Id(1)] + public Payload Payload; + [Id(2)] + public string Error; + [Id(3)] + public MapField Metadata; +} + +[RegisterConverter] +public sealed class RpcResponseurrogateConverter : + IConverter +{ + public RpcResponse ConvertFromSurrogate( + in RpcResponseSurrogate surrogate) => + new RpcResponse + { + RequestId = surrogate.RequestId, + Payload = surrogate.Payload, + Error = surrogate.Error, + // TODO: Add Metadata = value.Metadata + }; + + public RpcResponseSurrogate ConvertToSurrogate( + in RpcResponse value) => + new RpcResponseSurrogate + { + RequestId = value.RequestId, + Payload = value.Payload, + Error = value.Error, + Metadata = value.Metadata + }; +} +