Example #1
0
            /// <summary>
            /// Creates a server and a channel and initiates a call. The code is invoked from inside of an AppDomain
            /// to test if AppDomain.Unload() work if Grpc is being used.
            /// </summary>
            public AppDomainTestClass()
            {
                var helper = new MockServiceHelper(Host);
                var server = helper.GetServer();
                server.Start();
                var channel = helper.GetChannel();

                var readyToShutdown = new TaskCompletionSource<object>();
                helper.DuplexStreamingHandler = new DuplexStreamingServerMethod<string, string>(async (requestStream, responseStream, context) =>
                {
                    readyToShutdown.SetResult(null);
                    await requestStream.ToListAsync();
                });

                var call = Calls.AsyncDuplexStreamingCall(helper.CreateDuplexStreamingCall());
                readyToShutdown.Task.Wait();  // make sure handler is running
            }
Example #2
0
        public async Task ResponseHeadersAsync_DuplexStreamingCall()
        {
            helper.DuplexStreamingHandler = new DuplexStreamingServerMethod <string, string>(async(requestStream, responseStream, context) =>
            {
                await context.WriteResponseHeadersAsync(headers);
                while (await requestStream.MoveNext())
                {
                    await responseStream.WriteAsync(requestStream.Current);
                }
            });

            var call            = Calls.AsyncDuplexStreamingCall(helper.CreateDuplexStreamingCall());
            var responseHeaders = await call.ResponseHeadersAsync;

            var messages = new[] { "PASS" };
            await call.RequestStream.WriteAllAsync(messages);

            Assert.AreEqual("ascii-header", responseHeaders[0].Key);
            CollectionAssert.AreEqual(messages, await call.ResponseStream.ToListAsync());
        }
Example #3
0
        public void ProcessExitHookCanCleanupAbandonedCall()
        {
            var helper = new MockServiceHelper(Host);
            var server = helper.GetServer();

            server.Start();
            var channel = helper.GetChannel();

            var readyToShutdown = new TaskCompletionSource <object>();

            helper.DuplexStreamingHandler = new DuplexStreamingServerMethod <string, string>(async(requestStream, responseStream, context) =>
            {
                readyToShutdown.SetResult(null);
                await requestStream.ToListAsync();
            });

            var call = Calls.AsyncDuplexStreamingCall(helper.CreateDuplexStreamingCall());

            readyToShutdown.Task.Wait();  // make sure handler is running
        }
Example #4
0
        public async Task WriteOptions_DuplexStreaming()
        {
            helper.DuplexStreamingHandler = new DuplexStreamingServerMethod <string, string>(async(requestStream, responseStream, context) =>
            {
                await requestStream.ToListAsync();

                context.WriteOptions = new WriteOptions(WriteFlags.NoCompress);

                await context.WriteResponseHeadersAsync(new Metadata {
                    { "ascii-header", "abcdefg" }
                });

                await responseStream.WriteAsync("X");

                responseStream.WriteOptions = null;
                await responseStream.WriteAsync("Y");

                responseStream.WriteOptions = new WriteOptions(WriteFlags.NoCompress);
                await responseStream.WriteAsync("Z");
            });

            var callOptions = new CallOptions(writeOptions: new WriteOptions(WriteFlags.NoCompress));
            var call        = Calls.AsyncDuplexStreamingCall(helper.CreateDuplexStreamingCall(callOptions));

            // check that write options from call options are propagated to request stream.
            Assert.IsTrue((call.RequestStream.WriteOptions.Flags & WriteFlags.NoCompress) != 0);

            call.RequestStream.WriteOptions = new WriteOptions();
            await call.RequestStream.WriteAsync("A");

            call.RequestStream.WriteOptions = null;
            await call.RequestStream.WriteAsync("B");

            call.RequestStream.WriteOptions = new WriteOptions(WriteFlags.NoCompress);
            await call.RequestStream.WriteAsync("C");

            await call.RequestStream.CompleteAsync();

            await call.ResponseStream.ToListAsync();
        }