diff options
author | Craig Tiller <ctiller@google.com> | 2015-02-18 15:51:50 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-02-18 15:51:50 -0800 |
commit | 2d11c93ab548e359414efdbc5fcd013e8c5779ff (patch) | |
tree | c22a17bc2a71f9d5c42cb1b1a1e232c9913d5b74 /src/csharp/GrpcCoreTests/ClientServerTest.cs | |
parent | d24d13d6eb295f263ffca3def45dd6dc4b053ced (diff) | |
parent | c7851cf0554dde7d04526de8637217b8873c9300 (diff) |
Merge github.com:grpc/grpc into an-update-on-c++
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(); } - } } |