public static async Task RunClientCompressedStreamingAsync(IChannelWrapper channel, ClientOptions options) { var client = CreateClient <TestService.TestServiceClient>(channel); 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); }
public static async Task RunServerCompressedStreamingAsync(IChannelWrapper channel, ClientOptions options) { var client = CreateClient <TestService.TestServiceClient>(channel); var bodySizes = new List <int> { 31415, 92653 }; var request = new StreamingOutputCallRequest { ResponseParameters = { bodySizes.Select((size) => new ResponseParameters { Size = size, Compressed = new BoolValue { Value = true } }) } }; using (var call = client.StreamingOutputCall(request)) { // Compression of response message is not verified because there is no API available var responseList = await call.ResponseStream.ToListAsync(); CollectionAssert.AreEqual(bodySizes, responseList.Select((item) => item.Payload.Body.Length).ToList()); } }
public static async Task RunSpecialStatusMessageAsync(IChannelWrapper channel, ClientOptions options) { var client = CreateClient <TestService.TestServiceClient>(channel); var echoStatus = new EchoStatus { Code = 2, Message = "\t\ntest with whitespace\r\nand Unicode BMP ☺ and non-BMP 😈\t\n" }; try { await client.UnaryCallAsync(new SimpleRequest { ResponseStatus = echoStatus }); Assert.Fail(); } catch (RpcException e) { Assert.AreEqual(StatusCode.Unknown, e.Status.StatusCode); Assert.AreEqual(echoStatus.Message, e.Status.Detail); } }
public static async Task RunStatusCodeAndMessageAsync(IChannelWrapper channel, ClientOptions options) { var client = CreateClient <TestService.TestServiceClient>(channel); var echoStatus = new EchoStatus { Code = 2, Message = "test status message" }; { // step 1: test unary call var request = new SimpleRequest { ResponseStatus = echoStatus }; var e = await ExceptionAssert.ThrowsAsync <RpcException>(async() => await client.UnaryCallAsync(request)); Assert.AreEqual(StatusCode.Unknown, e.Status.StatusCode); Assert.AreEqual(echoStatus.Message, e.Status.Detail); } // We want to test a unary call in gRPC-Web but skip the unsupported full duplex call. #if !BLAZOR_WASM { // step 2: test full duplex call var request = new StreamingOutputCallRequest { ResponseStatus = echoStatus }; var call = client.FullDuplexCall(); await call.RequestStream.WriteAsync(request); await call.RequestStream.CompleteAsync(); try { // cannot use Assert.ThrowsAsync because it uses Task.Wait and would deadlock. await call.ResponseStream.ToListAsync(); Assert.Fail(); } catch (RpcException e) { Assert.AreEqual(StatusCode.Unknown, e.Status.StatusCode); Assert.AreEqual(echoStatus.Message, e.Status.Detail); } } #endif }
public static async Task RunTimeoutOnSleepingServerAsync(IChannelWrapper channel, ClientOptions options) { var client = CreateClient <TestService.TestServiceClient>(channel); var deadline = DateTime.UtcNow.AddMilliseconds(1); using (var call = client.FullDuplexCall(deadline: deadline)) { try { await call.RequestStream.WriteAsync(new StreamingOutputCallRequest { Payload = CreateZerosPayload(27182) }); } catch (InvalidOperationException) { // Deadline was reached before write has started. Eat the exception and continue. } catch (RpcException) { // Deadline was reached before write has started. Eat the exception and continue. } try { await call.ResponseStream.MoveNext(); Assert.Fail(); } catch (RpcException ex) { Assert.AreEqual(StatusCode.DeadlineExceeded, ex.StatusCode); } } }
public static async Task RunCancelAfterFirstResponseAsync(IChannelWrapper channel, ClientOptions options) { var client = CreateClient <TestService.TestServiceClient>(channel); var cts = new CancellationTokenSource(); using (var call = client.FullDuplexCall(cancellationToken: cts.Token)) { await call.RequestStream.WriteAsync(new StreamingOutputCallRequest { ResponseParameters = { new ResponseParameters { Size = 31415 } }, Payload = CreateZerosPayload(27182) }); Assert.IsTrue(await call.ResponseStream.MoveNext()); Assert.AreEqual(31415, call.ResponseStream.Current.Payload.Body.Length); cts.Cancel(); try { // cannot use Assert.ThrowsAsync because it uses Task.Wait and would deadlock. await call.ResponseStream.MoveNext(); Assert.Fail(); } catch (RpcException ex) { Assert.AreEqual(StatusCode.Cancelled, ex.Status.StatusCode); } } }
public InteropClient(ClientOptions options, ILoggerFactory loggerFactory) { this.options = options; this.loggerFactory = loggerFactory; this.logger = loggerFactory.CreateLogger <InteropClient>(); }