mirror of
https://github.com/microsoft/autogen.git
synced 2025-11-15 01:24:32 +00:00
Restoring the grpc + Orleans server into the project ## Why are these changes needed? This is the distributed agent runtime for .NET that can manage routing messages amongst a fleet of grpc agent runtimes. ## Related issue number ## Checks - [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation to build and test documentation locally. - [x] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [x] I've made sure all auto checks have passed. --------- Co-authored-by: Jack Gerrits <jack@jackgerrits.com> Co-authored-by: Jacob Alber <jaalber@microsoft.com>
75 lines
3.0 KiB
C#
75 lines
3.0 KiB
C#
#pragma warning disable IDE0073
|
|
// Copyright 2019 The gRPC 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 Grpc.Core;
|
|
|
|
namespace Microsoft.AutoGen.RuntimeGateway.Grpc.Tests.Helpers.Grpc;
|
|
|
|
public class TestServerCallContext : ServerCallContext
|
|
{
|
|
private readonly Metadata _requestHeaders;
|
|
private readonly CancellationToken _cancellationToken;
|
|
private readonly Metadata _responseTrailers;
|
|
private readonly AuthContext _authContext;
|
|
private readonly Dictionary<object, object> _userState;
|
|
private WriteOptions? _writeOptions;
|
|
|
|
public Metadata? ResponseHeaders { get; private set; }
|
|
|
|
private TestServerCallContext(Metadata requestHeaders, CancellationToken cancellationToken)
|
|
{
|
|
_requestHeaders = requestHeaders;
|
|
_cancellationToken = cancellationToken;
|
|
_responseTrailers = new Metadata();
|
|
_authContext = new AuthContext(string.Empty, new Dictionary<string, List<AuthProperty>>());
|
|
_userState = new Dictionary<object, object>();
|
|
}
|
|
|
|
protected override string MethodCore => "MethodName";
|
|
protected override string HostCore => "HostName";
|
|
protected override string PeerCore => "PeerName";
|
|
protected override DateTime DeadlineCore { get; }
|
|
protected override Metadata RequestHeadersCore => _requestHeaders;
|
|
protected override CancellationToken CancellationTokenCore => _cancellationToken;
|
|
protected override Metadata ResponseTrailersCore => _responseTrailers;
|
|
protected override Status StatusCore { get; set; }
|
|
protected override WriteOptions? WriteOptionsCore { get => _writeOptions; set { _writeOptions = value; } }
|
|
protected override AuthContext AuthContextCore => _authContext;
|
|
|
|
protected override ContextPropagationToken CreatePropagationTokenCore(ContextPropagationOptions? options)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
protected override Task WriteResponseHeadersAsyncCore(Metadata responseHeaders)
|
|
{
|
|
if (ResponseHeaders != null)
|
|
{
|
|
throw new InvalidOperationException("Response headers have already been written.");
|
|
}
|
|
|
|
ResponseHeaders = responseHeaders;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
protected override IDictionary<object, object> UserStateCore => _userState;
|
|
|
|
public static TestServerCallContext Create(Metadata? requestHeaders = null, CancellationToken cancellationToken = default)
|
|
{
|
|
requestHeaders ??= new Metadata() { { "client-id", Guid.NewGuid().ToString() } };
|
|
return new TestServerCallContext(requestHeaders ?? new Metadata(), cancellationToken);
|
|
}
|
|
}
|