diff options
Diffstat (limited to 'src/csharp/GrpcCoreTests/ClientServerTest.cs')
-rw-r--r-- | src/csharp/GrpcCoreTests/ClientServerTest.cs | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/src/csharp/GrpcCoreTests/ClientServerTest.cs b/src/csharp/GrpcCoreTests/ClientServerTest.cs index 4401156520..ba43e4f6a0 100644 --- a/src/csharp/GrpcCoreTests/ClientServerTest.cs +++ b/src/csharp/GrpcCoreTests/ClientServerTest.cs @@ -36,6 +36,7 @@ using NUnit.Framework; using Google.GRPC.Core; using Google.GRPC.Core.Internal; using System.Threading; +using System.Diagnostics; using System.Threading.Tasks; using Google.GRPC.Core.Utils; @@ -51,11 +52,21 @@ namespace Google.GRPC.Core.Tests Marshallers.StringMarshaller, Marshallers.StringMarshaller); - [Test] - public void EmptyCall() + [TestFixtureSetUp] + public void Init() { GrpcEnvironment.Initialize(); + } + + [TestFixtureTearDown] + public void Cleanup() + { + GrpcEnvironment.Shutdown(); + } + [Test] + public void UnaryCall() + { Server server = new Server(); server.AddServiceDefinition( ServerServiceDefinition.CreateBuilder("someService") @@ -69,19 +80,71 @@ namespace Google.GRPC.Core.Tests var call = new Call<string, string>(unaryEchoStringMethod, channel); Assert.AreEqual("ABC", Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken))); + Assert.AreEqual("abcdef", Calls.BlockingUnaryCall(call, "abcdef", default(CancellationToken))); } server.ShutdownAsync().Wait(); + } - GrpcEnvironment.Shutdown(); + [Test] + public void UnaryCallPerformance() + { + Server server = new Server(); + server.AddServiceDefinition( + ServerServiceDefinition.CreateBuilder("someService") + .AddMethod(unaryEchoStringMethod, HandleUnaryEchoString).Build()); + + int port = server.AddPort(host + ":0"); + server.Start(); + + using (Channel channel = new Channel(host + ":" + port)) + { + var call = new Call<string, string>(unaryEchoStringMethod, channel); + + var stopwatch = new Stopwatch(); + stopwatch.Start(); + for (int i = 0; i < 1000; i++) + { + Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)); + } + stopwatch.Stop(); + Console.WriteLine("Elapsed time: " + stopwatch.ElapsedMilliseconds + "ms"); + } + + server.ShutdownAsync().Wait(); } - private void HandleUnaryEchoString(string request, IObserver<string> responseObserver) { + [Test] + public void UnknownMethodHandler() + { + Server server = new Server(); + server.AddServiceDefinition( + ServerServiceDefinition.CreateBuilder("someService").Build()); + + int port = server.AddPort(host + ":0"); + server.Start(); + + using (Channel channel = new Channel(host + ":" + port)) + { + var call = new Call<string, string>(unaryEchoStringMethod, channel); + + try { + Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)); + Assert.Fail(); + } catch(RpcException e) { + Assert.AreEqual(StatusCode.GRPC_STATUS_UNIMPLEMENTED, e.Status.StatusCode); + } + } + + server.ShutdownAsync().Wait(); + } + + private void HandleUnaryEchoString(string request, IObserver<string> responseObserver) + { responseObserver.OnNext(request); responseObserver.OnCompleted(); } - } } |