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 | { |
| 58 | GrpcEnvironment.Initialize(); |
| 59 | |
| 60 | server = new Server(); |
Jan Tattermusch | 7eb3a76 | 2015-05-07 14:26:13 -0700 | [diff] [blame^] | 61 | server.AddServiceDefinition(TestService.BindService(new TestServiceImpl())); |
Jan Tattermusch | 03e82e2 | 2015-05-06 16:37:12 -0700 | [diff] [blame] | 62 | int port = server.AddListeningPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials()); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 63 | server.Start(); |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 64 | |
Jan Tattermusch | 286975f | 2015-03-12 14:04:36 -0700 | [diff] [blame] | 65 | var channelArgs = ChannelArgs.CreateBuilder() |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 66 | .AddString(ChannelArgs.SslTargetNameOverrideKey, TestCredentials.DefaultHostOverride).Build(); |
| 67 | |
| 68 | channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs); |
Jan Tattermusch | 7eb3a76 | 2015-05-07 14:26:13 -0700 | [diff] [blame^] | 69 | client = TestService.NewStub(channel); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | [TestFixtureTearDown] |
| 73 | public void Cleanup() |
| 74 | { |
| 75 | channel.Dispose(); |
| 76 | |
| 77 | server.ShutdownAsync().Wait(); |
| 78 | GrpcEnvironment.Shutdown(); |
| 79 | } |
| 80 | |
| 81 | [Test] |
| 82 | public void EmptyUnary() |
| 83 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 84 | InteropClient.RunEmptyUnary(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | [Test] |
| 88 | public void LargeUnary() |
| 89 | { |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 90 | InteropClient.RunLargeUnary(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | [Test] |
| 94 | public void ClientStreaming() |
| 95 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 96 | InteropClient.RunClientStreaming(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | [Test] |
| 100 | public void ServerStreaming() |
| 101 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 102 | InteropClient.RunServerStreaming(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | [Test] |
| 106 | public void PingPong() |
| 107 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 108 | InteropClient.RunPingPong(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | [Test] |
| 112 | public void EmptyStream() |
| 113 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 114 | InteropClient.RunEmptyStream(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 117 | [Test] |
| 118 | public void CancelAfterBegin() |
| 119 | { |
| 120 | InteropClient.RunCancelAfterBegin(client); |
| 121 | } |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 122 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 123 | [Test] |
| 124 | public void CancelAfterFirstResponse() |
| 125 | { |
| 126 | InteropClient.RunCancelAfterFirstResponse(client); |
| 127 | } |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 128 | } |
| 129 | } |