コード例 #1
0
 public void Init()
 {
     var marshaller = new Marshaller<string>(
         (str) =>
         {
             if (str == "UNSERIALIZABLE_VALUE")
             {
                 // Google.Protobuf throws exception inherited from IOException
                 throw new IOException("Error serializing the message.");
             }
             return System.Text.Encoding.UTF8.GetBytes(str); 
         },
         (payload) =>
         {
             var s = System.Text.Encoding.UTF8.GetString(payload);
             if (s == "UNPARSEABLE_VALUE")
             {
                 // Google.Protobuf throws exception inherited from IOException
                 throw new IOException("Error parsing the message.");
             }
             return s;
         });
     helper = new MockServiceHelper(Host, marshaller);
     server = helper.GetServer();
     server.Start();
     channel = helper.GetChannel();
 }
コード例 #2
0
ファイル: ClientServerTest.cs プロジェクト: xiexiemanyou/grpc
 public void Init()
 {
     helper = new MockServiceHelper(Host);
     server = helper.GetServer();
     server.Start();
     channel = helper.GetChannel();
 }
コード例 #3
0
        public void ProcessExitHookCanCleanupAbandonedServers()
        {
            var helper = new MockServiceHelper(Host);
            var server = helper.GetServer();

            server.Start();
        }
コード例 #4
0
        public void Init()
        {
            var marshaller = new Marshaller <string>(
                (str) =>
            {
                if (str == "UNSERIALIZABLE_VALUE")
                {
                    // Google.Protobuf throws exception inherited from IOException
                    throw new IOException("Error serializing the message.");
                }
                return(System.Text.Encoding.UTF8.GetBytes(str));
            },
                (payload) =>
            {
                var s = System.Text.Encoding.UTF8.GetString(payload);
                if (s == "UNPARSEABLE_VALUE")
                {
                    // Google.Protobuf throws exception inherited from IOException
                    throw new IOException("Error parsing the message.");
                }
                return(s);
            });

            helper = new MockServiceHelper(Host, marshaller);
            server = helper.GetServer();
            server.Start();
            channel = helper.GetChannel();
        }
コード例 #5
0
ファイル: ShutdownTest.cs プロジェクト: larsonmpdx/grpc
 public void Init()
 {
     helper = new MockServiceHelper(Host);
     server = helper.GetServer();
     server.Start();
     channel = helper.GetChannel();
 }
コード例 #6
0
        public void Init()
        {
            var contextualMarshaller = new Marshaller <string>(
                (str, serializationContext) =>
            {
                if (str == "UNSERIALIZABLE_VALUE")
                {
                    // Google.Protobuf throws exception inherited from IOException
                    throw new IOException("Error serializing the message.");
                }
                if (str == "SERIALIZE_TO_NULL")
                {
                    return;
                }
                var bytes = System.Text.Encoding.UTF8.GetBytes(str);
                serializationContext.Complete(bytes);
            },
                (deserializationContext) =>
            {
                var buffer = deserializationContext.PayloadAsNewBuffer();
                Assert.AreEqual(buffer.Length, deserializationContext.PayloadLength);
                var s = System.Text.Encoding.UTF8.GetString(buffer);
                if (s == "UNPARSEABLE_VALUE")
                {
                    // Google.Protobuf throws exception inherited from IOException
                    throw new IOException("Error parsing the message.");
                }
                return(s);
            });

            helper = new MockServiceHelper(Host, contextualMarshaller);
            server = helper.GetServer();
            server.Start();
            channel = helper.GetChannel();
        }
コード例 #7
0
        public void Init()
        {
            helper = new MockServiceHelper();

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

            headers = new Metadata { { "ascii-header", "abcdefg" } };
        }
コード例 #8
0
        public void Init()
        {
            helper = new MockServiceHelper();

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

            headers = new Metadata {
                { "ascii-header", "abcdefg" }
            };
        }
コード例 #9
0
ファイル: RetryTest.cs プロジェクト: weidmueller/grpc
        public void Init()
        {
            var channelOptions = new ChannelOption[]
            {
                new ChannelOption(
                    "grpc.service_config",
                    "{\"methodConfig\":[{\"name\":[{\"service\":\"" + MockServiceHelper.ServiceName + "\",\"method\":\"Unary\"}],\"retryPolicy\":{\"maxAttempts\":3,\"initialBackoff\":\"0.5s\",\"maxBackoff\":\"5s\",\"backoffMultiplier\":2.0,\"retryableStatusCodes\":[\"UNAVAILABLE\"]}}, {\"name\":[{\"service\":\"" + MockServiceHelper.ServiceName + "\",\"method\":\"ServerStreaming\"}],\"retryPolicy\":{\"maxAttempts\":3,\"initialBackoff\":\"0.5s\",\"maxBackoff\":\"5s\",\"backoffMultiplier\":2.0,\"retryableStatusCodes\":[\"UNAVAILABLE\"]}}]}")
            };

            helper = new MockServiceHelper(channelOptions: channelOptions);

            server = helper.GetServer();
            server.Start();
            channel = helper.GetChannel();
        }
コード例 #10
0
ファイル: AppDomainUnloadTest.cs プロジェクト: nerdrew/grpc
            /// <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
            }
コード例 #11
0
        public void DefaultUserAgentString()
        {
            helper = new MockServiceHelper(Host);
            server = helper.GetServer();
            server.Start();
            channel = helper.GetChannel();

            helper.UnaryHandler = new UnaryServerMethod <string, string>((request, context) =>
            {
                var userAgentString = context.RequestHeaders.First(m => (m.Key == "user-agent")).Value;
                var parts           = userAgentString.Split(new [] { ' ' }, 2);
                Assert.AreEqual(string.Format("grpc-csharp/{0}", VersionInfo.CurrentVersion), parts[0]);
                Assert.IsTrue(parts[1].StartsWith("grpc-c/"));
                return(Task.FromResult("PASS"));
            });
            Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), ""));
        }
コード例 #12
0
ファイル: UserAgentStringTest.cs プロジェクト: zmou/grpc
        public void DefaultUserAgentString()
        {
            helper = new MockServiceHelper(Host);
            helper.UnaryHandler = new UnaryServerMethod <string, string>((request, context) =>
            {
                var userAgentString = context.RequestHeaders.GetValue("user-agent");
                var parts           = userAgentString.Split(new [] { ' ' }, 2);
                Assert.AreEqual($"grpc-csharp/{VersionInfo.CurrentVersion}", parts[0]);
                Assert.That(parts[1], Does.Match(@"\(.*\) grpc-c/.*"));
                return(Task.FromResult("PASS"));
            });

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

            Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), ""));
        }
コード例 #13
0
        public void ApplicationUserAgentString()
        {
            helper = new MockServiceHelper(Host,
                                           channelOptions: new[] { new ChannelOption(ChannelOptions.PrimaryUserAgentString, "XYZ") });
            helper.UnaryHandler = new UnaryServerMethod <string, string>((request, context) =>
            {
                var userAgentString = context.RequestHeaders.First(m => (m.Key == "user-agent")).Value;
                var parts           = userAgentString.Split(new[] { ' ' }, 3);
                Assert.AreEqual("XYZ", parts[0]);
                return(Task.FromResult("PASS"));
            });

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

            Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), ""));
        }
コード例 #14
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
        }
コード例 #15
0
 public void ProcessExitHookCanCleanupAbandonedServers()
 {
     var helper = new MockServiceHelper(Host);
     var server = helper.GetServer();
     server.Start();
 }