Skip to content

Commit 680c3d0

Browse files
committed
configure surrogates for Orleans tests
1 parent f276683 commit 680c3d0

File tree

11 files changed

+345
-5
lines changed

11 files changed

+345
-5
lines changed

dotnet/src/Microsoft.AutoGen/Microsoft.AutoGen.Runtime.Grpc/GrpcGateway.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ public async ValueTask<RpcResponse> InvokeRequest(RpcRequest request, Cancellati
233233
return response;
234234
}
235235

236-
public ValueTask<RegisterAgentTypeResponse> RegisterAgentTypeAsync(RegisterAgentTypeRequest request)
236+
public async ValueTask<RegisterAgentTypeResponse> RegisterAgentTypeAsync(RegisterAgentTypeRequest request)
237237
{
238-
throw new NotImplementedException();
238+
return new RegisterAgentTypeResponse();
239239
}
240240

241241
public ValueTask<RpcResponse> InvokeRequest(RpcRequest request)

dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/GrpcGatewayServiceTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task Test_SaveState()
4949
var service = new GrpcGatewayService(gateway);
5050
var callContext = TestServerCallContext.Create();
5151

52-
var response = await service.SaveState(new AgentState { }, callContext);
52+
var response = await service.SaveState(new AgentState { AgentId = new AgentId { Key = "", Type = "" } }, callContext);
5353

5454
response.Should().NotBeNull();
5555
}

dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/Helpers/Orleans/ClusterFixture.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans;
77

