コード例 #1
0
ファイル: InteropClient.cs プロジェクト: Howard1981/grpc
        public static async Task RunClientStreamingAsync(TestService.ITestServiceClient client)
        {
            Console.WriteLine("running client_streaming");

            var bodySizes = new List<int> { 27182, 8, 1828, 45904 }.ConvertAll((size) => StreamingInputCallRequest.CreateBuilder().SetPayload(CreateZerosPayload(size)).Build());

            using (var call = client.StreamingInputCall())
            {
                await call.RequestStream.WriteAllAsync(bodySizes);

                var response = await call.ResponseAsync;
                Assert.AreEqual(74922, response.AggregatedPayloadSize);
            }
            Console.WriteLine("Passed!");
        }
コード例 #2
0
ファイル: InteropClient.cs プロジェクト: Howard1981/grpc
        public static async Task RunCancelAfterBeginAsync(TestService.ITestServiceClient client)
        {
            Console.WriteLine("running cancel_after_begin");

            var cts = new CancellationTokenSource();
            using (var call = client.StreamingInputCall(cancellationToken: cts.Token))
            {
                // TODO(jtattermusch): we need this to ensure call has been initiated once we cancel it.
                await Task.Delay(1000);
                cts.Cancel();

                var ex = Assert.Throws<RpcException>(async () => await call.ResponseAsync);
                Assert.AreEqual(StatusCode.Cancelled, ex.Status.StatusCode);
            }
            Console.WriteLine("Passed!");
        }
コード例 #3
0
ファイル: InteropClient.cs プロジェクト: meisterpeeps/grpc
        public static void RunCancelAfterBegin(TestService.ITestServiceClient client)
        {
            Task.Run(async () =>
            {
                Console.WriteLine("running cancel_after_begin");

                var cts = new CancellationTokenSource();
                using (var call = client.StreamingInputCall(cancellationToken: cts.Token))
                {
                    // TODO(jtattermusch): we need this to ensure call has been initiated once we cancel it.
                    await Task.Delay(1000);
                    cts.Cancel();

                    try
                    {
                        var response = await call.ResponseAsync;
                        Assert.Fail();
                    }
                    catch (RpcException e)
                    {
                        Assert.AreEqual(StatusCode.Cancelled, e.Status.StatusCode);
                    }
                }
                Console.WriteLine("Passed!");
            }).Wait();
        }