diff options
Diffstat (limited to 'src/csharp')
48 files changed, 774 insertions, 305 deletions
diff --git a/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs b/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs index f77e9c6573..1837f5c74b 100644 --- a/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs +++ b/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -71,7 +71,7 @@ namespace Grpc.Auth /// <returns>The interceptor.</returns> public static AsyncAuthInterceptor FromAccessToken(string accessToken) { - Preconditions.CheckNotNull(accessToken); + GrpcPreconditions.CheckNotNull(accessToken); return new AsyncAuthInterceptor(async (context, metadata) => { metadata.Add(CreateBearerTokenHeader(accessToken)); diff --git a/src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs b/src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs index 78295cf6d4..fac93fcc5c 100644 --- a/src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs +++ b/src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -84,7 +84,7 @@ namespace Grpc.Core.Tests { var coreVersion = GrpcEnvironment.GetCoreVersionString(); var parts = coreVersion.Split('.'); - Assert.AreEqual(4, parts.Length); + Assert.AreEqual(3, parts.Length); } } } diff --git a/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs b/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs index 5c9ab04812..5ba06d6509 100644 --- a/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs +++ b/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -61,8 +61,8 @@ namespace Grpc.Core /// </summary> public AuthInterceptorContext(string serviceUrl, string methodName) { - this.serviceUrl = Preconditions.CheckNotNull(serviceUrl); - this.methodName = Preconditions.CheckNotNull(methodName); + this.serviceUrl = GrpcPreconditions.CheckNotNull(serviceUrl); + this.methodName = GrpcPreconditions.CheckNotNull(methodName); } /// <summary> diff --git a/src/csharp/Grpc.Core/CallCredentials.cs b/src/csharp/Grpc.Core/CallCredentials.cs index a71c8904fe..7cd41d0480 100644 --- a/src/csharp/Grpc.Core/CallCredentials.cs +++ b/src/csharp/Grpc.Core/CallCredentials.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -87,7 +87,7 @@ namespace Grpc.Core /// <param name="interceptor">authentication interceptor</param> public MetadataCredentials(AsyncAuthInterceptor interceptor) { - this.interceptor = Preconditions.CheckNotNull(interceptor); + this.interceptor = GrpcPreconditions.CheckNotNull(interceptor); } internal override CallCredentialsSafeHandle ToNativeCredentials() @@ -111,7 +111,7 @@ namespace Grpc.Core /// <param name="credentials">credentials to compose</param> public CompositeCallCredentials(params CallCredentials[] credentials) { - Preconditions.CheckArgument(credentials.Length >= 2, "Composite credentials object can only be created from 2 or more credentials."); + GrpcPreconditions.CheckArgument(credentials.Length >= 2, "Composite credentials object can only be created from 2 or more credentials."); this.credentials = new List<CallCredentials>(credentials); } diff --git a/src/csharp/Grpc.Core/CallInvocationDetails.cs b/src/csharp/Grpc.Core/CallInvocationDetails.cs index 8228b8f317..52bfbe6edb 100644 --- a/src/csharp/Grpc.Core/CallInvocationDetails.cs +++ b/src/csharp/Grpc.Core/CallInvocationDetails.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -85,11 +85,11 @@ namespace Grpc.Core /// <param name="options">Call options.</param> public CallInvocationDetails(Channel channel, string method, string host, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller, CallOptions options) { - this.channel = Preconditions.CheckNotNull(channel, "channel"); - this.method = Preconditions.CheckNotNull(method, "method"); + this.channel = GrpcPreconditions.CheckNotNull(channel, "channel"); + this.method = GrpcPreconditions.CheckNotNull(method, "method"); this.host = host; - this.requestMarshaller = Preconditions.CheckNotNull(requestMarshaller, "requestMarshaller"); - this.responseMarshaller = Preconditions.CheckNotNull(responseMarshaller, "responseMarshaller"); + this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller"); + this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller"); this.options = options; } diff --git a/src/csharp/Grpc.Core/CallOptions.cs b/src/csharp/Grpc.Core/CallOptions.cs index 1fda80cb90..7bd95d4ba8 100644 --- a/src/csharp/Grpc.Core/CallOptions.cs +++ b/src/csharp/Grpc.Core/CallOptions.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -176,13 +176,13 @@ namespace Grpc.Core { if (propagationToken.Options.IsPropagateDeadline) { - Preconditions.CheckArgument(!newOptions.deadline.HasValue, + GrpcPreconditions.CheckArgument(!newOptions.deadline.HasValue, "Cannot propagate deadline from parent call. The deadline has already been set explicitly."); newOptions.deadline = propagationToken.ParentDeadline; } if (propagationToken.Options.IsPropagateCancellation) { - Preconditions.CheckArgument(!newOptions.cancellationToken.CanBeCanceled, + GrpcPreconditions.CheckArgument(!newOptions.cancellationToken.CanBeCanceled, "Cannot propagate cancellation token from parent call. The cancellation token has already been set to a non-default value."); newOptions.cancellationToken = propagationToken.ParentCancellationToken; } diff --git a/src/csharp/Grpc.Core/Channel.cs b/src/csharp/Grpc.Core/Channel.cs index d8d43c7998..d7a482d86f 100644 --- a/src/csharp/Grpc.Core/Channel.cs +++ b/src/csharp/Grpc.Core/Channel.cs @@ -1,5 +1,5 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -68,7 +68,7 @@ namespace Grpc.Core /// <param name="options">Channel options.</param> public Channel(string target, ChannelCredentials credentials, IEnumerable<ChannelOption> options = null) { - this.target = Preconditions.CheckNotNull(target, "target"); + this.target = GrpcPreconditions.CheckNotNull(target, "target"); this.options = CreateOptionsDictionary(options); EnsureUserAgentChannelOption(this.options); this.environment = GrpcEnvironment.AddRef(); @@ -117,7 +117,7 @@ namespace Grpc.Core /// </summary> public Task WaitForStateChangedAsync(ChannelState lastObservedState, DateTime? deadline = null) { - Preconditions.CheckArgument(lastObservedState != ChannelState.FatalFailure, + GrpcPreconditions.CheckArgument(lastObservedState != ChannelState.FatalFailure, "FatalFailure is a terminal state. No further state changes can occur."); var tcs = new TaskCompletionSource<object>(); var deadlineTimespec = deadline.HasValue ? Timespec.FromDateTime(deadline.Value) : Timespec.InfFuture; @@ -184,7 +184,7 @@ namespace Grpc.Core { lock (myLock) { - Preconditions.CheckState(!shutdownRequested); + GrpcPreconditions.CheckState(!shutdownRequested); shutdownRequested = true; } @@ -221,7 +221,7 @@ namespace Grpc.Core bool success = false; handle.DangerousAddRef(ref success); - Preconditions.CheckState(success); + GrpcPreconditions.CheckState(success); } internal void RemoveCallReference(object call) diff --git a/src/csharp/Grpc.Core/ChannelCredentials.cs b/src/csharp/Grpc.Core/ChannelCredentials.cs index 5d96958e7c..03cda28400 100644 --- a/src/csharp/Grpc.Core/ChannelCredentials.cs +++ b/src/csharp/Grpc.Core/ChannelCredentials.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -183,9 +183,9 @@ namespace Grpc.Core /// <param name="callCredentials">channelCredentials to compose</param> public CompositeChannelCredentials(ChannelCredentials channelCredentials, CallCredentials callCredentials) { - this.channelCredentials = Preconditions.CheckNotNull(channelCredentials); - this.callCredentials = Preconditions.CheckNotNull(callCredentials); - Preconditions.CheckArgument(channelCredentials.IsComposable, "Supplied channel credentials do not allow composition."); + this.channelCredentials = GrpcPreconditions.CheckNotNull(channelCredentials); + this.callCredentials = GrpcPreconditions.CheckNotNull(callCredentials); + GrpcPreconditions.CheckArgument(channelCredentials.IsComposable, "Supplied channel credentials do not allow composition."); } internal override ChannelCredentialsSafeHandle ToNativeCredentials() diff --git a/src/csharp/Grpc.Core/ChannelOptions.cs b/src/csharp/Grpc.Core/ChannelOptions.cs index d70673cf78..65e15e21e9 100644 --- a/src/csharp/Grpc.Core/ChannelOptions.cs +++ b/src/csharp/Grpc.Core/ChannelOptions.cs @@ -1,5 +1,5 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -73,8 +73,8 @@ namespace Grpc.Core public ChannelOption(string name, string stringValue) { this.type = OptionType.String; - this.name = Preconditions.CheckNotNull(name, "name"); - this.stringValue = Preconditions.CheckNotNull(stringValue, "stringValue"); + this.name = GrpcPreconditions.CheckNotNull(name, "name"); + this.stringValue = GrpcPreconditions.CheckNotNull(stringValue, "stringValue"); } /// <summary> @@ -85,7 +85,7 @@ namespace Grpc.Core public ChannelOption(string name, int intValue) { this.type = OptionType.Integer; - this.name = Preconditions.CheckNotNull(name, "name"); + this.name = GrpcPreconditions.CheckNotNull(name, "name"); this.intValue = intValue; } @@ -118,7 +118,7 @@ namespace Grpc.Core { get { - Preconditions.CheckState(type == OptionType.Integer); + GrpcPreconditions.CheckState(type == OptionType.Integer); return intValue; } } @@ -130,7 +130,7 @@ namespace Grpc.Core { get { - Preconditions.CheckState(type == OptionType.String); + GrpcPreconditions.CheckState(type == OptionType.String); return stringValue; } } diff --git a/src/csharp/Grpc.Core/ContextPropagationToken.cs b/src/csharp/Grpc.Core/ContextPropagationToken.cs index 1d899b97fd..c0f638f837 100644 --- a/src/csharp/Grpc.Core/ContextPropagationToken.cs +++ b/src/csharp/Grpc.Core/ContextPropagationToken.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -68,7 +68,7 @@ namespace Grpc.Core internal ContextPropagationToken(CallSafeHandle parentCall, DateTime deadline, CancellationToken cancellationToken, ContextPropagationOptions options) { - this.parentCall = Preconditions.CheckNotNull(parentCall); + this.parentCall = GrpcPreconditions.CheckNotNull(parentCall); this.deadline = deadline; this.cancellationToken = cancellationToken; this.options = options ?? ContextPropagationOptions.Default; diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index 9587503e4b..3189835ccd 100644 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -39,8 +39,7 @@ </PropertyGroup> <ItemGroup> <Reference Include="System" /> - <Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> + <Reference Include="System.Interactive.Async"> <HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath> </Reference> </ItemGroup> @@ -59,6 +58,7 @@ <Compile Include="IServerStreamWriter.cs" /> <Compile Include="IAsyncStreamWriter.cs" /> <Compile Include="IAsyncStreamReader.cs" /> + <Compile Include="Logging\NullLogger.cs" /> <Compile Include="ServerPort.cs" /> <Compile Include="Version.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> @@ -90,7 +90,6 @@ <Compile Include="Internal\AsyncCallBase.cs" /> <Compile Include="Internal\AsyncCallServer.cs" /> <Compile Include="Internal\AsyncCall.cs" /> - <Compile Include="Utils\Preconditions.cs" /> <Compile Include="Internal\ServerCredentialsSafeHandle.cs" /> <Compile Include="ServerCredentials.cs" /> <Compile Include="Metadata.cs" /> @@ -129,6 +128,7 @@ <Compile Include="Profiling\IProfiler.cs" /> <Compile Include="Profiling\Profilers.cs" /> <Compile Include="Internal\DefaultSslRootsOverride.cs" /> + <Compile Include="Utils\GrpcPreconditions.cs" /> </ItemGroup> <ItemGroup> <None Include="Grpc.Core.nuspec" /> diff --git a/src/csharp/Grpc.Core/GrpcEnvironment.cs b/src/csharp/Grpc.Core/GrpcEnvironment.cs index f3aa3d79de..86b37b8660 100644 --- a/src/csharp/Grpc.Core/GrpcEnvironment.cs +++ b/src/csharp/Grpc.Core/GrpcEnvironment.cs @@ -83,7 +83,7 @@ namespace Grpc.Core { lock (staticLock) { - Preconditions.CheckState(refCount > 0); + GrpcPreconditions.CheckState(refCount > 0); refCount--; if (refCount == 0) { @@ -118,7 +118,7 @@ namespace Grpc.Core /// </summary> public static void SetLogger(ILogger customLogger) { - Preconditions.CheckNotNull(customLogger, "customLogger"); + GrpcPreconditions.CheckNotNull(customLogger, "customLogger"); logger = customLogger; } diff --git a/src/csharp/Grpc.Core/Internal/AsyncCall.cs b/src/csharp/Grpc.Core/Internal/AsyncCall.cs index 7dc4490281..2caba260b3 100644 --- a/src/csharp/Grpc.Core/Internal/AsyncCall.cs +++ b/src/csharp/Grpc.Core/Internal/AsyncCall.cs @@ -99,7 +99,7 @@ namespace Grpc.Core.Internal lock (myLock) { - Preconditions.CheckState(!started); + GrpcPreconditions.CheckState(!started); started = true; Initialize(cq); @@ -141,7 +141,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckState(!started); + GrpcPreconditions.CheckState(!started); started = true; Initialize(environment.CompletionQueue); @@ -168,7 +168,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckState(!started); + GrpcPreconditions.CheckState(!started); started = true; Initialize(environment.CompletionQueue); @@ -192,7 +192,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckState(!started); + GrpcPreconditions.CheckState(!started); started = true; Initialize(environment.CompletionQueue); @@ -217,7 +217,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckState(!started); + GrpcPreconditions.CheckState(!started); started = true; Initialize(environment.CompletionQueue); @@ -257,7 +257,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); + GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); CheckSendingAllowed(); call.StartSendCloseFromClient(HandleHalfclosed); @@ -297,7 +297,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckState(finishedStatus.HasValue, "Status can only be accessed once the call has finished."); + GrpcPreconditions.CheckState(finishedStatus.HasValue, "Status can only be accessed once the call has finished."); return finishedStatus.Value.Status; } } @@ -310,7 +310,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckState(finishedStatus.HasValue, "Trailers can only be accessed once the call has finished."); + GrpcPreconditions.CheckState(finishedStatus.HasValue, "Trailers can only be accessed once the call has finished."); return finishedStatus.Value.Trailers; } } diff --git a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs index 81a9a40fcc..45d4c3e078 100644 --- a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs +++ b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs @@ -79,9 +79,9 @@ namespace Grpc.Core.Internal public AsyncCallBase(Func<TWrite, byte[]> serializer, Func<byte[], TRead> deserializer, GrpcEnvironment environment) { - this.serializer = Preconditions.CheckNotNull(serializer); - this.deserializer = Preconditions.CheckNotNull(deserializer); - this.environment = Preconditions.CheckNotNull(environment); + this.serializer = GrpcPreconditions.CheckNotNull(serializer); + this.deserializer = GrpcPreconditions.CheckNotNull(deserializer); + this.environment = GrpcPreconditions.CheckNotNull(environment); } /// <summary> @@ -91,7 +91,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckState(started); + GrpcPreconditions.CheckState(started); cancelRequested = true; if (!disposed) @@ -135,7 +135,7 @@ namespace Grpc.Core.Internal lock (myLock) { - Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); + GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); CheckSendingAllowed(); call.StartSendMessage(HandleSendFinished, payload, writeFlags, !initialMetadataSent); @@ -154,7 +154,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); + GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); CheckReadingAllowed(); call.StartReceiveMessage(HandleReadFinished); @@ -204,22 +204,22 @@ namespace Grpc.Core.Internal protected void CheckSendingAllowed() { - Preconditions.CheckState(started); + GrpcPreconditions.CheckState(started); CheckNotCancelled(); - Preconditions.CheckState(!disposed); + GrpcPreconditions.CheckState(!disposed); - Preconditions.CheckState(!halfcloseRequested, "Already halfclosed."); - Preconditions.CheckState(!finished, "Already finished."); - Preconditions.CheckState(sendCompletionDelegate == null, "Only one write can be pending at a time"); + GrpcPreconditions.CheckState(!halfcloseRequested, "Already halfclosed."); + GrpcPreconditions.CheckState(!finished, "Already finished."); + GrpcPreconditions.CheckState(sendCompletionDelegate == null, "Only one write can be pending at a time"); } protected virtual void CheckReadingAllowed() { - Preconditions.CheckState(started); - Preconditions.CheckState(!disposed); + GrpcPreconditions.CheckState(started); + GrpcPreconditions.CheckState(!disposed); - Preconditions.CheckState(!readingDone, "Stream has already been closed."); - Preconditions.CheckState(readCompletionDelegate == null, "Only one read can be pending at a time"); + GrpcPreconditions.CheckState(!readingDone, "Stream has already been closed."); + GrpcPreconditions.CheckState(readCompletionDelegate == null, "Only one read can be pending at a time"); } protected void CheckNotCancelled() diff --git a/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs b/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs index 6752d3fab3..b72cbd795f 100644 --- a/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs +++ b/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs @@ -53,7 +53,7 @@ namespace Grpc.Core.Internal public AsyncCallServer(Func<TResponse, byte[]> serializer, Func<byte[], TRequest> deserializer, GrpcEnvironment environment, Server server) : base(serializer, deserializer, environment) { - this.server = Preconditions.CheckNotNull(server); + this.server = GrpcPreconditions.CheckNotNull(server); } public void Initialize(CallSafeHandle call) @@ -71,7 +71,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckNotNull(call); + GrpcPreconditions.CheckNotNull(call); started = true; @@ -108,14 +108,14 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckNotNull(headers, "metadata"); - Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); + GrpcPreconditions.CheckNotNull(headers, "metadata"); + GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); - Preconditions.CheckState(!initialMetadataSent, "Response headers can only be sent once per call."); - Preconditions.CheckState(streamingWritesCounter == 0, "Response headers can only be sent before the first write starts."); + GrpcPreconditions.CheckState(!initialMetadataSent, "Response headers can only be sent once per call."); + GrpcPreconditions.CheckState(streamingWritesCounter == 0, "Response headers can only be sent before the first write starts."); CheckSendingAllowed(); - Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); + GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); using (var metadataArray = MetadataArraySafeHandle.Create(headers)) { @@ -136,7 +136,7 @@ namespace Grpc.Core.Internal { lock (myLock) { - Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); + GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null"); CheckSendingAllowed(); using (var metadataArray = MetadataArraySafeHandle.Create(trailers)) @@ -177,7 +177,7 @@ namespace Grpc.Core.Internal protected override void CheckReadingAllowed() { base.CheckReadingAllowed(); - Preconditions.CheckArgument(!cancelRequested); + GrpcPreconditions.CheckArgument(!cancelRequested); } protected override void OnAfterReleaseResources() diff --git a/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs b/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs index 9d7a990c42..5c75b52e23 100644 --- a/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs @@ -101,7 +101,7 @@ namespace Grpc.Core.Internal { bool success = false; shutdownRefcount.IncrementIfNonzero(ref success); - Preconditions.CheckState(success, "Shutdown has already been called"); + GrpcPreconditions.CheckState(success, "Shutdown has already been called"); } private void EndOp() diff --git a/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs b/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs index 2796c959a3..3a293e1626 100644 --- a/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs +++ b/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -59,7 +59,7 @@ namespace Grpc.Core.Internal public void Register(IntPtr key, OpCompletionDelegate callback) { environment.DebugStats.PendingBatchCompletions.Increment(); - Preconditions.CheckState(dict.TryAdd(key, callback)); + GrpcPreconditions.CheckState(dict.TryAdd(key, callback)); } public void RegisterBatchCompletion(BatchContextSafeHandle ctx, BatchCompletionDelegate callback) @@ -71,7 +71,7 @@ namespace Grpc.Core.Internal public OpCompletionDelegate Extract(IntPtr key) { OpCompletionDelegate value; - Preconditions.CheckState(dict.TryRemove(key, out value)); + GrpcPreconditions.CheckState(dict.TryRemove(key, out value)); environment.DebugStats.PendingBatchCompletions.Decrement(); return value; } diff --git a/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs b/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs index eeaa7add81..dfaee5d9d7 100644 --- a/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs +++ b/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs @@ -56,7 +56,7 @@ namespace Grpc.Core.Internal { lock (staticLock) { - var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(RootsPemResourceName); + var stream = typeof(DefaultSslRootsOverride).GetTypeInfo().Assembly.GetManifestResourceStream(RootsPemResourceName); if (stream == null) { throw new IOException(string.Format("Error loading the embedded resource \"{0}\"", RootsPemResourceName)); diff --git a/src/csharp/Grpc.Core/Internal/Enums.cs b/src/csharp/Grpc.Core/Internal/Enums.cs index b0eab2001b..098e7c0e99 100644 --- a/src/csharp/Grpc.Core/Internal/Enums.cs +++ b/src/csharp/Grpc.Core/Internal/Enums.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -72,7 +72,7 @@ namespace Grpc.Core.Internal /// </summary> public static void CheckOk(this GRPCCallError callError) { - Preconditions.CheckState(callError == GRPCCallError.OK, "Call error: " + callError); + GrpcPreconditions.CheckState(callError == GRPCCallError.OK, "Call error: " + callError); } } diff --git a/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs b/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs index 36b865c09c..e810ffcdd0 100644 --- a/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs +++ b/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs @@ -53,7 +53,7 @@ namespace Grpc.Core.Internal public NativeMetadataCredentialsPlugin(AsyncAuthInterceptor interceptor) { - this.interceptor = Preconditions.CheckNotNull(interceptor, "interceptor"); + this.interceptor = GrpcPreconditions.CheckNotNull(interceptor, "interceptor"); this.nativeInterceptor = NativeMetadataInterceptorHandler; // Make sure the callback doesn't get garbage collected until it is destroyed. diff --git a/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs index de66759b94..ccf144de2d 100644 --- a/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs +++ b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -78,10 +78,10 @@ namespace Grpc.Core.Internal var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken); try { - Preconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false)); + GrpcPreconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false)); var request = requestStream.Current; // TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated. - Preconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false)); + GrpcPreconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false)); var result = await handler(request, context).ConfigureAwait(false); status = context.Status; await responseStream.WriteAsync(result).ConfigureAwait(false); @@ -134,10 +134,10 @@ namespace Grpc.Core.Internal var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken); try { - Preconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false)); + GrpcPreconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false)); var request = requestStream.Current; // TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated. - Preconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false)); + GrpcPreconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false)); await handler(request, responseStream, context).ConfigureAwait(false); status = context.Status; } diff --git a/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs index a1d080c7f1..a50f357990 100644 --- a/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs @@ -49,7 +49,7 @@ namespace Grpc.Core.Internal public static ServerCredentialsSafeHandle CreateSslCredentials(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, bool forceClientAuth) { - Preconditions.CheckArgument(keyCertPairCertChainArray.Length == keyCertPairPrivateKeyArray.Length); + GrpcPreconditions.CheckArgument(keyCertPairCertChainArray.Length == keyCertPairPrivateKeyArray.Length); return Native.grpcsharp_ssl_server_credentials_create(pemRootCerts, keyCertPairCertChainArray, keyCertPairPrivateKeyArray, new UIntPtr((ulong)keyCertPairCertChainArray.Length), diff --git a/src/csharp/Grpc.Core/Internal/Timespec.cs b/src/csharp/Grpc.Core/Internal/Timespec.cs index 148d877da5..754be4e035 100644 --- a/src/csharp/Grpc.Core/Internal/Timespec.cs +++ b/src/csharp/Grpc.Core/Internal/Timespec.cs @@ -141,8 +141,8 @@ namespace Grpc.Core.Internal /// </summary> public DateTime ToDateTime() { - Preconditions.CheckState(tv_nsec >= 0 && tv_nsec < NanosPerSecond); - Preconditions.CheckState(clock_type == GPRClockType.Realtime); + GrpcPreconditions.CheckState(tv_nsec >= 0 && tv_nsec < NanosPerSecond); + GrpcPreconditions.CheckState(clock_type == GPRClockType.Realtime); // fast path for InfFuture if (this.Equals(InfFuture)) @@ -195,7 +195,7 @@ namespace Grpc.Core.Internal return Timespec.InfPast; } - Preconditions.CheckArgument(dateTime.Kind == DateTimeKind.Utc, "dateTime needs of kind DateTimeKind.Utc or be equal to DateTime.MaxValue or DateTime.MinValue."); + GrpcPreconditions.CheckArgument(dateTime.Kind == DateTimeKind.Utc, "dateTime needs of kind DateTimeKind.Utc or be equal to DateTime.MaxValue or DateTime.MinValue."); try { diff --git a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs index 95a8797e3e..e763c15025 100644 --- a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs +++ b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs @@ -65,7 +65,7 @@ namespace Grpc.Core.Internal public UnmanagedLibrary(string libraryPath) { - this.libraryPath = Preconditions.CheckNotNull(libraryPath); + this.libraryPath = GrpcPreconditions.CheckNotNull(libraryPath); if (!File.Exists(this.libraryPath)) { diff --git a/src/csharp/Grpc.Core/KeyCertificatePair.cs b/src/csharp/Grpc.Core/KeyCertificatePair.cs index 6f691975e9..0fb6817986 100644 --- a/src/csharp/Grpc.Core/KeyCertificatePair.cs +++ b/src/csharp/Grpc.Core/KeyCertificatePair.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -54,8 +54,8 @@ namespace Grpc.Core /// <param name="privateKey">PEM encoded private key.</param> public KeyCertificatePair(string certificateChain, string privateKey) { - this.certificateChain = Preconditions.CheckNotNull(certificateChain, "certificateChain"); - this.privateKey = Preconditions.CheckNotNull(privateKey, "privateKey"); + this.certificateChain = GrpcPreconditions.CheckNotNull(certificateChain, "certificateChain"); + this.privateKey = GrpcPreconditions.CheckNotNull(privateKey, "privateKey"); } /// <summary> diff --git a/src/csharp/Grpc.Core/Logging/NullLogger.cs b/src/csharp/Grpc.Core/Logging/NullLogger.cs new file mode 100644 index 0000000000..58679a0ff9 --- /dev/null +++ b/src/csharp/Grpc.Core/Logging/NullLogger.cs @@ -0,0 +1,122 @@ +#region Copyright notice and license + +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; + +namespace Grpc.Core.Logging +{ + /// <summary> + /// Logger which doesn't log any information anywhere. + /// </summary> + public sealed class NullLogger : ILogger + { + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Debug(string message) + { + } + + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Debug(string format, params object[] formatArgs) + { + } + + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Error(string message) + { + } + + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Error(Exception exception, string message) + { + } + + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Error(string format, params object[] formatArgs) + { + } + + /// <summary> + /// Returns a reference to the instance on which the method is called, as + /// instances aren't associated with specific types. + /// </summary> + public ILogger ForType<T>() + { + return this; + } + + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Info(string message) + { + } + + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Info(string format, params object[] formatArgs) + { + } + + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Warning(string message) + { + } + + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Warning(Exception exception, string message) + { + } + + /// <summary> + /// As with all logging calls on this logger, this method is a no-op. + /// </summary> + public void Warning(string format, params object[] formatArgs) + { + } + } +} diff --git a/src/csharp/Grpc.Core/Marshaller.cs b/src/csharp/Grpc.Core/Marshaller.cs index 3493d2d38f..5847248c1a 100644 --- a/src/csharp/Grpc.Core/Marshaller.cs +++ b/src/csharp/Grpc.Core/Marshaller.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -51,8 +51,8 @@ namespace Grpc.Core /// <param name="deserializer">Function that will be used to deserialize messages.</param> public Marshaller(Func<T, byte[]> serializer, Func<byte[], T> deserializer) { - this.serializer = Preconditions.CheckNotNull(serializer, "serializer"); - this.deserializer = Preconditions.CheckNotNull(deserializer, "deserializer"); + this.serializer = GrpcPreconditions.CheckNotNull(serializer, "serializer"); + this.deserializer = GrpcPreconditions.CheckNotNull(deserializer, "deserializer"); } /// <summary> diff --git a/src/csharp/Grpc.Core/Metadata.cs b/src/csharp/Grpc.Core/Metadata.cs index 21bdf4f114..aa22f840d6 100644 --- a/src/csharp/Grpc.Core/Metadata.cs +++ b/src/csharp/Grpc.Core/Metadata.cs @@ -1,5 +1,5 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -179,7 +179,7 @@ namespace Grpc.Core private void CheckWriteable() { - Preconditions.CheckState(!readOnly, "Object is read only"); + GrpcPreconditions.CheckState(!readOnly, "Object is read only"); } #endregion @@ -211,10 +211,10 @@ namespace Grpc.Core public Entry(string key, byte[] valueBytes) { this.key = NormalizeKey(key); - Preconditions.CheckArgument(this.key.EndsWith(BinaryHeaderSuffix), + GrpcPreconditions.CheckArgument(this.key.EndsWith(BinaryHeaderSuffix), "Key for binary valued metadata entry needs to have suffix indicating binary value."); this.value = null; - Preconditions.CheckNotNull(valueBytes, "valueBytes"); + GrpcPreconditions.CheckNotNull(valueBytes, "valueBytes"); this.valueBytes = new byte[valueBytes.Length]; Buffer.BlockCopy(valueBytes, 0, this.valueBytes, 0, valueBytes.Length); // defensive copy to guarantee immutability } @@ -227,9 +227,9 @@ namespace Grpc.Core public Entry(string key, string value) { this.key = NormalizeKey(key); - Preconditions.CheckArgument(!this.key.EndsWith(BinaryHeaderSuffix), + GrpcPreconditions.CheckArgument(!this.key.EndsWith(BinaryHeaderSuffix), "Key for ASCII valued metadata entry cannot have suffix indicating binary value."); - this.value = Preconditions.CheckNotNull(value, "value"); + this.value = GrpcPreconditions.CheckNotNull(value, "value"); this.valueBytes = null; } @@ -270,7 +270,7 @@ namespace Grpc.Core { get { - Preconditions.CheckState(!IsBinary, "Cannot access string value of a binary metadata entry"); + GrpcPreconditions.CheckState(!IsBinary, "Cannot access string value of a binary metadata entry"); return value ?? Encoding.GetString(valueBytes); } } @@ -323,8 +323,8 @@ namespace Grpc.Core private static string NormalizeKey(string key) { - var normalized = Preconditions.CheckNotNull(key, "key").ToLower(CultureInfo.InvariantCulture); - Preconditions.CheckArgument(ValidKeyRegex.IsMatch(normalized), + var normalized = GrpcPreconditions.CheckNotNull(key, "key").ToLower(CultureInfo.InvariantCulture); + GrpcPreconditions.CheckArgument(ValidKeyRegex.IsMatch(normalized), "Metadata entry key not valid. Keys can only contain lowercase alphanumeric characters, underscores and hyphens."); return normalized; } diff --git a/src/csharp/Grpc.Core/Method.cs b/src/csharp/Grpc.Core/Method.cs index 99162a7d5d..3870076f7f 100644 --- a/src/csharp/Grpc.Core/Method.cs +++ b/src/csharp/Grpc.Core/Method.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -106,10 +106,10 @@ namespace Grpc.Core public Method(MethodType type, string serviceName, string name, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller) { this.type = type; - this.serviceName = Preconditions.CheckNotNull(serviceName, "serviceName"); - this.name = Preconditions.CheckNotNull(name, "name"); - this.requestMarshaller = Preconditions.CheckNotNull(requestMarshaller, "requestMarshaller"); - this.responseMarshaller = Preconditions.CheckNotNull(responseMarshaller, "responseMarshaller"); + this.serviceName = GrpcPreconditions.CheckNotNull(serviceName, "serviceName"); + this.name = GrpcPreconditions.CheckNotNull(name, "name"); + this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller"); + this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller"); this.fullName = GetFullName(serviceName, name); } diff --git a/src/csharp/Grpc.Core/Profiling/Profilers.cs b/src/csharp/Grpc.Core/Profiling/Profilers.cs index 471ee20875..8a181447d6 100644 --- a/src/csharp/Grpc.Core/Profiling/Profilers.cs +++ b/src/csharp/Grpc.Core/Profiling/Profilers.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -111,7 +111,7 @@ namespace Grpc.Core.Profiling public void Dump(string filepath) { - using (var stream = new StreamWriter(filepath)) + using (var stream = File.CreateText(filepath)) { Dump(stream); } diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs index d120f95fdf..5d0fc6b1f0 100644 --- a/src/csharp/Grpc.Core/Server.cs +++ b/src/csharp/Grpc.Core/Server.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -125,7 +125,7 @@ namespace Grpc.Core { lock (myLock) { - Preconditions.CheckState(!startRequested); + GrpcPreconditions.CheckState(!startRequested); startRequested = true; handle.Start(); @@ -142,8 +142,8 @@ namespace Grpc.Core { lock (myLock) { - Preconditions.CheckState(startRequested); - Preconditions.CheckState(!shutdownRequested); + GrpcPreconditions.CheckState(startRequested); + GrpcPreconditions.CheckState(!shutdownRequested); shutdownRequested = true; } @@ -162,8 +162,8 @@ namespace Grpc.Core { lock (myLock) { - Preconditions.CheckState(startRequested); - Preconditions.CheckState(!shutdownRequested); + GrpcPreconditions.CheckState(startRequested); + GrpcPreconditions.CheckState(!shutdownRequested); shutdownRequested = true; } @@ -181,7 +181,7 @@ namespace Grpc.Core bool success = false; handle.DangerousAddRef(ref success); - Preconditions.CheckState(success); + GrpcPreconditions.CheckState(success); } internal void RemoveCallReference(object call) @@ -197,7 +197,7 @@ namespace Grpc.Core { lock (myLock) { - Preconditions.CheckState(!startRequested); + GrpcPreconditions.CheckState(!startRequested); foreach (var entry in serviceDefinition.CallHandlers) { callHandlers.Add(entry.Key, entry.Value); @@ -213,8 +213,8 @@ namespace Grpc.Core { lock (myLock) { - Preconditions.CheckNotNull(serverPort.Credentials, "serverPort"); - Preconditions.CheckState(!startRequested); + GrpcPreconditions.CheckNotNull(serverPort.Credentials, "serverPort"); + GrpcPreconditions.CheckState(!startRequested); var address = string.Format("{0}:{1}", serverPort.Host, serverPort.Port); int boundPort; using (var nativeCredentials = serverPort.Credentials.ToNativeCredentials()) diff --git a/src/csharp/Grpc.Core/ServerCredentials.cs b/src/csharp/Grpc.Core/ServerCredentials.cs index 3c6703d30e..456d331c9c 100644 --- a/src/csharp/Grpc.Core/ServerCredentials.cs +++ b/src/csharp/Grpc.Core/ServerCredentials.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -90,11 +90,11 @@ namespace Grpc.Core public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs, string rootCertificates, bool forceClientAuth) { this.keyCertificatePairs = new List<KeyCertificatePair>(keyCertificatePairs).AsReadOnly(); - Preconditions.CheckArgument(this.keyCertificatePairs.Count > 0, + GrpcPreconditions.CheckArgument(this.keyCertificatePairs.Count > 0, "At least one KeyCertificatePair needs to be provided."); if (forceClientAuth) { - Preconditions.CheckNotNull(rootCertificates, + GrpcPreconditions.CheckNotNull(rootCertificates, "Cannot force client authentication unless you provide rootCertificates."); } this.rootCertificates = rootCertificates; diff --git a/src/csharp/Grpc.Core/ServerPort.cs b/src/csharp/Grpc.Core/ServerPort.cs index 598404d045..10ddcb782f 100644 --- a/src/csharp/Grpc.Core/ServerPort.cs +++ b/src/csharp/Grpc.Core/ServerPort.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -62,9 +62,9 @@ namespace Grpc.Core /// <param name="credentials">credentials to use to secure this port.</param> public ServerPort(string host, int port, ServerCredentials credentials) { - this.host = Preconditions.CheckNotNull(host, "host"); + this.host = GrpcPreconditions.CheckNotNull(host, "host"); this.port = port; - this.credentials = Preconditions.CheckNotNull(credentials, "credentials"); + this.credentials = GrpcPreconditions.CheckNotNull(credentials, "credentials"); } /// <summary> diff --git a/src/csharp/Grpc.Core/Utils/Preconditions.cs b/src/csharp/Grpc.Core/Utils/GrpcPreconditions.cs index a8ab603391..76bf04ce8b 100644 --- a/src/csharp/Grpc.Core/Utils/Preconditions.cs +++ b/src/csharp/Grpc.Core/Utils/GrpcPreconditions.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -38,7 +38,7 @@ namespace Grpc.Core.Utils /// <summary> /// Utility methods to simplify checking preconditions in the code. /// </summary> - public static class Preconditions + public static class GrpcPreconditions { /// <summary> /// Throws <see cref="ArgumentException"/> if condition is false. diff --git a/src/csharp/Grpc.Core/Version.cs b/src/csharp/Grpc.Core/Version.cs index d02b301cac..6d88438a07 100644 --- a/src/csharp/Grpc.Core/Version.cs +++ b/src/csharp/Grpc.Core/Version.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -34,4 +34,4 @@ using System.Reflection; // The current version of gRPC C#. -[assembly: AssemblyVersion(Grpc.Core.VersionInfo.CurrentVersion + ".0")] +[assembly: AssemblyVersion(Grpc.Core.VersionInfo.CurrentAssemblyVersion)] diff --git a/src/csharp/Grpc.Core/VersionInfo.cs b/src/csharp/Grpc.Core/VersionInfo.cs index 65813909de..4bd4f204dd 100644 --- a/src/csharp/Grpc.Core/VersionInfo.cs +++ b/src/csharp/Grpc.Core/VersionInfo.cs @@ -39,8 +39,13 @@ namespace Grpc.Core public static class VersionInfo { /// <summary> + /// Current version of gRPC C# assemblies + /// </summary> + public const string CurrentAssemblyVersion = "0.14.0.0"; + + /// <summary> /// Current version of gRPC C# /// </summary> - public const string CurrentVersion = "0.13.0"; + public const string CurrentVersion = "0.14.0-dev"; } } diff --git a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs index 26c6445c35..e2ad1a834b 100644 --- a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs +++ b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs @@ -1,5 +1,5 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -127,8 +127,8 @@ namespace Grpc.HealthCheck { public Key(string host, string service) { - this.Host = Preconditions.CheckNotNull(host); - this.Service = Preconditions.CheckNotNull(service); + this.Host = GrpcPreconditions.CheckNotNull(host); + this.Service = GrpcPreconditions.CheckNotNull(service); } readonly string Host; diff --git a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs index e9e659cb1f..c4016012cb 100644 --- a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs +++ b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -58,7 +58,7 @@ namespace Grpc.IntegrationTesting public static IClientRunner CreateStarted(ClientConfig config) { string target = config.ServerTargets.Single(); - Grpc.Core.Utils.Preconditions.CheckArgument(config.LoadParams.LoadCase == LoadParams.LoadOneofCase.ClosedLoop); + GrpcPreconditions.CheckArgument(config.LoadParams.LoadCase == LoadParams.LoadOneofCase.ClosedLoop); var credentials = config.SecurityParams != null ? TestCredentials.CreateSslCredentials() : ChannelCredentials.Insecure; var channel = new Channel(target, credentials); @@ -95,7 +95,7 @@ namespace Grpc.IntegrationTesting public SyncUnaryClientRunner(Channel channel, int payloadSize, HistogramParams histogramParams) { - this.channel = Grpc.Core.Utils.Preconditions.CheckNotNull(channel); + this.channel = GrpcPreconditions.CheckNotNull(channel); this.payloadSize = payloadSize; this.histogram = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible); diff --git a/src/csharp/Grpc.IntegrationTesting/Control.cs b/src/csharp/Grpc.IntegrationTesting/Control.cs index b90243c2bd..291bc75397 100644 --- a/src/csharp/Grpc.IntegrationTesting/Control.cs +++ b/src/csharp/Grpc.IntegrationTesting/Control.cs @@ -38,7 +38,7 @@ namespace Grpc.Testing { "LmdycGMudGVzdGluZy5EZXRlcm1pbmlzdGljUGFyYW1zSAASLAoGcGFyZXRv", "GAUgASgLMhouZ3JwYy50ZXN0aW5nLlBhcmV0b1BhcmFtc0gAQgYKBGxvYWQi", "QwoOU2VjdXJpdHlQYXJhbXMSEwoLdXNlX3Rlc3RfY2EYASABKAgSHAoUc2Vy", - "dmVyX2hvc3Rfb3ZlcnJpZGUYAiABKAkirwMKDENsaWVudENvbmZpZxIWCg5z", + "dmVyX2hvc3Rfb3ZlcnJpZGUYAiABKAki1gMKDENsaWVudENvbmZpZxIWCg5z", "ZXJ2ZXJfdGFyZ2V0cxgBIAMoCRItCgtjbGllbnRfdHlwZRgCIAEoDjIYLmdy", "cGMudGVzdGluZy5DbGllbnRUeXBlEjUKD3NlY3VyaXR5X3BhcmFtcxgDIAEo", "CzIcLmdycGMudGVzdGluZy5TZWN1cml0eVBhcmFtcxIkChxvdXRzdGFuZGlu", @@ -48,24 +48,27 @@ namespace Grpc.Testing { "GAogASgLMhguZ3JwYy50ZXN0aW5nLkxvYWRQYXJhbXMSMwoOcGF5bG9hZF9j", "b25maWcYCyABKAsyGy5ncnBjLnRlc3RpbmcuUGF5bG9hZENvbmZpZxI3ChBo", "aXN0b2dyYW1fcGFyYW1zGAwgASgLMh0uZ3JwYy50ZXN0aW5nLkhpc3RvZ3Jh", - "bVBhcmFtcyI4CgxDbGllbnRTdGF0dXMSKAoFc3RhdHMYASABKAsyGS5ncnBj", - "LnRlc3RpbmcuQ2xpZW50U3RhdHMiFQoETWFyaxINCgVyZXNldBgBIAEoCCJo", - "CgpDbGllbnRBcmdzEisKBXNldHVwGAEgASgLMhouZ3JwYy50ZXN0aW5nLkNs", - "aWVudENvbmZpZ0gAEiIKBG1hcmsYAiABKAsyEi5ncnBjLnRlc3RpbmcuTWFy", - "a0gAQgkKB2FyZ3R5cGUi9wEKDFNlcnZlckNvbmZpZxItCgtzZXJ2ZXJfdHlw", - "ZRgBIAEoDjIYLmdycGMudGVzdGluZy5TZXJ2ZXJUeXBlEjUKD3NlY3VyaXR5", - "X3BhcmFtcxgCIAEoCzIcLmdycGMudGVzdGluZy5TZWN1cml0eVBhcmFtcxIM", - "CgRob3N0GAMgASgJEgwKBHBvcnQYBCABKAUSHAoUYXN5bmNfc2VydmVyX3Ro", - "cmVhZHMYByABKAUSEgoKY29yZV9saW1pdBgIIAEoBRIzCg5wYXlsb2FkX2Nv", - "bmZpZxgJIAEoCzIbLmdycGMudGVzdGluZy5QYXlsb2FkQ29uZmlnImgKClNl", - "cnZlckFyZ3MSKwoFc2V0dXAYASABKAsyGi5ncnBjLnRlc3RpbmcuU2VydmVy", - "Q29uZmlnSAASIgoEbWFyaxgCIAEoCzISLmdycGMudGVzdGluZy5NYXJrSABC", - "CQoHYXJndHlwZSJVCgxTZXJ2ZXJTdGF0dXMSKAoFc3RhdHMYASABKAsyGS5n", - "cnBjLnRlc3RpbmcuU2VydmVyU3RhdHMSDAoEcG9ydBgCIAEoBRINCgVjb3Jl", - "cxgDIAEoBSovCgpDbGllbnRUeXBlEg8KC1NZTkNfQ0xJRU5UEAASEAoMQVNZ", - "TkNfQ0xJRU5UEAEqLwoKU2VydmVyVHlwZRIPCgtTWU5DX1NFUlZFUhAAEhAK", - "DEFTWU5DX1NFUlZFUhABKiMKB1JwY1R5cGUSCQoFVU5BUlkQABINCglTVFJF", - "QU1JTkcQAWIGcHJvdG8z")); + "bVBhcmFtcxIRCgljb3JlX2xpc3QYDSADKAUSEgoKY29yZV9saW1pdBgOIAEo", + "BSI4CgxDbGllbnRTdGF0dXMSKAoFc3RhdHMYASABKAsyGS5ncnBjLnRlc3Rp", + "bmcuQ2xpZW50U3RhdHMiFQoETWFyaxINCgVyZXNldBgBIAEoCCJoCgpDbGll", + "bnRBcmdzEisKBXNldHVwGAEgASgLMhouZ3JwYy50ZXN0aW5nLkNsaWVudENv", + "bmZpZ0gAEiIKBG1hcmsYAiABKAsyEi5ncnBjLnRlc3RpbmcuTWFya0gAQgkK", + "B2FyZ3R5cGUi/AEKDFNlcnZlckNvbmZpZxItCgtzZXJ2ZXJfdHlwZRgBIAEo", + "DjIYLmdycGMudGVzdGluZy5TZXJ2ZXJUeXBlEjUKD3NlY3VyaXR5X3BhcmFt", + "cxgCIAEoCzIcLmdycGMudGVzdGluZy5TZWN1cml0eVBhcmFtcxIMCgRwb3J0", + "GAQgASgFEhwKFGFzeW5jX3NlcnZlcl90aHJlYWRzGAcgASgFEhIKCmNvcmVf", + "bGltaXQYCCABKAUSMwoOcGF5bG9hZF9jb25maWcYCSABKAsyGy5ncnBjLnRl", + "c3RpbmcuUGF5bG9hZENvbmZpZxIRCgljb3JlX2xpc3QYCiADKAUiaAoKU2Vy", + "dmVyQXJncxIrCgVzZXR1cBgBIAEoCzIaLmdycGMudGVzdGluZy5TZXJ2ZXJD", + "b25maWdIABIiCgRtYXJrGAIgASgLMhIuZ3JwYy50ZXN0aW5nLk1hcmtIAEIJ", + "Cgdhcmd0eXBlIlUKDFNlcnZlclN0YXR1cxIoCgVzdGF0cxgBIAEoCzIZLmdy", + "cGMudGVzdGluZy5TZXJ2ZXJTdGF0cxIMCgRwb3J0GAIgASgFEg0KBWNvcmVz", + "GAMgASgFIg0KC0NvcmVSZXF1ZXN0Ih0KDENvcmVSZXNwb25zZRINCgVjb3Jl", + "cxgBIAEoBSIGCgRWb2lkKi8KCkNsaWVudFR5cGUSDwoLU1lOQ19DTElFTlQQ", + "ABIQCgxBU1lOQ19DTElFTlQQASpJCgpTZXJ2ZXJUeXBlEg8KC1NZTkNfU0VS", + "VkVSEAASEAoMQVNZTkNfU0VSVkVSEAESGAoUQVNZTkNfR0VORVJJQ19TRVJW", + "RVIQAiojCgdScGNUeXBlEgkKBVVOQVJZEAASDQoJU1RSRUFNSU5HEAFiBnBy", + "b3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { global::Grpc.Testing.PayloadsReflection.Descriptor, global::Grpc.Testing.StatsReflection.Descriptor, }, new pbr::GeneratedCodeInfo(new[] {typeof(global::Grpc.Testing.ClientType), typeof(global::Grpc.Testing.ServerType), typeof(global::Grpc.Testing.RpcType), }, new pbr::GeneratedCodeInfo[] { @@ -76,13 +79,16 @@ namespace Grpc.Testing { new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClosedLoopParams), global::Grpc.Testing.ClosedLoopParams.Parser, null, null, null, null), new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.LoadParams), global::Grpc.Testing.LoadParams.Parser, new[]{ "ClosedLoop", "Poisson", "Uniform", "Determ", "Pareto" }, new[]{ "Load" }, null, null), new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.SecurityParams), global::Grpc.Testing.SecurityParams.Parser, new[]{ "UseTestCa", "ServerHostOverride" }, null, null, null), - new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClientConfig), global::Grpc.Testing.ClientConfig.Parser, new[]{ "ServerTargets", "ClientType", "SecurityParams", "OutstandingRpcsPerChannel", "ClientChannels", "AsyncClientThreads", "RpcType", "LoadParams", "PayloadConfig", "HistogramParams" }, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClientConfig), global::Grpc.Testing.ClientConfig.Parser, new[]{ "ServerTargets", "ClientType", "SecurityParams", "OutstandingRpcsPerChannel", "ClientChannels", "AsyncClientThreads", "RpcType", "LoadParams", "PayloadConfig", "HistogramParams", "CoreList", "CoreLimit" }, null, null, null), new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClientStatus), global::Grpc.Testing.ClientStatus.Parser, new[]{ "Stats" }, null, null, null), new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.Mark), global::Grpc.Testing.Mark.Parser, new[]{ "Reset" }, null, null, null), new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClientArgs), global::Grpc.Testing.ClientArgs.Parser, new[]{ "Setup", "Mark" }, new[]{ "Argtype" }, null, null), - new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerConfig), global::Grpc.Testing.ServerConfig.Parser, new[]{ "ServerType", "SecurityParams", "Host", "Port", "AsyncServerThreads", "CoreLimit", "PayloadConfig" }, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerConfig), global::Grpc.Testing.ServerConfig.Parser, new[]{ "ServerType", "SecurityParams", "Port", "AsyncServerThreads", "CoreLimit", "PayloadConfig", "CoreList" }, null, null, null), new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerArgs), global::Grpc.Testing.ServerArgs.Parser, new[]{ "Setup", "Mark" }, new[]{ "Argtype" }, null, null), - new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerStatus), global::Grpc.Testing.ServerStatus.Parser, new[]{ "Stats", "Port", "Cores" }, null, null, null) + new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerStatus), global::Grpc.Testing.ServerStatus.Parser, new[]{ "Stats", "Port", "Cores" }, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.CoreRequest), global::Grpc.Testing.CoreRequest.Parser, null, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.CoreResponse), global::Grpc.Testing.CoreResponse.Parser, new[]{ "Cores" }, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.Void), global::Grpc.Testing.Void.Parser, null, null, null, null) })); } #endregion @@ -97,6 +103,7 @@ namespace Grpc.Testing { public enum ServerType { SYNC_SERVER = 0, ASYNC_SERVER = 1, + ASYNC_GENERIC_SERVER = 2, } public enum RpcType { @@ -1097,6 +1104,8 @@ namespace Grpc.Testing { LoadParams = other.loadParams_ != null ? other.LoadParams.Clone() : null; PayloadConfig = other.payloadConfig_ != null ? other.PayloadConfig.Clone() : null; HistogramParams = other.histogramParams_ != null ? other.HistogramParams.Clone() : null; + coreList_ = other.coreList_.Clone(); + coreLimit_ = other.coreLimit_; } public ClientConfig Clone() { @@ -1219,6 +1228,28 @@ namespace Grpc.Testing { } } + /// <summary>Field number for the "core_list" field.</summary> + public const int CoreListFieldNumber = 13; + private static readonly pb::FieldCodec<int> _repeated_coreList_codec + = pb::FieldCodec.ForInt32(106); + private readonly pbc::RepeatedField<int> coreList_ = new pbc::RepeatedField<int>(); + /// <summary> + /// Specify the cores we should run the client on, if desired + /// </summary> + public pbc::RepeatedField<int> CoreList { + get { return coreList_; } + } + + /// <summary>Field number for the "core_limit" field.</summary> + public const int CoreLimitFieldNumber = 14; + private int coreLimit_; + public int CoreLimit { + get { return coreLimit_; } + set { + coreLimit_ = value; + } + } + public override bool Equals(object other) { return Equals(other as ClientConfig); } @@ -1240,6 +1271,8 @@ namespace Grpc.Testing { if (!object.Equals(LoadParams, other.LoadParams)) return false; if (!object.Equals(PayloadConfig, other.PayloadConfig)) return false; if (!object.Equals(HistogramParams, other.HistogramParams)) return false; + if(!coreList_.Equals(other.coreList_)) return false; + if (CoreLimit != other.CoreLimit) return false; return true; } @@ -1255,6 +1288,8 @@ namespace Grpc.Testing { if (loadParams_ != null) hash ^= LoadParams.GetHashCode(); if (payloadConfig_ != null) hash ^= PayloadConfig.GetHashCode(); if (histogramParams_ != null) hash ^= HistogramParams.GetHashCode(); + hash ^= coreList_.GetHashCode(); + if (CoreLimit != 0) hash ^= CoreLimit.GetHashCode(); return hash; } @@ -1300,6 +1335,11 @@ namespace Grpc.Testing { output.WriteRawTag(98); output.WriteMessage(HistogramParams); } + coreList_.WriteTo(output, _repeated_coreList_codec); + if (CoreLimit != 0) { + output.WriteRawTag(112); + output.WriteInt32(CoreLimit); + } } public int CalculateSize() { @@ -1332,6 +1372,10 @@ namespace Grpc.Testing { if (histogramParams_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(HistogramParams); } + size += coreList_.CalculateSize(_repeated_coreList_codec); + if (CoreLimit != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(CoreLimit); + } return size; } @@ -1379,6 +1423,10 @@ namespace Grpc.Testing { } HistogramParams.MergeFrom(other.HistogramParams); } + coreList_.Add(other.coreList_); + if (other.CoreLimit != 0) { + CoreLimit = other.CoreLimit; + } } public void MergeFrom(pb::CodedInputStream input) { @@ -1440,6 +1488,15 @@ namespace Grpc.Testing { input.ReadMessage(histogramParams_); break; } + case 106: + case 104: { + coreList_.AddEntriesFrom(input, _repeated_coreList_codec); + break; + } + case 112: { + CoreLimit = input.ReadInt32(); + break; + } } } } @@ -1855,11 +1912,11 @@ namespace Grpc.Testing { public ServerConfig(ServerConfig other) : this() { serverType_ = other.serverType_; SecurityParams = other.securityParams_ != null ? other.SecurityParams.Clone() : null; - host_ = other.host_; port_ = other.port_; asyncServerThreads_ = other.asyncServerThreads_; coreLimit_ = other.coreLimit_; PayloadConfig = other.payloadConfig_ != null ? other.PayloadConfig.Clone() : null; + coreList_ = other.coreList_.Clone(); } public ServerConfig Clone() { @@ -1886,19 +1943,6 @@ namespace Grpc.Testing { } } - /// <summary>Field number for the "host" field.</summary> - public const int HostFieldNumber = 3; - private string host_ = ""; - /// <summary> - /// Host on which to listen. - /// </summary> - public string Host { - get { return host_; } - set { - host_ = pb::Preconditions.CheckNotNull(value, "value"); - } - } - /// <summary>Field number for the "port" field.</summary> public const int PortFieldNumber = 4; private int port_; @@ -1929,7 +1973,7 @@ namespace Grpc.Testing { public const int CoreLimitFieldNumber = 8; private int coreLimit_; /// <summary> - /// restrict core usage, currently unused + /// Specify the number of cores to limit server to, if desired /// </summary> public int CoreLimit { get { return coreLimit_; } @@ -1941,6 +1985,9 @@ namespace Grpc.Testing { /// <summary>Field number for the "payload_config" field.</summary> public const int PayloadConfigFieldNumber = 9; private global::Grpc.Testing.PayloadConfig payloadConfig_; + /// <summary> + /// payload config, used in generic server + /// </summary> public global::Grpc.Testing.PayloadConfig PayloadConfig { get { return payloadConfig_; } set { @@ -1948,6 +1995,18 @@ namespace Grpc.Testing { } } + /// <summary>Field number for the "core_list" field.</summary> + public const int CoreListFieldNumber = 10; + private static readonly pb::FieldCodec<int> _repeated_coreList_codec + = pb::FieldCodec.ForInt32(82); + private readonly pbc::RepeatedField<int> coreList_ = new pbc::RepeatedField<int>(); + /// <summary> + /// Specify the cores we should run the server on, if desired + /// </summary> + public pbc::RepeatedField<int> CoreList { + get { return coreList_; } + } + public override bool Equals(object other) { return Equals(other as ServerConfig); } @@ -1961,11 +2020,11 @@ namespace Grpc.Testing { } if (ServerType != other.ServerType) return false; if (!object.Equals(SecurityParams, other.SecurityParams)) return false; - if (Host != other.Host) return false; if (Port != other.Port) return false; if (AsyncServerThreads != other.AsyncServerThreads) return false; if (CoreLimit != other.CoreLimit) return false; if (!object.Equals(PayloadConfig, other.PayloadConfig)) return false; + if(!coreList_.Equals(other.coreList_)) return false; return true; } @@ -1973,11 +2032,11 @@ namespace Grpc.Testing { int hash = 1; if (ServerType != global::Grpc.Testing.ServerType.SYNC_SERVER) hash ^= ServerType.GetHashCode(); if (securityParams_ != null) hash ^= SecurityParams.GetHashCode(); - if (Host.Length != 0) hash ^= Host.GetHashCode(); if (Port != 0) hash ^= Port.GetHashCode(); if (AsyncServerThreads != 0) hash ^= AsyncServerThreads.GetHashCode(); if (CoreLimit != 0) hash ^= CoreLimit.GetHashCode(); if (payloadConfig_ != null) hash ^= PayloadConfig.GetHashCode(); + hash ^= coreList_.GetHashCode(); return hash; } @@ -1994,10 +2053,6 @@ namespace Grpc.Testing { output.WriteRawTag(18); output.WriteMessage(SecurityParams); } - if (Host.Length != 0) { - output.WriteRawTag(26); - output.WriteString(Host); - } if (Port != 0) { output.WriteRawTag(32); output.WriteInt32(Port); @@ -2014,6 +2069,7 @@ namespace Grpc.Testing { output.WriteRawTag(74); output.WriteMessage(PayloadConfig); } + coreList_.WriteTo(output, _repeated_coreList_codec); } public int CalculateSize() { @@ -2024,9 +2080,6 @@ namespace Grpc.Testing { if (securityParams_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(SecurityParams); } - if (Host.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Host); - } if (Port != 0) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(Port); } @@ -2039,6 +2092,7 @@ namespace Grpc.Testing { if (payloadConfig_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(PayloadConfig); } + size += coreList_.CalculateSize(_repeated_coreList_codec); return size; } @@ -2055,9 +2109,6 @@ namespace Grpc.Testing { } SecurityParams.MergeFrom(other.SecurityParams); } - if (other.Host.Length != 0) { - Host = other.Host; - } if (other.Port != 0) { Port = other.Port; } @@ -2073,6 +2124,7 @@ namespace Grpc.Testing { } PayloadConfig.MergeFrom(other.PayloadConfig); } + coreList_.Add(other.coreList_); } public void MergeFrom(pb::CodedInputStream input) { @@ -2093,10 +2145,6 @@ namespace Grpc.Testing { input.ReadMessage(securityParams_); break; } - case 26: { - Host = input.ReadString(); - break; - } case 32: { Port = input.ReadInt32(); break; @@ -2116,6 +2164,11 @@ namespace Grpc.Testing { input.ReadMessage(payloadConfig_); break; } + case 82: + case 80: { + coreList_.AddEntriesFrom(input, _repeated_coreList_codec); + break; + } } } } @@ -2347,7 +2400,7 @@ namespace Grpc.Testing { public const int CoresFieldNumber = 3; private int cores_; /// <summary> - /// Number of cores on the server. See gpr_cpu_num_cores. + /// Number of cores available to the server /// </summary> public int Cores { get { return cores_; } @@ -2460,6 +2513,264 @@ namespace Grpc.Testing { } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public sealed partial class CoreRequest : pb::IMessage<CoreRequest> { + private static readonly pb::MessageParser<CoreRequest> _parser = new pb::MessageParser<CoreRequest>(() => new CoreRequest()); + public static pb::MessageParser<CoreRequest> Parser { get { return _parser; } } + + public static pbr::MessageDescriptor Descriptor { + get { return global::Grpc.Testing.ControlReflection.Descriptor.MessageTypes[14]; } + } + + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + public CoreRequest() { + OnConstruction(); + } + + partial void OnConstruction(); + + public CoreRequest(CoreRequest other) : this() { + } + + public CoreRequest Clone() { + return new CoreRequest(this); + } + + public override bool Equals(object other) { + return Equals(other as CoreRequest); + } + + public bool Equals(CoreRequest other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + return true; + } + + public override int GetHashCode() { + int hash = 1; + return hash; + } + + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + public void WriteTo(pb::CodedOutputStream output) { + } + + public int CalculateSize() { + int size = 0; + return size; + } + + public void MergeFrom(CoreRequest other) { + if (other == null) { + return; + } + } + + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + } + } + } + + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public sealed partial class CoreResponse : pb::IMessage<CoreResponse> { + private static readonly pb::MessageParser<CoreResponse> _parser = new pb::MessageParser<CoreResponse>(() => new CoreResponse()); + public static pb::MessageParser<CoreResponse> Parser { get { return _parser; } } + + public static pbr::MessageDescriptor Descriptor { + get { return global::Grpc.Testing.ControlReflection.Descriptor.MessageTypes[15]; } + } + + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + public CoreResponse() { + OnConstruction(); + } + + partial void OnConstruction(); + + public CoreResponse(CoreResponse other) : this() { + cores_ = other.cores_; + } + + public CoreResponse Clone() { + return new CoreResponse(this); + } + + /// <summary>Field number for the "cores" field.</summary> + public const int CoresFieldNumber = 1; + private int cores_; + /// <summary> + /// Number of cores available on the server + /// </summary> + public int Cores { + get { return cores_; } + set { + cores_ = value; + } + } + + public override bool Equals(object other) { + return Equals(other as CoreResponse); + } + + public bool Equals(CoreResponse other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Cores != other.Cores) return false; + return true; + } + + public override int GetHashCode() { + int hash = 1; + if (Cores != 0) hash ^= Cores.GetHashCode(); + return hash; + } + + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + public void WriteTo(pb::CodedOutputStream output) { + if (Cores != 0) { + output.WriteRawTag(8); + output.WriteInt32(Cores); + } + } + + public int CalculateSize() { + int size = 0; + if (Cores != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Cores); + } + return size; + } + + public void MergeFrom(CoreResponse other) { + if (other == null) { + return; + } + if (other.Cores != 0) { + Cores = other.Cores; + } + } + + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 8: { + Cores = input.ReadInt32(); + break; + } + } + } + } + + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public sealed partial class Void : pb::IMessage<Void> { + private static readonly pb::MessageParser<Void> _parser = new pb::MessageParser<Void>(() => new Void()); + public static pb::MessageParser<Void> Parser { get { return _parser; } } + + public static pbr::MessageDescriptor Descriptor { + get { return global::Grpc.Testing.ControlReflection.Descriptor.MessageTypes[16]; } + } + + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + public Void() { + OnConstruction(); + } + + partial void OnConstruction(); + + public Void(Void other) : this() { + } + + public Void Clone() { + return new Void(this); + } + + public override bool Equals(object other) { + return Equals(other as Void); + } + + public bool Equals(Void other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + return true; + } + + public override int GetHashCode() { + int hash = 1; + return hash; + } + + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + public void WriteTo(pb::CodedOutputStream output) { + } + + public int CalculateSize() { + int size = 0; + return size; + } + + public void MergeFrom(Void other) { + if (other == null) { + return; + } + } + + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + } + } + } + + } + #endregion } diff --git a/src/csharp/Grpc.IntegrationTesting/Histogram.cs b/src/csharp/Grpc.IntegrationTesting/Histogram.cs index 7e7cb2c4de..08a674d817 100644 --- a/src/csharp/Grpc.IntegrationTesting/Histogram.cs +++ b/src/csharp/Grpc.IntegrationTesting/Histogram.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -66,8 +66,8 @@ namespace Grpc.IntegrationTesting public Histogram(double resolution, double maxPossible) { - Grpc.Core.Utils.Preconditions.CheckArgument(resolution > 0); - Grpc.Core.Utils.Preconditions.CheckArgument(maxPossible > 0); + GrpcPreconditions.CheckArgument(resolution > 0); + GrpcPreconditions.CheckArgument(maxPossible > 0); this.maxPossible = maxPossible; this.multiplier = 1.0 + resolution; this.oneOnLogMultiplier = 1.0 / Math.Log(1.0 + resolution); diff --git a/src/csharp/Grpc.IntegrationTesting/QpsWorker.cs b/src/csharp/Grpc.IntegrationTesting/QpsWorker.cs index 686b484345..e407792c4b 100644 --- a/src/csharp/Grpc.IntegrationTesting/QpsWorker.cs +++ b/src/csharp/Grpc.IntegrationTesting/QpsWorker.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -85,24 +85,27 @@ namespace Grpc.IntegrationTesting } var workerServer = new QpsWorker(options); - workerServer.Run(); + workerServer.RunAsync().Wait(); } - private void Run() + private async Task RunAsync() { string host = "0.0.0.0"; int port = options.DriverPort; + var tcs = new TaskCompletionSource<object>(); + var workerServiceImpl = new WorkerServiceImpl(() => { Task.Run(() => tcs.SetResult(null)); }); + var server = new Server { - Services = { WorkerService.BindService(new WorkerServiceImpl()) }, + Services = { WorkerService.BindService(workerServiceImpl) }, Ports = { new ServerPort(host, options.DriverPort, ServerCredentials.Insecure )} }; int boundPort = server.Ports.Single().BoundPort; Console.WriteLine("Running qps worker server on " + string.Format("{0}:{1}", host, boundPort)); server.Start(); - - server.ShutdownTask.Wait(); + await tcs.Task; + await server.ShutdownAsync(); } } } diff --git a/src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs b/src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs index 3dd91b7948..06d5ee93d8 100644 --- a/src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs +++ b/src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -48,7 +48,6 @@ namespace Grpc.IntegrationTesting /// </summary> public class RunnerClientServerTest { - const string Host = "localhost"; IServerRunner serverRunner; [TestFixtureSetUp] @@ -57,7 +56,6 @@ namespace Grpc.IntegrationTesting var serverConfig = new ServerConfig { ServerType = ServerType.ASYNC_SERVER, - Host = Host, PayloadConfig = new PayloadConfig { SimpleParams = new SimpleProtoParams @@ -83,7 +81,7 @@ namespace Grpc.IntegrationTesting { var config = new ClientConfig { - ServerTargets = { string.Format("{0}:{1}", Host, serverRunner.BoundPort) }, + ServerTargets = { string.Format("{0}:{1}", "localhost", serverRunner.BoundPort) }, RpcType = RpcType.UNARY, LoadParams = new LoadParams { ClosedLoop = new ClosedLoopParams() }, PayloadConfig = new PayloadConfig diff --git a/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs b/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs index e8be7758ce..4a73645e6c 100644 --- a/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs +++ b/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -57,7 +57,7 @@ namespace Grpc.IntegrationTesting /// </summary> public static IServerRunner CreateStarted(ServerConfig config) { - Grpc.Core.Utils.Preconditions.CheckArgument(config.ServerType == ServerType.ASYNC_SERVER); + GrpcPreconditions.CheckArgument(config.ServerType == ServerType.ASYNC_SERVER); var credentials = config.SecurityParams != null ? TestCredentials.CreateSslServerCredentials() : ServerCredentials.Insecure; // TODO: qps_driver needs to setup payload properly... @@ -65,7 +65,7 @@ namespace Grpc.IntegrationTesting var server = new Server { Services = { BenchmarkService.BindService(new BenchmarkServiceImpl(responseSize)) }, - Ports = { new ServerPort(config.Host, config.Port, credentials) } + Ports = { new ServerPort("[::]", config.Port, credentials) } }; server.Start(); @@ -83,7 +83,7 @@ namespace Grpc.IntegrationTesting public ServerRunnerImpl(Server server) { - this.server = Grpc.Core.Utils.Preconditions.CheckNotNull(server); + this.server = GrpcPreconditions.CheckNotNull(server); } public int BoundPort diff --git a/src/csharp/Grpc.IntegrationTesting/Services.cs b/src/csharp/Grpc.IntegrationTesting/Services.cs index 04a092ccd7..a8475c1817 100644 --- a/src/csharp/Grpc.IntegrationTesting/Services.cs +++ b/src/csharp/Grpc.IntegrationTesting/Services.cs @@ -29,11 +29,14 @@ namespace Grpc.Testing { "QmVuY2htYXJrU2VydmljZRJGCglVbmFyeUNhbGwSGy5ncnBjLnRlc3Rpbmcu", "U2ltcGxlUmVxdWVzdBocLmdycGMudGVzdGluZy5TaW1wbGVSZXNwb25zZRJO", "Cg1TdHJlYW1pbmdDYWxsEhsuZ3JwYy50ZXN0aW5nLlNpbXBsZVJlcXVlc3Qa", - "HC5ncnBjLnRlc3RpbmcuU2ltcGxlUmVzcG9uc2UoATABMp0BCg1Xb3JrZXJT", + "HC5ncnBjLnRlc3RpbmcuU2ltcGxlUmVzcG9uc2UoATABMpcCCg1Xb3JrZXJT", "ZXJ2aWNlEkUKCVJ1blNlcnZlchIYLmdycGMudGVzdGluZy5TZXJ2ZXJBcmdz", "GhouZ3JwYy50ZXN0aW5nLlNlcnZlclN0YXR1cygBMAESRQoJUnVuQ2xpZW50", "EhguZ3JwYy50ZXN0aW5nLkNsaWVudEFyZ3MaGi5ncnBjLnRlc3RpbmcuQ2xp", - "ZW50U3RhdHVzKAEwAWIGcHJvdG8z")); + "ZW50U3RhdHVzKAEwARJCCglDb3JlQ291bnQSGS5ncnBjLnRlc3RpbmcuQ29y", + "ZVJlcXVlc3QaGi5ncnBjLnRlc3RpbmcuQ29yZVJlc3BvbnNlEjQKClF1aXRX", + "b3JrZXISEi5ncnBjLnRlc3RpbmcuVm9pZBoSLmdycGMudGVzdGluZy5Wb2lk", + "YgZwcm90bzM=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { global::Grpc.Testing.MessagesReflection.Descriptor, global::Grpc.Testing.ControlReflection.Descriptor, }, new pbr::GeneratedCodeInfo(null, null)); diff --git a/src/csharp/Grpc.IntegrationTesting/ServicesGrpc.cs b/src/csharp/Grpc.IntegrationTesting/ServicesGrpc.cs index dd30afb427..996439afbf 100644 --- a/src/csharp/Grpc.IntegrationTesting/ServicesGrpc.cs +++ b/src/csharp/Grpc.IntegrationTesting/ServicesGrpc.cs @@ -114,6 +114,9 @@ namespace Grpc.Testing { static readonly Marshaller<global::Grpc.Testing.ServerStatus> __Marshaller_ServerStatus = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.ServerStatus.Parser.ParseFrom); static readonly Marshaller<global::Grpc.Testing.ClientArgs> __Marshaller_ClientArgs = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.ClientArgs.Parser.ParseFrom); static readonly Marshaller<global::Grpc.Testing.ClientStatus> __Marshaller_ClientStatus = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.ClientStatus.Parser.ParseFrom); + static readonly Marshaller<global::Grpc.Testing.CoreRequest> __Marshaller_CoreRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.CoreRequest.Parser.ParseFrom); + static readonly Marshaller<global::Grpc.Testing.CoreResponse> __Marshaller_CoreResponse = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.CoreResponse.Parser.ParseFrom); + static readonly Marshaller<global::Grpc.Testing.Void> __Marshaller_Void = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.Void.Parser.ParseFrom); static readonly Method<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus> __Method_RunServer = new Method<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus>( MethodType.DuplexStreaming, @@ -129,6 +132,20 @@ namespace Grpc.Testing { __Marshaller_ClientArgs, __Marshaller_ClientStatus); + static readonly Method<global::Grpc.Testing.CoreRequest, global::Grpc.Testing.CoreResponse> __Method_CoreCount = new Method<global::Grpc.Testing.CoreRequest, global::Grpc.Testing.CoreResponse>( + MethodType.Unary, + __ServiceName, + "CoreCount", + __Marshaller_CoreRequest, + __Marshaller_CoreResponse); + + static readonly Method<global::Grpc.Testing.Void, global::Grpc.Testing.Void> __Method_QuitWorker = new Method<global::Grpc.Testing.Void, global::Grpc.Testing.Void>( + MethodType.Unary, + __ServiceName, + "QuitWorker", + __Marshaller_Void, + __Marshaller_Void); + // service descriptor public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor { @@ -142,6 +159,14 @@ namespace Grpc.Testing { AsyncDuplexStreamingCall<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus> RunServer(CallOptions options); AsyncDuplexStreamingCall<global::Grpc.Testing.ClientArgs, global::Grpc.Testing.ClientStatus> RunClient(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); AsyncDuplexStreamingCall<global::Grpc.Testing.ClientArgs, global::Grpc.Testing.ClientStatus> RunClient(CallOptions options); + global::Grpc.Testing.CoreResponse CoreCount(global::Grpc.Testing.CoreRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + global::Grpc.Testing.CoreResponse CoreCount(global::Grpc.Testing.CoreRequest request, CallOptions options); + AsyncUnaryCall<global::Grpc.Testing.CoreResponse> CoreCountAsync(global::Grpc.Testing.CoreRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + AsyncUnaryCall<global::Grpc.Testing.CoreResponse> CoreCountAsync(global::Grpc.Testing.CoreRequest request, CallOptions options); + global::Grpc.Testing.Void QuitWorker(global::Grpc.Testing.Void request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + global::Grpc.Testing.Void QuitWorker(global::Grpc.Testing.Void request, CallOptions options); + AsyncUnaryCall<global::Grpc.Testing.Void> QuitWorkerAsync(global::Grpc.Testing.Void request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + AsyncUnaryCall<global::Grpc.Testing.Void> QuitWorkerAsync(global::Grpc.Testing.Void request, CallOptions options); } // server-side interface @@ -149,6 +174,8 @@ namespace Grpc.Testing { { Task RunServer(IAsyncStreamReader<global::Grpc.Testing.ServerArgs> requestStream, IServerStreamWriter<global::Grpc.Testing.ServerStatus> responseStream, ServerCallContext context); Task RunClient(IAsyncStreamReader<global::Grpc.Testing.ClientArgs> requestStream, IServerStreamWriter<global::Grpc.Testing.ClientStatus> responseStream, ServerCallContext context); + Task<global::Grpc.Testing.CoreResponse> CoreCount(global::Grpc.Testing.CoreRequest request, ServerCallContext context); + Task<global::Grpc.Testing.Void> QuitWorker(global::Grpc.Testing.Void request, ServerCallContext context); } // client stub @@ -177,6 +204,46 @@ namespace Grpc.Testing { var call = CreateCall(__Method_RunClient, options); return Calls.AsyncDuplexStreamingCall(call); } + public global::Grpc.Testing.CoreResponse CoreCount(global::Grpc.Testing.CoreRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) + { + var call = CreateCall(__Method_CoreCount, new CallOptions(headers, deadline, cancellationToken)); + return Calls.BlockingUnaryCall(call, request); + } + public global::Grpc.Testing.CoreResponse CoreCount(global::Grpc.Testing.CoreRequest request, CallOptions options) + { + var call = CreateCall(__Method_CoreCount, options); + return Calls.BlockingUnaryCall(call, request); + } + public AsyncUnaryCall<global::Grpc.Testing.CoreResponse> CoreCountAsync(global::Grpc.Testing.CoreRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) + { + var call = CreateCall(__Method_CoreCount, new CallOptions(headers, deadline, cancellationToken)); + return Calls.AsyncUnaryCall(call, request); + } + public AsyncUnaryCall<global::Grpc.Testing.CoreResponse> CoreCountAsync(global::Grpc.Testing.CoreRequest request, CallOptions options) + { + var call = CreateCall(__Method_CoreCount, options); + return Calls.AsyncUnaryCall(call, request); + } + public global::Grpc.Testing.Void QuitWorker(global::Grpc.Testing.Void request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) + { + var call = CreateCall(__Method_QuitWorker, new CallOptions(headers, deadline, cancellationToken)); + return Calls.BlockingUnaryCall(call, request); + } + public global::Grpc.Testing.Void QuitWorker(global::Grpc.Testing.Void request, CallOptions options) + { + var call = CreateCall(__Method_QuitWorker, options); + return Calls.BlockingUnaryCall(call, request); + } + public AsyncUnaryCall<global::Grpc.Testing.Void> QuitWorkerAsync(global::Grpc.Testing.Void request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) + { + var call = CreateCall(__Method_QuitWorker, new CallOptions(headers, deadline, cancellationToken)); + return Calls.AsyncUnaryCall(call, request); + } + public AsyncUnaryCall<global::Grpc.Testing.Void> QuitWorkerAsync(global::Grpc.Testing.Void request, CallOptions options) + { + var call = CreateCall(__Method_QuitWorker, options); + return Calls.AsyncUnaryCall(call, request); + } } // creates service definition that can be registered with a server @@ -184,7 +251,9 @@ namespace Grpc.Testing { { return ServerServiceDefinition.CreateBuilder(__ServiceName) .AddMethod(__Method_RunServer, serviceImpl.RunServer) - .AddMethod(__Method_RunClient, serviceImpl.RunClient).Build(); + .AddMethod(__Method_RunClient, serviceImpl.RunClient) + .AddMethod(__Method_CoreCount, serviceImpl.CoreCount) + .AddMethod(__Method_QuitWorker, serviceImpl.QuitWorker).Build(); } // creates a new client diff --git a/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs b/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs index bb2918bf46..cab299a137 100644 --- a/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs +++ b/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -47,9 +47,16 @@ namespace Grpc.Testing /// </summary> public class WorkerServiceImpl : WorkerService.IWorkerService { + readonly Action stopRequestHandler; + + public WorkerServiceImpl(Action stopRequestHandler) + { + this.stopRequestHandler = GrpcPreconditions.CheckNotNull(stopRequestHandler); + } + public async Task RunServer(IAsyncStreamReader<ServerArgs> requestStream, IServerStreamWriter<ServerStatus> responseStream, ServerCallContext context) { - Grpc.Core.Utils.Preconditions.CheckState(await requestStream.MoveNext()); + GrpcPreconditions.CheckState(await requestStream.MoveNext()); var serverConfig = requestStream.Current.Setup; var runner = ServerRunners.CreateStarted(serverConfig); @@ -73,7 +80,7 @@ namespace Grpc.Testing public async Task RunClient(IAsyncStreamReader<ClientArgs> requestStream, IServerStreamWriter<ClientStatus> responseStream, ServerCallContext context) { - Grpc.Core.Utils.Preconditions.CheckState(await requestStream.MoveNext()); + GrpcPreconditions.CheckState(await requestStream.MoveNext()); var clientConfig = requestStream.Current.Setup; var runner = ClientRunners.CreateStarted(clientConfig); @@ -92,5 +99,16 @@ namespace Grpc.Testing } await runner.StopAsync(); } + + public Task<CoreResponse> CoreCount(CoreRequest request, ServerCallContext context) + { + return Task.FromResult(new CoreResponse { Cores = Environment.ProcessorCount }); + } + + public Task<Void> QuitWorker(Void request, ServerCallContext context) + { + stopRequestHandler(); + return Task.FromResult(new Void()); + } } } diff --git a/src/csharp/README.md b/src/csharp/README.md index 65ae0b5efd..b4fa945ac9 100644 --- a/src/csharp/README.md +++ b/src/csharp/README.md @@ -12,9 +12,9 @@ Beta PREREQUISITES -------------- -- Windows: .NET Framework 4.5+, Visual Studio 2013 or 2015. -- Linux: Mono 3.2.8+, MonoDevelop 5.9 with NuGet add-in installed. -- Mac OS X: [homebrew][], Xamarin Studio with NuGet add-in installed. +- Windows: .NET Framework 4.5+, Visual Studio 2013 or 2015 +- Linux: Mono 4+, MonoDevelop 5.9+ (with NuGet add-in installed) +- Mac OS X: Xamarin Studio 5.9+ HOW TO USE -------------- @@ -24,66 +24,28 @@ HOW TO USE - Open Visual Studio and start a new project/solution. - Add NuGet package `Grpc` as a dependency (Project options -> Manage NuGet Packages). - That will also pull all the transitive dependencies (including the native libraries that + That will also pull all the transitive dependencies (including the gRPC native library that gRPC C# is using internally). **Linux (Debian)** -- Add [Debian jessie-backports][] to your `sources.list` file. Example: - - ```sh - echo "deb http://http.debian.net/debian jessie-backports main" | \ - sudo tee -a /etc/apt/sources.list - ``` - -- Install the gRPC Debian package - - ```sh - sudo apt-get update - sudo apt-get install libgrpc0 - ``` - -- gRPC C# depends on native shared library `libgrpc_csharp_ext.so` (Unix flavor of grpc_csharp_ext.dll). - This library is not part of the base gRPC debian package and needs to be installed manually from - a `.deb` file. Download the debian package `libgrpc_csharp_ext` from corresponding gRPC release on GitHub - and install it using `dpkg`. - - ```sh - # choose version corresponding to the version of libgrpc you've installed. - wget https://github.com/grpc/grpc/releases/download/release-0_11_0/libgrpc-csharp-ext0_0.11.0.0-1_amd64.deb - dpkg -i libgrpc-csharp-ext0_0.11.0.0-1_amd64.deb - ``` - - Open MonoDevelop and start a new project/solution. - Add NuGet package `Grpc` as a dependency (Project -> Add NuGet packages). + That will also pull all the transitive dependencies (including the gRPC native library that + gRPC C# is using internally). -- NOTE: Currently, there are no debian packages for the latest version Protocol Buffers compiler (_protoc_) - and the gRPC _protoc_ plugin. You can install them using [gRPC Linuxbrew instructions][]. +- NOTE: gRPC C# doesn't have a good story yet for shipping precompiled Linux version of Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin. You can install them using [gRPC Linuxbrew instructions][]. **Mac OS X** -- WARNING: As of now gRPC C# only works on 64bit version of Mono (because we don't compile - the native extension for C# in 32bit mode yet). That means your development experience - with Xamarin Studio on MacOS will not be great, as you won't be able to run your - code directly from Xamarin Studio (which requires 32bit version of Mono). - -- Install [homebrew][]. Run the following command to install gRPC C# native dependencies. - - ```sh - $ curl -fsSL https://goo.gl/getgrpc | bash - - ``` - This will download and run the [gRPC install script][], then install the latest version of gRPC C core and native C# extension. - It also installs Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin for C#. - -- Install 64-bit version of mono with command `brew install mono`. - - Open Xamarin Studio and start a new project/solution. - Add NuGet package `Grpc` as a dependency (Project -> Add NuGet packages). + That will also pull all the transitive dependencies (including the gRPC native library that + gRPC C# is using internally). -- *You will be able to build your project in Xamarin Studio, but to run or test it, - you will need to run it under 64-bit version of Mono.* +- NOTE: gRPC C# doesn't have a good story yet for shipping precompiled Mac OS X version of Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin. You can install them using [gRPC Homebrew instructions][]. BUILD FROM SOURCE ----------------- @@ -94,7 +56,7 @@ If you are a user of gRPC C#, go to Usage section above. **Windows** - The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution. You can - either build the native solution in `vsprojects/grpc.sln` from Visual Studio manually, or you can use + either build the native solution in `vsprojects/grpc_csharp_ext.sln` from Visual Studio manually, or you can use a convenience batch script that builds everything for you. ``` @@ -102,30 +64,28 @@ If you are a user of gRPC C#, go to Usage section above. > buildall.bat ``` -- Open Grpc.sln using Visual Studio. NuGet dependencies will be restored - upon build (you need to have NuGet add-in installed). +- Open Grpc.sln using Visual Studio. **Linux** +- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution: ```sh - $ sudo apt-get install mono-devel - $ sudo apt-get install nunit nunit-console + # from the gRPC repository root + $ make CONFIG=dbg grpc_csharp_ext ``` -You can use older versions of MonoDevelop, but then you might need to restore -NuGet dependencies manually (by `nuget restore`), because older versions of MonoDevelop -don't support NuGet add-in. +- Use MonoDevelop to open the solution Grpc.sln + +**Mac OS X** -- Compile and install the gRPC C# extension library (that will be used via - P/Invoke from C#). +- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution. + ```sh - $ make grpc_csharp_ext - $ sudo make install_grpc_csharp_ext + # from the gRPC repository root + $ tools/run_tests/run_tests.py -c dbg -l csharp --build_only ``` -- Use MonoDevelop to open the solution Grpc.sln - -- Build the solution & run all the tests from test view. +- Use Xamarin Studio to open the solution Grpc.sln RUNNING TESTS ------------- @@ -135,17 +95,9 @@ gRPC C# is using NUnit as the testing framework. Under Visual Studio, make sure NUnit test adapter is installed (under "Extensions and Updates"). Then you should be able to run all the tests using Test Explorer. -Under Monodevelop, make sure you installed "NUnit support" in Add-in manager. +Under Monodevelop or Xamarin Studio, make sure you installed "NUnit support" in Add-in manager. Then you should be able to run all the test from the Test View. -After building the solution, you can also run the tests from command line -using nunit-console tool. - -```sh -# from Grpc.Core.Test/bin/Debug directory -$ nunit-console Grpc.Core.Tests.dll -``` - gRPC team uses a Python script to simplify facilitate running tests for different languages. @@ -176,27 +128,15 @@ CONTENTS - Grpc.IntegrationTesting: Cross-language gRPC implementation testing (interop testing). -TROUBLESHOOTING +THE NATIVE DEPENDENCY --------------- -### Problem: Unable to load DLL 'grpc_csharp_ext.dll' - -Internally, gRPC C# uses a native library written in C (gRPC C core) and invokes its functionality via P/Invoke. `grpc_csharp_ext` library is a native extension library that facilitates this by wrapping some C core API into a form that's more digestible for P/Invoke. If you get the above error, it means that the native dependencies could not be located by the C# runtime (or they are incompatible with the current runtime, so they could not be loaded). The solution to this is environment specific. - -- If you are developing on Windows in Visual Studio, the `grpc_csharp_ext.dll` that is shipped by gRPC nuget packages should be automatically copied to your build destination folder once you build. By adjusting project properties in your VS project file, you can influence which exact configuration of `grpc_csharp_ext.dll` will be used (based on VS version, bitness, debug/release configuration). - -- If you are running your application that is using gRPC on Windows machine that doesn't have Visual Studio installed, you might need to install [Visual C++ 2013 redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=40784) that contains some system .dll libraries that `grpc_csharp_ext.dll` depends on (see #905 for more details). - -- On Linux (or Docker), you need to first install gRPC C core and `libgrpc_csharp_ext.so` shared libraries. - See [How to Use](#how-to-use) section for details how to install it. - Installation on a machine where your application is going to be deployed is no different. - -- On Mac, you need to first install gRPC C core and `libgrpc_csharp_ext.dylib` shared libraries using Homebrew. See above for installation instruction. - Installation on a machine where your application is going to be deployed is no different. +Internally, gRPC C# uses a native library written in C (gRPC C core) and invokes its functionality via P/Invoke. `grpc_csharp_ext` library is a native extension library that facilitates this by wrapping some C core API into a form that's more digestible for P/Invoke. -- Possible cause for the problem is that the `grpc_csharp_ext` library is installed, but it has different bitness (32/64bit) than your C# runtime (in case you are using mono) or C# application. +Prior to version 0.13, installing `grpc_csharp_ext` was required to make gRPC work on Linux and MacOS. Starting with version 0.13, we have improved the packaging story significantly and precompiled versions of the native library for all supported platforms are now shipped with the NuGet package. Just installing the `Grpc` NuGet package should be the only step needed to use gRPC C#, regardless of your platform (Windows, Linux or Mac) and the bitness (32 or 64bit). [gRPC Linuxbrew instructions]:https://github.com/grpc/homebrew-grpc#quick-install-linux +[gRPC Homebrew instructions]:https://github.com/grpc/homebrew-grpc#quick-install-linux [homebrew]:http://brew.sh [gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install [grpc.io]: http://www.grpc.io/docs/installation/csharp.html diff --git a/src/csharp/build_packages.bat b/src/csharp/build_packages.bat index e423545ef8..b7768f7821 100644 --- a/src/csharp/build_packages.bat +++ b/src/csharp/build_packages.bat @@ -1,7 +1,7 @@ @rem Builds gRPC NuGet packages @rem Current package versions -set VERSION=0.13.0 +set VERSION=0.14.0-dev set PROTOBUF_VERSION=3.0.0-beta2 @rem Packages that depend on prerelease packages (like Google.Protobuf) need to have prerelease suffix as well. |