88
public sealed class ClusterFixture : IDisposable
99
{
10-
public TestCluster Cluster { get; } = new TestClusterBuilder().Build();
10+
public ClusterFixture()
11+
{
12+
var builder = new TestClusterBuilder();
13+
builder.AddSiloBuilderConfigurator<SiloBuilderConfigurator>();
14+
Cluster = builder.Build();
15+
Cluster.Deploy();
1116

12-
public ClusterFixture() => Cluster.Deploy();
17+
}
18+
public TestCluster Cluster { get; }
1319

1420
void IDisposable.Dispose() => Cluster.StopAllSilos();
1521
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// SiloBuilderConfigurator.cs
3+
4+
using Orleans.Serialization;
5+
using Orleans.TestingHost;
6+
7+
namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans;
8+
9+
public class SiloBuilderConfigurator : ISiloConfigurator
10+
{
11+
public void Configure(ISiloBuilder siloBuilder)
12+
{
13+
siloBuilder.ConfigureServices(services =>
14+
{
15+
services.AddSerializer(a=> a.AddProtobufSerializer());
16+
});
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// AgentIdSurrogate.cs
3+
using Microsoft.AutoGen.Abstractions;
4+
5+
namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates;
6+
7+
[GenerateSerializer]
8+
public struct AgentIdSurrogate
9+
{
10+
[Id(0)]
11+
public string Key;
12+
[Id(1)]
13+
public string Type;
14+
}
15+
16+
[RegisterConverter]
17+
public sealed class AgentIdSurrogateConverter :
18+
IConverter<AgentId, AgentIdSurrogate>
19+
{
20+
public AgentId ConvertFromSurrogate(
21+
in AgentIdSurrogate surrogate) =>
22+
new AgentId
23+
{
24+
Key = surrogate.Key,
25+
Type = surrogate.Type
26+
};
27+
28+
public AgentIdSurrogate ConvertToSurrogate(
29+
in AgentId value) =>
30+
new AgentIdSurrogate
31+
{
32+
Key = value.Key,
33+
Type = value.Type
34+
};
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// AgentStateSurrogate.cs
3+
4+
using Google.Protobuf;
5+
using Google.Protobuf.WellKnownTypes;
6+
using Microsoft.AutoGen.Abstractions;
7+
8+
namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates;
9+
10+
[GenerateSerializer]
11+
public struct AgentStateSurrogate
12+
{
13+
[Id(0)]
14+
public string Id;
15+
[Id(1)]
16+
public string TextData;
17+
[Id(2)]
18+
public ByteString BinaryData;
19+
[Id(3)]
20+
public AgentId AgentId;
21+
[Id(4)]
22+
public string Etag;
23+
[Id(5)]
24+
public Any ProtoData;
25+
}
26+
27+
[RegisterConverter]
28+
public sealed class AgentStateSurrogateConverter :
29+
IConverter<AgentState, AgentStateSurrogate>
30+
{
31+
public AgentState ConvertFromSurrogate(
32+
in AgentStateSurrogate surrogate) =>
33+
new AgentState
34+
{
35+
TextData = surrogate.TextData,
36+
BinaryData = surrogate.BinaryData,
37+
AgentId = surrogate.AgentId,
38+
ProtoData = surrogate.ProtoData,
39+
ETag = surrogate.Etag
40+
};
41+
42+
public AgentStateSurrogate ConvertToSurrogate(
43+
in AgentState value) =>
44+
new AgentStateSurrogate
45+
{
46+
AgentId = value.AgentId,
47+
BinaryData = value.BinaryData,
48+
TextData = value.TextData,
49+
Etag = value.ETag,
50+
ProtoData = value.ProtoData
51+
};
52+
}
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// CloudEventSurrogate.cs
3+
4+
using Google.Protobuf;
5+
using Google.Protobuf.WellKnownTypes;
6+
using Microsoft.AutoGen.Abstractions;
7+
8+
namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates;
9+
10+
// TODO: Add the rest of the properties
11+
[GenerateSerializer]
12+
public struct CloudEventSurrogate
13+
{
14+
[Id(0)]
15+
public string Id;
16+
[Id(1)]
17+
public string TextData;
18+
[Id(2)]
19+
public ByteString BinaryData;
20+
[Id(3)]
21+
public Any ProtoData;
22+
}
23+
24+
[RegisterConverter]
25+
public sealed class CloudEventSurrogateConverter :
26+
IConverter<CloudEvent, CloudEventSurrogate>
27+
{
28+
public CloudEvent ConvertFromSurrogate(
29+
in CloudEventSurrogate surrogate) =>
30+
new CloudEvent
31+
{
32+
TextData = surrogate.TextData,
33+
BinaryData = surrogate.BinaryData ,
34+
Id = surrogate.Id
35+
};
36+
37+
public CloudEventSurrogate ConvertToSurrogate(
38+
in CloudEvent value) =>
39+
new CloudEventSurrogate
40+
{
41+
TextData = value.TextData,
42+
BinaryData = value.BinaryData,
43+
Id = value.Id,
44+
ProtoData = value.ProtoData
45+
};
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// RegisterAgentTypeRequestSurrogate.cs
3+
4+
using Google.Protobuf.Collections;
5+
using Microsoft.AutoGen.Abstractions;
6+
7+
namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates;
8+
9+
[GenerateSerializer]
10+
public struct RegisterAgentTypeRequestSurrogate
11+
{
12+
[Id(0)]
13+
public string RequestId;
14+
[Id(1)]
15+
public string Type;
16+
[Id(2)]
17+
public RepeatedField<string> Events;
18+
}
19+
20+
[RegisterConverter]
21+
public sealed class RegisterAgentTypeRequestSurrogateConverter :
22+
IConverter<RegisterAgentTypeRequest, RegisterAgentTypeRequestSurrogate>
23+
{
24+
public RegisterAgentTypeRequest ConvertFromSurrogate(
25+
in RegisterAgentTypeRequestSurrogate surrogate) =>
26+
new RegisterAgentTypeRequest()
27+
{
28+
RequestId = surrogate.RequestId,
29+
Type = surrogate.Type,
30+
// TODO : Map Events
31+
};
32+
33+
public RegisterAgentTypeRequestSurrogate ConvertToSurrogate(
34+
in RegisterAgentTypeRequest value) =>
35+
new RegisterAgentTypeRequestSurrogate
36+
{
37+
RequestId = value.RequestId,
38+
Type = value.Type,
39+
Events = value.Events
40+
};
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// RegisterAgentTypeResponseSurrogate.cs
3+
4+
using Microsoft.AutoGen.Abstractions;
5+
6+
namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates;
7+
8+
[GenerateSerializer]
9+
public struct RegisterAgentTypeResponseSurrogate
10+
{
11+
[Id(0)]
12+
public string RequestId;
13+
[Id(1)]
14+
public bool Success;
15+
[Id(2)]
16+
public string Error;
17+
}
18+
19+
[RegisterConverter]
20+
public sealed class RegisterAgentTypeResponseSurrogateConverter :
21+
IConverter<RegisterAgentTypeResponse, RegisterAgentTypeResponseSurrogate>
22+
{
23+
public RegisterAgentTypeResponse ConvertFromSurrogate(
24+
in RegisterAgentTypeResponseSurrogate surrogate) =>
25+
new RegisterAgentTypeResponse
26+
{
27+
RequestId = surrogate.RequestId,
28+
Success = surrogate.Success,
29+
Error = surrogate.Error
30+
};
31+
32+
public RegisterAgentTypeResponseSurrogate ConvertToSurrogate(
33+
in RegisterAgentTypeResponse value) =>
34+
new RegisterAgentTypeResponseSurrogate
35+
{
36+
RequestId = value.RequestId,
37+
Success = value.Success,
38+
Error = value.Error
39+
};
40+
}
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// RpcRequestSurrogate.cs
3+
4+
using Google.Protobuf.Collections;
5+
using Microsoft.AutoGen.Abstractions;
6+
7+
namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates;
8+
9+
[GenerateSerializer]
10+
public struct RpcRequestSurrogate
11+
{
12+
[Id(0)]
13+
public string RequestId;
14+
[Id(1)]
15+
public AgentId Source;
16+
[Id(2)]
17+
public AgentId Target;
18+
[Id(3)]
19+
public string Method;
20+
[Id(4)]
21+
public Payload Payload;
22+
[Id(5)]
23+
public MapField<string, string> Metadata;
24+
}
25+
26+
[RegisterConverter]
27+
public sealed class RpcRequestSurrogateConverter :
28+
IConverter<RpcRequest, RpcRequestSurrogate>
29+
{
30+
public RpcRequest ConvertFromSurrogate(
31+
in RpcRequestSurrogate surrogate) =>
32+
new RpcRequest
33+
{
34+
RequestId = surrogate.RequestId,
35+
Source = surrogate.Source,
36+
Target = surrogate.Target,
37+
Method = surrogate.Method,
38+
Payload = surrogate.Payload,
39+
// TODO: Add Metadata Metadata = surrogate.Metadata
40+
};
41+
42+
public RpcRequestSurrogate ConvertToSurrogate(
43+
in RpcRequest value) =>
44+
new RpcRequestSurrogate
45+
{
46+
RequestId = value.RequestId,
47+
Source = value.Source,
48+
Target = value.Target,
49+
Method = value.Method,
50+
Payload = value.Payload,
51+
Metadata = value.Metadata
52+
};
53+
}
54+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// RpcResponseSurrogate.cs
3+
4+
using Google.Protobuf.Collections;
5+
using Microsoft.AutoGen.Abstractions;
6+
7+
namespace Microsoft.AutoGen.Runtime.Grpc.Tests.Helpers.Orleans.Surrogates;
8+
9+
[GenerateSerializer]
10+
public struct RpcResponseSurrogate
11+
{
12+
[Id(0)]
13+
public string RequestId;
14+
[Id(1)]
15+
public Payload Payload;
16+
[Id(2)]
17+
public string Error;
18+
[Id(3)]
19+
public MapField<string, string> Metadata;
20+
}
21+
22+
[RegisterConverter]
23+
public sealed class RpcResponseurrogateConverter :
24+
IConverter<RpcResponse, RpcResponseSurrogate>
25+
{
26+
public RpcResponse ConvertFromSurrogate(
27+
in RpcResponseSurrogate surrogate) =>
28+
new RpcResponse
29+
{
30+
RequestId = surrogate.RequestId,
31+
Payload = surrogate.Payload,
32+
Error = surrogate.Error,
33+
// TODO: Add Metadata = value.Metadata
34+
};
35+
36+
public RpcResponseSurrogate ConvertToSurrogate(
37+
in RpcResponse value) =>
38+
new RpcResponseSurrogate
39+
{
40+
RequestId = value.RequestId,
41+
Payload = value.Payload,
42+
Error = value.Error,
43+
Metadata = value.Metadata
44+
};
45+
}
46+

0 commit comments

Comments
 (0)