Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
| 3 | // Copyright 2015, Google Inc. |
| 4 | // 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 | |
| 34 | using System; |
| 35 | using System.Collections.Generic; |
| 36 | using System.Threading; |
| 37 | using System.Threading.Tasks; |
Jan Tattermusch | 075dde4 | 2015-03-11 18:21:00 -0700 | [diff] [blame] | 38 | using grpc.testing; |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 39 | using Grpc.Core; |
| 40 | using Grpc.Core.Utils; |
| 41 | using NUnit.Framework; |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 42 | |
| 43 | namespace Grpc.IntegrationTesting |
| 44 | { |
| 45 | /// <summary> |
| 46 | /// Runs interop tests in-process. |
| 47 | /// </summary> |
| 48 | public class InteropClientServerTest |
| 49 | { |
| 50 | string host = "localhost"; |
| 51 | Server server; |
| 52 | Channel channel; |
Jan Tattermusch | 7eb3a76 | 2015-05-07 14:26:13 -0700 | [diff] [blame] | 53 | TestService.ITestServiceClient client; |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 54 | |
| 55 | [TestFixtureSetUp] |
| 56 | public void Init() |
| 57 | { |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 58 | server = new Server(); |
Jan Tattermusch | 7eb3a76 | 2015-05-07 14:26:13 -0700 | [diff] [blame] | 59 | server.AddServiceDefinition(TestService.BindService(new TestServiceImpl())); |
Jan Tattermusch | a96ac05 | 2015-07-24 14:49:30 -0700 | [diff] [blame] | 60 | int port = server.AddPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials()); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 61 | server.Start(); |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 62 | |
Jan Tattermusch | c8f7d10 | 2015-06-08 17:53:45 -0700 | [diff] [blame] | 63 | var options = new List<ChannelOption> |
| 64 | { |
Jan Tattermusch | 2ddb5a6 | 2015-06-08 17:51:36 -0700 | [diff] [blame] | 65 | new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride) |
| 66 | }; |
| 67 | channel = new Channel(host, port, TestCredentials.CreateTestClientCredentials(true), options); |
Jan Tattermusch | b533281 | 2015-07-14 19:29:35 -0700 | [diff] [blame] | 68 | client = TestService.NewClient(channel); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | [TestFixtureTearDown] |
| 72 | public void Cleanup() |
| 73 | { |
| 74 | channel.Dispose(); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 75 | server.ShutdownAsync().Wait(); |
| 76 | GrpcEnvironment.Shutdown(); |
| 77 | } |
| 78 | |
| 79 | [Test] |
| 80 | public void EmptyUnary() |
| 81 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 82 | InteropClient.RunEmptyUnary(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | [Test] |
| 86 | public void LargeUnary() |
| 87 | { |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 88 | InteropClient.RunLargeUnary(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | [Test] |
| 92 | public void ClientStreaming() |
| 93 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 94 | InteropClient.RunClientStreaming(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | [Test] |
| 98 | public void ServerStreaming() |
| 99 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 100 | InteropClient.RunServerStreaming(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | [Test] |
| 104 | public void PingPong() |
| 105 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 106 | InteropClient.RunPingPong(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | [Test] |
| 110 | public void EmptyStream() |
| 111 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 112 | InteropClient.RunEmptyStream(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 113 | } |
| 114 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 115 | [Test] |
| 116 | public void CancelAfterBegin() |
| 117 | { |
| 118 | InteropClient.RunCancelAfterBegin(client); |
| 119 | } |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 120 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 121 | [Test] |
| 122 | public void CancelAfterFirstResponse() |
| 123 | { |
| 124 | InteropClient.RunCancelAfterFirstResponse(client); |
| 125 | } |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 126 | } |
| 127 | } |