Beispiel #1
0
 private void RunTestCase(string testCase, TestServiceGrpc.ITestServiceClient client)
 {
     switch (testCase)
     {
         case "empty_unary":
             RunEmptyUnary(client);
             break;
         case "large_unary":
             RunLargeUnary(client);
             break;
         case "client_streaming":
             RunClientStreaming(client);
             break;
         case "server_streaming":
             RunServerStreaming(client);
             break;
         case "ping_pong":
             RunPingPong(client);
             break;
         case "empty_stream":
             RunEmptyStream(client);
             break;
         case "benchmark_empty_unary":
             RunBenchmarkEmptyUnary(client);
             break;
         default:
             throw new ArgumentException("Unknown test case " + testCase);
     }
 }
Beispiel #2
0
        public static void RunPingPong(TestServiceGrpc.ITestServiceClient client)
        {
            Console.WriteLine("running ping_pong");

            var recorder = new RecordingQueue<StreamingOutputCallResponse>();
            var inputs = client.FullDuplexCall(recorder);

            StreamingOutputCallResponse response;

            inputs.OnNext(StreamingOutputCallRequest.CreateBuilder()
                .SetResponseType(PayloadType.COMPRESSABLE)
                .AddResponseParameters(ResponseParameters.CreateBuilder().SetSize(31415))
                .SetPayload(CreateZerosPayload(27182)).Build());

            response = recorder.Queue.Take();
            Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
            Assert.AreEqual(31415, response.Payload.Body.Length);

            inputs.OnNext(StreamingOutputCallRequest.CreateBuilder()
                          .SetResponseType(PayloadType.COMPRESSABLE)
                          .AddResponseParameters(ResponseParameters.CreateBuilder().SetSize(9))
                          .SetPayload(CreateZerosPayload(8)).Build());

            response = recorder.Queue.Take();
            Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
            Assert.AreEqual(9, response.Payload.Body.Length);

            inputs.OnNext(StreamingOutputCallRequest.CreateBuilder()
                          .SetResponseType(PayloadType.COMPRESSABLE)
                          .AddResponseParameters(ResponseParameters.CreateBuilder().SetSize(2653))
                          .SetPayload(CreateZerosPayload(1828)).Build());

            response = recorder.Queue.Take();
            Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
            Assert.AreEqual(2653, response.Payload.Body.Length);

            inputs.OnNext(StreamingOutputCallRequest.CreateBuilder()
                          .SetResponseType(PayloadType.COMPRESSABLE)
                          .AddResponseParameters(ResponseParameters.CreateBuilder().SetSize(58979))
                          .SetPayload(CreateZerosPayload(45904)).Build());

            response = recorder.Queue.Take();
            Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
            Assert.AreEqual(58979, response.Payload.Body.Length);

            inputs.OnCompleted();

            recorder.Finished.Wait();
            Assert.AreEqual(0, recorder.Queue.Count);

            Console.WriteLine("Passed!");
        }
Beispiel #3
0
        public static void RunServerStreaming(TestServiceGrpc.ITestServiceClient client)
        {
            Console.WriteLine("running server_streaming");

            var bodySizes = new List<int> { 31415, 9, 2653, 58979 };

            var request = StreamingOutputCallRequest.CreateBuilder()
                .SetResponseType(PayloadType.COMPRESSABLE)
                .AddRangeResponseParameters(bodySizes.ConvertAll(
                        (size) => ResponseParameters.CreateBuilder().SetSize(size).Build()))
                .Build();

            var recorder = new RecordingObserver<StreamingOutputCallResponse>();
            client.StreamingOutputCall(request, recorder);

            var responseList = recorder.ToList().Result;

            foreach (var res in responseList)
            {
                Assert.AreEqual(PayloadType.COMPRESSABLE, res.Payload.Type);
            }
            CollectionAssert.AreEqual(bodySizes, responseList.ConvertAll((item) => item.Payload.Body.Length));
            Console.WriteLine("Passed!");
        }
Beispiel #4
0
        public static void RunLargeUnary(TestServiceGrpc.ITestServiceClient client)
        {
            Console.WriteLine("running large_unary");
            var request = SimpleRequest.CreateBuilder()
                    .SetResponseType(PayloadType.COMPRESSABLE)
                    .SetResponseSize(314159)
                    .SetPayload(CreateZerosPayload(271828))
                    .Build();

            var response = client.UnaryCall(request);

            Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
            Assert.AreEqual(314159, response.Payload.Body.Length);
            Console.WriteLine("Passed!");
        }
Beispiel #5
0
 public static void RunEmptyUnary(TestServiceGrpc.ITestServiceClient client)
 {
     Console.WriteLine("running empty_unary");
     var response = client.EmptyCall(Empty.DefaultInstance);
     Assert.IsNotNull(response);
     Console.WriteLine("Passed!");
 }
Beispiel #6
0
        public static void RunEmptyStream(TestServiceGrpc.ITestServiceClient client)
        {
            Console.WriteLine("running empty_stream");

            var recorder = new RecordingObserver<StreamingOutputCallResponse>();
            var inputs = client.FullDuplexCall(recorder);
            inputs.OnCompleted();

            var responseList = recorder.ToList().Result;
            Assert.AreEqual(0, responseList.Count);

            Console.WriteLine("Passed!");
        }
Beispiel #7
0
        public static void RunClientStreaming(TestServiceGrpc.ITestServiceClient client)
        {
            Console.WriteLine("running client_streaming");

            var bodySizes = new List<int> { 27182, 8, 1828, 45904 };

            var context = client.StreamingInputCall();
            foreach (var size in bodySizes)
            {
                context.Inputs.OnNext(
                    StreamingInputCallRequest.CreateBuilder().SetPayload(CreateZerosPayload(size)).Build());
            }
            context.Inputs.OnCompleted();

            var response = context.Task.Result;
            Assert.AreEqual(74922, response.AggregatedPayloadSize);
            Console.WriteLine("Passed!");
        }
Beispiel #8
0
 // This is not an official interop test, but it's useful.
 public static void RunBenchmarkEmptyUnary(TestServiceGrpc.ITestServiceClient client)
 {
     BenchmarkUtil.RunBenchmark(10000, 10000,
                                () => { client.EmptyCall(Empty.DefaultInstance); });
 }