blob: ddbfc61a4ef74acc08500d77c384da579d090621 [file] [log] [blame]
Jan Tattermusch20831382015-02-24 14:16:04 -08001#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
34using System;
35using System.Collections.Generic;
36using System.Threading;
37using System.Threading.Tasks;
Jan Tattermusch075dde42015-03-11 18:21:00 -070038using grpc.testing;
Jan Tattermusch20831382015-02-24 14:16:04 -080039using Grpc.Core;
40using Grpc.Core.Utils;
41using NUnit.Framework;
Jan Tattermusch20831382015-02-24 14:16:04 -080042
43namespace 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 Tattermusch7eb3a762015-05-07 14:26:13 -070053 TestService.ITestServiceClient client;
Jan Tattermusch20831382015-02-24 14:16:04 -080054
55 [TestFixtureSetUp]
56 public void Init()
57 {
58 GrpcEnvironment.Initialize();
59
60 server = new Server();
Jan Tattermusch7eb3a762015-05-07 14:26:13 -070061 server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
Jan Tattermusch03e82e22015-05-06 16:37:12 -070062 int port = server.AddListeningPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials());
Jan Tattermusch20831382015-02-24 14:16:04 -080063 server.Start();
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080064
Jan Tattermusch286975f2015-03-12 14:04:36 -070065 var channelArgs = ChannelArgs.CreateBuilder()
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080066 .AddString(ChannelArgs.SslTargetNameOverrideKey, TestCredentials.DefaultHostOverride).Build();
67
68 channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs);
Jan Tattermusch7eb3a762015-05-07 14:26:13 -070069 client = TestService.NewStub(channel);
Jan Tattermusch20831382015-02-24 14:16:04 -080070 }
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 Tattermusch503bbac2015-02-26 18:19:47 -080084 InteropClient.RunEmptyUnary(client);
Jan Tattermusch20831382015-02-24 14:16:04 -080085 }
86
87 [Test]
88 public void LargeUnary()
89 {
Jan Tattermuscha5272b62015-04-30 11:56:46 -070090 InteropClient.RunLargeUnary(client);
Jan Tattermusch20831382015-02-24 14:16:04 -080091 }
92
93 [Test]
94 public void ClientStreaming()
95 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -080096 InteropClient.RunClientStreaming(client);
Jan Tattermusch20831382015-02-24 14:16:04 -080097 }
98
99 [Test]
100 public void ServerStreaming()
101 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -0800102 InteropClient.RunServerStreaming(client);
Jan Tattermusch20831382015-02-24 14:16:04 -0800103 }
104
105 [Test]
106 public void PingPong()
107 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -0800108 InteropClient.RunPingPong(client);
Jan Tattermusch20831382015-02-24 14:16:04 -0800109 }
110
111 [Test]
112 public void EmptyStream()
113 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -0800114 InteropClient.RunEmptyStream(client);
Jan Tattermusch20831382015-02-24 14:16:04 -0800115 }
116
Jan Tattermusche5c44602015-05-01 11:12:34 -0700117 [Test]
118 public void CancelAfterBegin()
119 {
120 InteropClient.RunCancelAfterBegin(client);
121 }
Jan Tattermusch20831382015-02-24 14:16:04 -0800122
Jan Tattermusche5c44602015-05-01 11:12:34 -0700123 [Test]
124 public void CancelAfterFirstResponse()
125 {
126 InteropClient.RunCancelAfterFirstResponse(client);
127 }
Jan Tattermusch20831382015-02-24 14:16:04 -0800128 }
129}