blob: 865556c2426fe62ec17cee22a9dae43199b5b20f [file] [log] [blame]
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -07001#region Copyright notice and license
2
Craig Tiller6169d5f2016-03-31 07:46:18 -07003// Copyright 2015, 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.Diagnostics;
37using System.IO;
38using System.Linq;
39using System.Text.RegularExpressions;
40using System.Threading.Tasks;
41
42using CommandLine;
43using CommandLine.Text;
44using Grpc.Core;
45using Grpc.Core.Utils;
46using Grpc.Testing;
47using NUnit.Framework;
48
49namespace Grpc.IntegrationTesting
50{
51 public class QpsWorker
52 {
53 private class ServerOptions
54 {
Jan Tattermusch678ec902016-08-08 12:54:16 +080055 [Option("driver_port", Default = 0)]
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070056 public int DriverPort { get; set; }
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070057 }
58
59 ServerOptions options;
60
61 private QpsWorker(ServerOptions options)
62 {
63 this.options = options;
64 }
65
66 public static void Run(string[] args)
67 {
Jan Tattermusch90cbde82016-08-08 14:33:28 +080068 var parserResult = Parser.Default.ParseArguments<ServerOptions>(args)
69 .WithNotParsed((x) => Environment.Exit(1))
70 .WithParsed(options =>
71 {
72 var workerServer = new QpsWorker(options);
73 workerServer.RunAsync().Wait();
74 });
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070075 }
76
Jan Tattermusch1cbb5672016-02-18 14:27:28 -080077 private async Task RunAsync()
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070078 {
79 string host = "0.0.0.0";
80 int port = options.DriverPort;
81
Jan Tattermusch1cbb5672016-02-18 14:27:28 -080082 var tcs = new TaskCompletionSource<object>();
83 var workerServiceImpl = new WorkerServiceImpl(() => { Task.Run(() => tcs.SetResult(null)); });
84
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070085 var server = new Server
86 {
Jan Tattermusch1cbb5672016-02-18 14:27:28 -080087 Services = { WorkerService.BindService(workerServiceImpl) },
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070088 Ports = { new ServerPort(host, options.DriverPort, ServerCredentials.Insecure )}
89 };
90 int boundPort = server.Ports.Single().BoundPort;
91 Console.WriteLine("Running qps worker server on " + string.Format("{0}:{1}", host, boundPort));
92 server.Start();
Jan Tattermusch1cbb5672016-02-18 14:27:28 -080093 await tcs.Task;
94 await server.ShutdownAsync();
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070095 }
96 }
97}