diff options
author | 2015-02-06 11:43:13 -0800 | |
---|---|---|
committer | 2015-02-06 14:17:07 -0800 | |
commit | eb3e76e76c9789dddec88674a79c494eea1ce9c9 (patch) | |
tree | 7911f428992b0592773f837e27e332113b6a4477 /src/csharp/InteropClient | |
parent | a4b63bfc6bffdc1d94bc3a69c831cbae4ec39bd5 (diff) |
scaffolding for interop_client and little bit of project renaming
Diffstat (limited to 'src/csharp/InteropClient')
-rw-r--r-- | src/csharp/InteropClient/.gitignore | 1 | ||||
-rw-r--r-- | src/csharp/InteropClient/InteropClient.cs | 172 | ||||
-rw-r--r-- | src/csharp/InteropClient/InteropClient.csproj | 59 | ||||
-rw-r--r-- | src/csharp/InteropClient/Properties/AssemblyInfo.cs | 22 |
4 files changed, 254 insertions, 0 deletions
diff --git a/src/csharp/InteropClient/.gitignore b/src/csharp/InteropClient/.gitignore new file mode 100644 index 0000000000..ba077a4031 --- /dev/null +++ b/src/csharp/InteropClient/.gitignore @@ -0,0 +1 @@ +bin diff --git a/src/csharp/InteropClient/InteropClient.cs b/src/csharp/InteropClient/InteropClient.cs new file mode 100644 index 0000000000..62091c5fdc --- /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 0000000000..ecc1c10875 --- /dev/null +++ b/src/csharp/InteropClient/InteropClient.csproj @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">x86</Platform> + <ProductVersion>10.0.0</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{C61154BA-DD4A-4838-8420-0162A28925E0}</ProjectGuid> + <OutputType>Exe</OutputType> + <RootNamespace>InteropClient</RootNamespace> + <AssemblyName>InteropClient</AssemblyName> + <StartupObject>InteropClient.InteropClient</StartupObject> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug</OutputPath> + <DefineConstants>DEBUG;</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Externalconsole>true</Externalconsole> + <PlatformTarget>x86</PlatformTarget> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> + <DebugType>full</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release</OutputPath> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Externalconsole>true</Externalconsole> + <PlatformTarget>x86</PlatformTarget> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"> + <Private>False</Private> + </Reference> + <Reference Include="Google.ProtocolBuffers"> + <HintPath>..\lib\Google.ProtocolBuffers.dll</HintPath> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="InteropClient.cs" /> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <ItemGroup> + <ProjectReference Include="..\GrpcCore\GrpcCore.csproj"> + <Project>{CCC4440E-49F7-4790-B0AF-FEABB0837AE7}</Project> + <Name>GrpcCore</Name> + </ProjectReference> + <ProjectReference Include="..\GrpcApi\GrpcApi.csproj"> + <Project>{7DC1433E-3225-42C7-B7EA-546D56E27A4B}</Project> + <Name>GrpcApi</Name> + </ProjectReference> + </ItemGroup> +</Project>
\ 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 0000000000..1f3cc19a9d --- /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("")] + |