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(); }
public void Init() { helper = new MockServiceHelper(Host); server = helper.GetServer(); server.Start(); channel = helper.GetChannel(); }
public void ProcessExitHookCanCleanupAbandonedServers() { var helper = new MockServiceHelper(Host); var server = helper.GetServer(); server.Start(); }
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(); }
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(); }
public void Init() { helper = new MockServiceHelper(); server = helper.GetServer(); server.Start(); channel = helper.GetChannel(); headers = new Metadata { { "ascii-header", "abcdefg" } }; }
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(); }
/// <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 }
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(), "")); }
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(), "")); }
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(), "")); }
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 }