Skip to content
Snippets Groups Projects
Commit 075dde42 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

code style fixes based on StyleCop warnings

parent 053d894e
No related branches found
No related tags found
No related merge requests found
Showing
with 58 additions and 73 deletions
...@@ -122,10 +122,13 @@ namespace Grpc.Core.Tests ...@@ -122,10 +122,13 @@ namespace Grpc.Core.Tests
{ {
var call = new Call<string, string>(unaryEchoStringMethod, channel); var call = new Call<string, string>(unaryEchoStringMethod, channel);
try { try
{
Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)); Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken));
Assert.Fail(); Assert.Fail();
} catch(RpcException e) { }
catch (RpcException e)
{
Assert.AreEqual(StatusCode.Unimplemented, e.Status.StatusCode); Assert.AreEqual(StatusCode.Unimplemented, e.Status.StatusCode);
} }
} }
...@@ -140,4 +143,3 @@ namespace Grpc.Core.Tests ...@@ -140,4 +143,3 @@ namespace Grpc.Core.Tests
} }
} }
} }
...@@ -68,7 +68,7 @@ namespace Grpc.Core.Tests ...@@ -68,7 +68,7 @@ namespace Grpc.Core.Tests
var tp2 = GrpcEnvironment.ThreadPool; var tp2 = GrpcEnvironment.ThreadPool;
GrpcEnvironment.Shutdown(); GrpcEnvironment.Shutdown();
Assert.IsFalse(Object.ReferenceEquals(tp1, tp2)); Assert.IsFalse(object.ReferenceEquals(tp1, tp2));
} }
} }
} }
...@@ -33,13 +33,13 @@ ...@@ -33,13 +33,13 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Grpc.Core; using Grpc.Core;
using Grpc.Core.Internal; using Grpc.Core.Internal;
using Grpc.Core.Utils; using Grpc.Core.Utils;
using NUnit.Framework; using NUnit.Framework;
using System.Runtime.InteropServices;
namespace Grpc.Core.Tests namespace Grpc.Core.Tests
{ {
...@@ -73,14 +73,13 @@ namespace Grpc.Core.Tests ...@@ -73,14 +73,13 @@ namespace Grpc.Core.Tests
{ {
BenchmarkUtil.RunBenchmark( BenchmarkUtil.RunBenchmark(
100000, 1000000, 100000, 1000000,
() => { () =>
{
CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create(); CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create();
cq.Dispose(); cq.Dispose();
} });
);
} }
/// <summary> /// <summary>
/// Approximate results: /// Approximate results:
/// (~80ns Mono Linux) /// (~80ns Mono Linux)
...@@ -94,10 +93,10 @@ namespace Grpc.Core.Tests ...@@ -94,10 +93,10 @@ namespace Grpc.Core.Tests
counter = 0; counter = 0;
BenchmarkUtil.RunBenchmark( BenchmarkUtil.RunBenchmark(
1000000, 10000000, 1000000, 10000000,
() => { () =>
{
grpcsharp_test_callback(handler); grpcsharp_test_callback(handler);
} });
);
Assert.AreNotEqual(0, counter); Assert.AreNotEqual(0, counter);
} }
...@@ -113,10 +112,10 @@ namespace Grpc.Core.Tests ...@@ -113,10 +112,10 @@ namespace Grpc.Core.Tests
counter = 0; counter = 0;
BenchmarkUtil.RunBenchmark( BenchmarkUtil.RunBenchmark(
10000, 10000, 10000, 10000,
() => { () =>
{
grpcsharp_test_callback(new CompletionCallbackDelegate(Handler)); grpcsharp_test_callback(new CompletionCallbackDelegate(Handler));
} });
);
Assert.AreNotEqual(0, counter); Assert.AreNotEqual(0, counter);
} }
...@@ -129,15 +128,15 @@ namespace Grpc.Core.Tests ...@@ -129,15 +128,15 @@ namespace Grpc.Core.Tests
{ {
BenchmarkUtil.RunBenchmark( BenchmarkUtil.RunBenchmark(
1000000, 100000000, 1000000, 100000000,
() => { () =>
{
grpcsharp_test_nop(IntPtr.Zero); grpcsharp_test_nop(IntPtr.Zero);
} });
);
} }
private void Handler(GRPCOpError op, IntPtr ptr) { private void Handler(GRPCOpError op, IntPtr ptr)
{
counter++; counter++;
} }
} }
} }
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Grpc.Core.Tests")] [assembly: AssemblyTitle("Grpc.Core.Tests")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
...@@ -11,12 +9,4 @@ using System.Runtime.CompilerServices; ...@@ -11,12 +9,4 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")] [assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("0.1.*")] [assembly: AssemblyVersion("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
...@@ -53,6 +53,5 @@ namespace Grpc.Core.Tests ...@@ -53,6 +53,5 @@ namespace Grpc.Core.Tests
GrpcEnvironment.Shutdown(); GrpcEnvironment.Shutdown();
} }
} }
} }
...@@ -86,4 +86,3 @@ namespace Grpc.Core.Internal.Tests ...@@ -86,4 +86,3 @@ namespace Grpc.Core.Internal.Tests
} }
} }
} }
...@@ -47,7 +47,8 @@ namespace Grpc.Core ...@@ -47,7 +47,8 @@ namespace Grpc.Core
Func<TRequest, byte[]> requestSerializer, Func<TRequest, byte[]> requestSerializer,
Func<byte[], TResponse> responseDeserializer, Func<byte[], TResponse> responseDeserializer,
TimeSpan timeout, TimeSpan timeout,
Channel channel) { Channel channel)
{
this.methodName = methodName; this.methodName = methodName;
this.requestSerializer = requestSerializer; this.requestSerializer = requestSerializer;
this.responseDeserializer = responseDeserializer; this.responseDeserializer = responseDeserializer;
...@@ -95,4 +96,3 @@ namespace Grpc.Core ...@@ -95,4 +96,3 @@ namespace Grpc.Core
} }
} }
} }
...@@ -89,9 +89,9 @@ namespace Grpc.Core ...@@ -89,9 +89,9 @@ namespace Grpc.Core
return new ClientStreamingInputObserver<TRequest, TResponse>(asyncCall); return new ClientStreamingInputObserver<TRequest, TResponse>(asyncCall);
} }
private static CompletionQueueSafeHandle GetCompletionQueue() { private static CompletionQueueSafeHandle GetCompletionQueue()
{
return GrpcEnvironment.ThreadPool.CompletionQueue; return GrpcEnvironment.ThreadPool.CompletionQueue;
} }
} }
} }
...@@ -39,7 +39,7 @@ namespace Grpc.Core ...@@ -39,7 +39,7 @@ namespace Grpc.Core
public class Channel : IDisposable public class Channel : IDisposable
{ {
readonly ChannelSafeHandle handle; readonly ChannelSafeHandle handle;
readonly String target; readonly string target;
/// <summary> /// <summary>
/// Creates a channel. /// Creates a channel.
......
...@@ -67,4 +67,3 @@ namespace Grpc.Core ...@@ -67,4 +67,3 @@ namespace Grpc.Core
} }
} }
} }
...@@ -74,4 +74,3 @@ namespace Grpc.Core ...@@ -74,4 +74,3 @@ namespace Grpc.Core
} }
} }
} }
...@@ -63,7 +63,8 @@ namespace Grpc.Core ...@@ -63,7 +63,8 @@ namespace Grpc.Core
/// lifetime (and call Shutdown once you're done), for the sake of easier testing it's /// lifetime (and call Shutdown once you're done), for the sake of easier testing it's
/// allowed to initialize the environment again after it has been successfully shutdown. /// allowed to initialize the environment again after it has been successfully shutdown.
/// </summary> /// </summary>
public static void Initialize() { public static void Initialize()
{
lock (staticLock) lock (staticLock)
{ {
if (instance == null) if (instance == null)
...@@ -133,4 +134,3 @@ namespace Grpc.Core ...@@ -133,4 +134,3 @@ namespace Grpc.Core
} }
} }
} }
...@@ -54,7 +54,7 @@ namespace Grpc.Core.Internal ...@@ -54,7 +54,7 @@ namespace Grpc.Core.Internal
TaskCompletionSource<TResponse> unaryResponseTcs; TaskCompletionSource<TResponse> unaryResponseTcs;
// Set after status is received. Only used for streaming response calls. // Set after status is received. Only used for streaming response calls.
Nullable<Status> finishedStatus; Status? finishedStatus;
bool readObserverCompleted; // True if readObserver has already been completed. bool readObserverCompleted; // True if readObserver has already been completed.
...@@ -64,7 +64,7 @@ namespace Grpc.Core.Internal ...@@ -64,7 +64,7 @@ namespace Grpc.Core.Internal
this.finishedHandler = CreateBatchCompletionCallback(HandleFinished); this.finishedHandler = CreateBatchCompletionCallback(HandleFinished);
} }
public void Initialize(Channel channel, CompletionQueueSafeHandle cq, String methodName) public void Initialize(Channel channel, CompletionQueueSafeHandle cq, string methodName)
{ {
var call = CallSafeHandle.Create(channel.Handle, cq, methodName, channel.Target, Timespec.InfFuture); var call = CallSafeHandle.Create(channel.Handle, cq, methodName, channel.Target, Timespec.InfFuture);
InitializeInternal(call); InitializeInternal(call);
...@@ -77,7 +77,7 @@ namespace Grpc.Core.Internal ...@@ -77,7 +77,7 @@ namespace Grpc.Core.Internal
/// <summary> /// <summary>
/// Blocking unary request - unary response call. /// Blocking unary request - unary response call.
/// </summary> /// </summary>
public TResponse UnaryCall(Channel channel, String methodName, TRequest msg) public TResponse UnaryCall(Channel channel, string methodName, TRequest msg)
{ {
using (CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create()) using (CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create())
{ {
...@@ -264,9 +264,7 @@ namespace Grpc.Core.Internal ...@@ -264,9 +264,7 @@ namespace Grpc.Core.Internal
if (wasError) if (wasError)
{ {
unaryResponseTcs.SetException(new RpcException( unaryResponseTcs.SetException(new RpcException(new Status(StatusCode.Internal, "Internal error occured.")));
new Status(StatusCode.Internal, "Internal error occured.")
));
return; return;
} }
......
...@@ -302,7 +302,8 @@ namespace Grpc.Core.Internal ...@@ -302,7 +302,8 @@ namespace Grpc.Core.Internal
/// </summary> /// </summary>
protected CompletionCallbackDelegate CreateBatchCompletionCallback(Action<bool, BatchContextSafeHandleNotOwned> handler) protected CompletionCallbackDelegate CreateBatchCompletionCallback(Action<bool, BatchContextSafeHandleNotOwned> handler)
{ {
return new CompletionCallbackDelegate( (error, batchContextPtr) => { return new CompletionCallbackDelegate((error, batchContextPtr) =>
{
try try
{ {
var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr); var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);
...@@ -363,7 +364,6 @@ namespace Grpc.Core.Internal ...@@ -363,7 +364,6 @@ namespace Grpc.Core.Internal
{ {
FireCompletion(origCompletionDelegate, null); FireCompletion(origCompletionDelegate, null);
} }
} }
/// <summary> /// <summary>
......
...@@ -91,5 +91,4 @@ namespace Grpc.Core.Internal ...@@ -91,5 +91,4 @@ namespace Grpc.Core.Internal
tcs.SetException(error); tcs.SetException(error);
} }
} }
} }
\ No newline at end of file
...@@ -85,11 +85,13 @@ namespace Grpc.Core.Internal ...@@ -85,11 +85,13 @@ namespace Grpc.Core.Internal
return data; return data;
} }
public CallSafeHandle GetServerRpcNewCall() { public CallSafeHandle GetServerRpcNewCall()
{
return grpcsharp_batch_context_server_rpc_new_call(this); return grpcsharp_batch_context_server_rpc_new_call(this);
} }
public string GetServerRpcNewMethod() { public string GetServerRpcNewMethod()
{
return Marshal.PtrToStringAnsi(grpcsharp_batch_context_server_rpc_new_method(this)); return Marshal.PtrToStringAnsi(grpcsharp_batch_context_server_rpc_new_method(this));
} }
} }
......
...@@ -37,12 +37,13 @@ using Grpc.Core; ...@@ -37,12 +37,13 @@ using Grpc.Core;
namespace Grpc.Core.Internal namespace Grpc.Core.Internal
{ {
internal delegate void CompletionCallbackDelegate(GRPCOpError error, IntPtr batchContextPtr); internal delegate void CompletionCallbackDelegate(GRPCOpError error, IntPtr batchContextPtr);
/// <summary> /// <summary>
/// grpc_call from <grpc/grpc.h> /// grpc_call from <grpc/grpc.h>
/// </summary> /// </summary>
internal class CallSafeHandle : SafeHandleZeroIsInvalid internal class CallSafeHandle : SafeHandleZeroIsInvalid
{ {
const UInt32 GRPC_WRITE_BUFFER_HINT = 1; const uint GRPC_WRITE_BUFFER_HINT = 1;
[DllImport("grpc_csharp_ext.dll")] [DllImport("grpc_csharp_ext.dll")]
static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline); static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline);
...@@ -179,7 +180,7 @@ namespace Grpc.Core.Internal ...@@ -179,7 +180,7 @@ namespace Grpc.Core.Internal
Trace.Assert(callError == GRPCCallError.GRPC_CALL_OK, "Status not GRPC_CALL_OK"); Trace.Assert(callError == GRPCCallError.GRPC_CALL_OK, "Status not GRPC_CALL_OK");
} }
private static UInt32 GetFlags(bool buffered) private static uint GetFlags(bool buffered)
{ {
return buffered ? 0 : GRPC_WRITE_BUFFER_HINT; return buffered ? 0 : GRPC_WRITE_BUFFER_HINT;
} }
......
...@@ -74,4 +74,3 @@ namespace Grpc.Core.Internal ...@@ -74,4 +74,3 @@ namespace Grpc.Core.Internal
} }
} }
} }
...@@ -77,4 +77,3 @@ namespace Grpc.Core.Internal ...@@ -77,4 +77,3 @@ namespace Grpc.Core.Internal
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment