diff --git a/src/csharp/Grpc.sln b/src/csharp/Grpc.sln index c46c4d67620..2fd10cb94af 100644 --- a/src/csharp/Grpc.sln +++ b/src/csharp/Grpc.sln @@ -1,8 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcDemo", "GrpcDemo\GrpcDemo.csproj", "{61ECB8EE-0C96-4F8E-B187-8E4D227417C0}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcApi", "GrpcApi\GrpcApi.csproj", "{7DC1433E-3225-42C7-B7EA-546D56E27A4B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcCore", "GrpcCore\GrpcCore.csproj", "{CCC4440E-49F7-4790-B0AF-FEABB0837AE7}" @@ -11,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcCoreTests", "GrpcCoreTe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcApiTests", "GrpcApiTests\GrpcApiTests.csproj", "{143B1C29-C442-4BE0-BF3F-A8F92288AC9F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MathClient", "MathClient\MathClient.csproj", "{61ECB8EE-0C96-4F8E-B187-8E4D227417C0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InteropClient", "InteropClient\InteropClient.csproj", "{C61154BA-DD4A-4838-8420-0162A28925E0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -33,12 +35,16 @@ Global {86EC5CB4-4EA2-40A2-8057-86542A0353BB}.Debug|x86.Build.0 = Debug|Any CPU {86EC5CB4-4EA2-40A2-8057-86542A0353BB}.Release|x86.ActiveCfg = Release|Any CPU {86EC5CB4-4EA2-40A2-8057-86542A0353BB}.Release|x86.Build.0 = Release|Any CPU + {C61154BA-DD4A-4838-8420-0162A28925E0}.Debug|x86.ActiveCfg = Debug|x86 + {C61154BA-DD4A-4838-8420-0162A28925E0}.Debug|x86.Build.0 = Debug|x86 + {C61154BA-DD4A-4838-8420-0162A28925E0}.Release|x86.ActiveCfg = Release|x86 + {C61154BA-DD4A-4838-8420-0162A28925E0}.Release|x86.Build.0 = Release|x86 {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Debug|x86.ActiveCfg = Debug|Any CPU {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Debug|x86.Build.0 = Debug|Any CPU {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Release|x86.ActiveCfg = Release|Any CPU {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = GrpcDemo\GrpcDemo.csproj + StartupItem = GrpcApi\GrpcApi.csproj EndGlobalSection EndGlobal diff --git a/src/csharp/GrpcApi/GrpcApi.csproj b/src/csharp/GrpcApi/GrpcApi.csproj index bf457a1e6b5..f0f11de2167 100644 --- a/src/csharp/GrpcApi/GrpcApi.csproj +++ b/src/csharp/GrpcApi/GrpcApi.csproj @@ -47,13 +47,13 @@ - + diff --git a/src/csharp/GrpcApi/Examples.cs b/src/csharp/GrpcApi/MathExamples.cs similarity index 98% rename from src/csharp/GrpcApi/Examples.cs rename to src/csharp/GrpcApi/MathExamples.cs index d2a6cc01fdb..43f0cedef6e 100644 --- a/src/csharp/GrpcApi/Examples.cs +++ b/src/csharp/GrpcApi/MathExamples.cs @@ -6,7 +6,7 @@ using Google.GRPC.Core.Utils; namespace math { - public class Examples + public static class MathExamples { public static void DivExample(MathGrpc.IMathServiceClient stub) { diff --git a/src/csharp/GrpcDemo/.gitignore b/src/csharp/InteropClient/.gitignore similarity index 100% rename from src/csharp/GrpcDemo/.gitignore rename to src/csharp/InteropClient/.gitignore diff --git a/src/csharp/InteropClient/InteropClient.cs b/src/csharp/InteropClient/InteropClient.cs new file mode 100644 index 00000000000..62091c5fdc3 --- /dev/null +++ b/src/csharp/InteropClient/InteropClient.cs @@ -0,0 +1,172 @@ +using System; +using NUnit.Framework; +using System.Text.RegularExpressions; +using Google.GRPC.Core; +using Google.ProtocolBuffers; +using grpc.testing; + +namespace InteropClient +{ + class InteropClient + { + private class ClientOptions + { + public bool help; + public string serverHost; + public string serverHostOverride; + public int? serverPort; + public string testCase; + public bool useTls; + public bool useTestCa; + } + + ClientOptions options; + + private InteropClient(ClientOptions options) { + this.options = options; + } + + public static void Main(string[] args) + { + Console.WriteLine("gRPC C# interop testing client"); + ClientOptions options = ParseArguments(args); + + if (options.serverHost == null || !options.serverPort.HasValue || options.testCase == null) + { + Console.WriteLine("Missing required argument."); + Console.WriteLine(); + options.help = true; + } + + if (options.help) + { + Console.WriteLine("Usage:"); + Console.WriteLine(" --server_host=HOSTNAME"); + Console.WriteLine(" --server_host_override=HOSTNAME"); + Console.WriteLine(" --server_port=PORT"); + Console.WriteLine(" --test_case=TESTCASE"); + Console.WriteLine(" --use_tls=BOOLEAN"); + Console.WriteLine(" --use_test_ca=BOOLEAN"); + Console.WriteLine(); + Environment.Exit(1); + } + + var interopClient = new InteropClient(options); + interopClient.Run(); + } + + private void Run() + { + string addr = string.Format("{0}:{1}", options.serverHost, options.serverPort); + using (Channel channel = new Channel(addr)) + { + TestServiceGrpc.ITestServiceClient client = new TestServiceGrpc.TestServiceClientStub(channel); + + RunTestCase(options.testCase, client); + } + + GrpcEnvironment.Shutdown(); + } + + private void RunTestCase(string testCase, TestServiceGrpc.ITestServiceClient client) + { + switch (testCase) + { + case "empty_unary": + RunEmptyUnary(client); + break; + case "large_unary": + RunLargeUnary(client); + break; + default: + throw new ArgumentException("Unknown test case " + testCase); + } + } + + private void RunEmptyUnary(TestServiceGrpc.ITestServiceClient client) + { + Console.WriteLine("running empty_unary"); + var response = client.EmptyCall(Empty.DefaultInstance); + Assert.IsNotNull(response); + } + + private void RunLargeUnary(TestServiceGrpc.ITestServiceClient client) + { + Console.WriteLine("running large_unary"); + var request = SimpleRequest.CreateBuilder() + .SetResponseType(PayloadType.COMPRESSABLE) + .SetResponseSize(314159) + .SetPayload(Payload.CreateBuilder().SetBody(ByteString.CopyFrom(new byte[271828]))) + .Build(); + + var response = client.UnaryCall(request); + + Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type); + Assert.AreEqual(314159, response.Payload.Body.Length); + // TODO: assert that the response is all zeros... + } + + private static ClientOptions ParseArguments(string[] args) + { + var options = new ClientOptions(); + foreach(string arg in args) + { + ParseArgument(arg, options); + if (options.help) + { + break; + } + } + return options; + } + + private static void ParseArgument(string arg, ClientOptions options) + { + Match match; + match = Regex.Match(arg, "--server_host=(.*)"); + if (match.Success) + { + options.serverHost = match.Groups[1].Value.Trim(); + return; + } + + match = Regex.Match(arg, "--server_host_override=(.*)"); + if (match.Success) + { + options.serverHostOverride = match.Groups[1].Value.Trim(); + return; + } + + match = Regex.Match(arg, "--server_port=(.*)"); + if (match.Success) + { + options.serverPort = int.Parse(match.Groups[1].Value.Trim()); + return; + } + + match = Regex.Match(arg, "--test_case=(.*)"); + if (match.Success) + { + options.testCase = match.Groups[1].Value.Trim(); + return; + } + + match = Regex.Match(arg, "--use_tls=(.*)"); + if (match.Success) + { + options.useTls = bool.Parse(match.Groups[1].Value.Trim()); + return; + } + + match = Regex.Match(arg, "--use_test_ca=(.*)"); + if (match.Success) + { + options.useTestCa = bool.Parse(match.Groups[1].Value.Trim()); + return; + } + + Console.WriteLine(string.Format("Unrecognized argument \"{0}\"", arg)); + options.help = true; + } + } +} diff --git a/src/csharp/InteropClient/InteropClient.csproj b/src/csharp/InteropClient/InteropClient.csproj new file mode 100644 index 00000000000..ecc1c108759 --- /dev/null +++ b/src/csharp/InteropClient/InteropClient.csproj @@ -0,0 +1,59 @@ + + + + Debug + x86 + 10.0.0 + 2.0 + {C61154BA-DD4A-4838-8420-0162A28925E0} + Exe + InteropClient + InteropClient + InteropClient.InteropClient + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + full + true + bin\Release + prompt + 4 + true + x86 + + + + + False + + + ..\lib\Google.ProtocolBuffers.dll + + + + + + + + + + {CCC4440E-49F7-4790-B0AF-FEABB0837AE7} + GrpcCore + + + {7DC1433E-3225-42C7-B7EA-546D56E27A4B} + GrpcApi + + + \ No newline at end of file diff --git a/src/csharp/InteropClient/Properties/AssemblyInfo.cs b/src/csharp/InteropClient/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..1f3cc19a9de --- /dev/null +++ b/src/csharp/InteropClient/Properties/AssemblyInfo.cs @@ -0,0 +1,22 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. +[assembly: AssemblyTitle("InteropClient")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("jtattermusch")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. +[assembly: AssemblyVersion("1.0.*")] +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/src/csharp/MathClient/.gitignore b/src/csharp/MathClient/.gitignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/src/csharp/MathClient/.gitignore @@ -0,0 +1 @@ +bin diff --git a/src/csharp/GrpcDemo/Program.cs b/src/csharp/MathClient/MathClient.cs similarity index 65% rename from src/csharp/GrpcDemo/Program.cs rename to src/csharp/MathClient/MathClient.cs index c442c32193e..45222abb79b 100644 --- a/src/csharp/GrpcDemo/Program.cs +++ b/src/csharp/MathClient/MathClient.cs @@ -2,25 +2,23 @@ using System; using System.Runtime.InteropServices; using Google.GRPC.Core; using System.Threading; -using math; -namespace Google.GRPC.Demo +namespace math { - class MainClass + class MathClient { public static void Main (string[] args) { using (Channel channel = new Channel("127.0.0.1:23456")) { - MathGrpc.IMathServiceClient stub = new MathGrpc.MathServiceClientStub(channel); - Examples.DivExample(stub); + MathExamples.DivExample(stub); - Examples.FibExample(stub); + MathExamples.FibExample(stub); - Examples.SumExample(stub); + MathExamples.SumExample(stub); - Examples.DivManyExample(stub); + MathExamples.DivManyExample(stub); } GrpcEnvironment.Shutdown(); diff --git a/src/csharp/GrpcDemo/GrpcDemo.csproj b/src/csharp/MathClient/MathClient.csproj similarity index 97% rename from src/csharp/GrpcDemo/GrpcDemo.csproj rename to src/csharp/MathClient/MathClient.csproj index 31ce7f133b3..74213653d21 100644 --- a/src/csharp/GrpcDemo/GrpcDemo.csproj +++ b/src/csharp/MathClient/MathClient.csproj @@ -35,8 +35,8 @@ - + diff --git a/src/csharp/GrpcDemo/Properties/AssemblyInfo.cs b/src/csharp/MathClient/Properties/AssemblyInfo.cs similarity index 95% rename from src/csharp/GrpcDemo/Properties/AssemblyInfo.cs rename to src/csharp/MathClient/Properties/AssemblyInfo.cs index b8e1406da7c..f521cd63f0c 100644 --- a/src/csharp/GrpcDemo/Properties/AssemblyInfo.cs +++ b/src/csharp/MathClient/Properties/AssemblyInfo.cs @@ -3,7 +3,7 @@ using System.Runtime.CompilerServices; // Information about this assembly is defined by the following attributes. // Change them to the values specific to your project. -[assembly: AssemblyTitle ("GrpcDemo")] +[assembly: AssemblyTitle ("MathClient")] [assembly: AssemblyDescription ("")] [assembly: AssemblyConfiguration ("")] [assembly: AssemblyCompany ("")]