blob: 4ebd294d50bae8922eff5887d34adb2ade91e66e [file] [log] [blame]
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -07001#region Copyright notice and license
2
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003// Copyright 2015-2016 gRPC authors.
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -07004//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -07008//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009// http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070010//
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070016
17#endregion
18
19using System;
20using System.Collections.Generic;
21using System.Threading;
22using System.Threading.Tasks;
23using Google.Protobuf;
24using Grpc.Core;
25using Grpc.Core.Utils;
26
27namespace Grpc.Testing
28{
29 /// <summary>
30 /// Implementation of BenchmarkService server
31 /// </summary>
Jan Tattermuschd39426d2016-03-14 16:07:52 -070032 public class BenchmarkServiceImpl : BenchmarkService.BenchmarkServiceBase
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070033 {
Jan Tattermuschc8485022016-03-21 12:27:18 -070034 public BenchmarkServiceImpl()
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070035 {
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070036 }
37
Jan Tattermuschd39426d2016-03-14 16:07:52 -070038 public override Task<SimpleResponse> UnaryCall(SimpleRequest request, ServerCallContext context)
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070039 {
Jan Tattermuschc8485022016-03-21 12:27:18 -070040 var response = new SimpleResponse { Payload = CreateZerosPayload(request.ResponseSize) };
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070041 return Task.FromResult(response);
42 }
43
Jan Tattermuschd39426d2016-03-14 16:07:52 -070044 public override async Task StreamingCall(IAsyncStreamReader<SimpleRequest> requestStream, IServerStreamWriter<SimpleResponse> responseStream, ServerCallContext context)
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070045 {
46 await requestStream.ForEachAsync(async request =>
47 {
Jan Tattermuschc8485022016-03-21 12:27:18 -070048 var response = new SimpleResponse { Payload = CreateZerosPayload(request.ResponseSize) };
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070049 await responseStream.WriteAsync(response);
50 });
51 }
52
53 private static Payload CreateZerosPayload(int size)
54 {
55 return new Payload { Body = ByteString.CopyFrom(new byte[size]) };
56 }
57 }
58}