blob: 1edeedae2fa1555a50d40029704b296204b171cd [file] [log] [blame]
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -07001#region Copyright notice and license
2
Jan Tattermusch42140522016-03-25 17:13:24 -07003// Copyright 2015-2016, Google Inc.
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -07004// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
10// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following disclaimer
14// in the documentation and/or other materials provided with the
15// distribution.
16// * Neither the name of Google Inc. nor the names of its
17// contributors may be used to endorse or promote products derived from
18// this software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#endregion
33
34using System;
35using System.Collections.Generic;
36using System.Threading;
37using System.Threading.Tasks;
38using Google.Protobuf;
39using Grpc.Core;
40using Grpc.Core.Utils;
41
42namespace Grpc.Testing
43{
44 /// <summary>
45 /// Implementation of BenchmarkService server
46 /// </summary>
47 public class BenchmarkServiceImpl : BenchmarkService.IBenchmarkService
48 {
Jan Tattermuschc8485022016-03-21 12:27:18 -070049 public BenchmarkServiceImpl()
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070050 {
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070051 }
52
53 public Task<SimpleResponse> UnaryCall(SimpleRequest request, ServerCallContext context)
54 {
Jan Tattermuschc8485022016-03-21 12:27:18 -070055 var response = new SimpleResponse { Payload = CreateZerosPayload(request.ResponseSize) };
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070056 return Task.FromResult(response);
57 }
58
59 public async Task StreamingCall(IAsyncStreamReader<SimpleRequest> requestStream, IServerStreamWriter<SimpleResponse> responseStream, ServerCallContext context)
60 {
61 await requestStream.ForEachAsync(async request =>
62 {
Jan Tattermuschc8485022016-03-21 12:27:18 -070063 var response = new SimpleResponse { Payload = CreateZerosPayload(request.ResponseSize) };
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070064 await responseStream.WriteAsync(response);
65 });
66 }
67
68 private static Payload CreateZerosPayload(int size)
69 {
70 return new Payload { Body = ByteString.CopyFrom(new byte[size]) };
71 }
72 }
73}