当前位置: 首页>>代码示例>>C#>>正文


C# TestService.StreamingInputCall方法代码示例

本文整理汇总了C#中Grpc.Testing.TestService.StreamingInputCall方法的典型用法代码示例。如果您正苦于以下问题:C# TestService.StreamingInputCall方法的具体用法?C# TestService.StreamingInputCall怎么用?C# TestService.StreamingInputCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grpc.Testing.TestService的用法示例。


在下文中一共展示了TestService.StreamingInputCall方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunCancelAfterBeginAsync

        public static async Task RunCancelAfterBeginAsync(TestService.TestServiceClient 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.ThrowsAsync<RpcException>(async () => await call.ResponseAsync);
                Assert.AreEqual(StatusCode.Cancelled, ex.Status.StatusCode);
            }
            Console.WriteLine("Passed!");
        }
开发者ID:wuyunhao,项目名称:grpc,代码行数:16,代码来源:InteropClient.cs

示例2: RunClientCompressedStreamingAsync

        public static async Task RunClientCompressedStreamingAsync(TestService.TestServiceClient client)
        {
            Console.WriteLine("running client_compressed_streaming");
            try
            {
                var probeCall = client.StreamingInputCall(CreateClientCompressionMetadata(false));
                await probeCall.RequestStream.WriteAsync(new StreamingInputCallRequest
                {
                    ExpectCompressed = new BoolValue
                    {
                        Value = true
                    },
                    Payload = CreateZerosPayload(27182)
                });

                // cannot use Assert.ThrowsAsync because it uses Task.Wait and would deadlock.
                await probeCall;
                Assert.Fail();
            }
            catch (RpcException e)
            {
                Assert.AreEqual(StatusCode.InvalidArgument, e.Status.StatusCode);
            }

            var call = client.StreamingInputCall(CreateClientCompressionMetadata(true));
            await call.RequestStream.WriteAsync(new StreamingInputCallRequest
            {
                ExpectCompressed = new BoolValue
                {
                    Value = true
                },
                Payload = CreateZerosPayload(27182)
            });

            call.RequestStream.WriteOptions = new WriteOptions(WriteFlags.NoCompress);
            await call.RequestStream.WriteAsync(new StreamingInputCallRequest
            {
                ExpectCompressed = new BoolValue
                {
                    Value = false
                },
                Payload = CreateZerosPayload(45904)
            });
            await call.RequestStream.CompleteAsync();

            var response = await call.ResponseAsync;
            Assert.AreEqual(73086, response.AggregatedPayloadSize);

            Console.WriteLine("Passed!");
        }
开发者ID:wuyunhao,项目名称:grpc,代码行数:50,代码来源:InteropClient.cs

示例3: RunClientStreamingAsync

        public static async Task RunClientStreamingAsync(TestService.TestServiceClient client)
        {
            Console.WriteLine("running client_streaming");

            var bodySizes = new List<int> { 27182, 8, 1828, 45904 }.Select((size) => new StreamingInputCallRequest { Payload = CreateZerosPayload(size) });

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

                var response = await call.ResponseAsync;
                Assert.AreEqual(74922, response.AggregatedPayloadSize);
            }
            Console.WriteLine("Passed!");
        }
开发者ID:wuyunhao,项目名称:grpc,代码行数:15,代码来源:InteropClient.cs


注:本文中的Grpc.Testing.TestService.StreamingInputCall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。