internal static bool SpannerExceptionsEqualForRetry(SpannerException e1, SpannerException e2)
 {
     // Quick return for the most common case.
     if (e1 == null && e2 == null)
     {
         return(true);
     }
     if (!Equals(e1?.ErrorCode, e2?.ErrorCode))
     {
         return(false);
     }
     if (!Equals(e1?.Message, e2?.Message))
     {
         return(false);
     }
     if (!Equals(e1?.InnerException?.GetType(), e2?.InnerException?.GetType()))
     {
         return(false);
     }
     if (e1?.InnerException is RpcException)
     {
         Status status1 = ((RpcException)e1.InnerException).Status;
         Status status2 = ((RpcException)e2.InnerException).Status;
         if (!(Equals(status1.StatusCode, status2.StatusCode) && Equals(status1.Detail, status2.Detail)))
         {
             return(false);
         }
     }
     return(true);
 }
        // Gets data of recv_status_on_client completion.
        public ClientSideStatus GetReceivedStatusOnClient()
        {
            string details = Marshal.PtrToStringAnsi(Native.grpcsharp_batch_context_recv_status_on_client_details(this));
            var status = new Status(Native.grpcsharp_batch_context_recv_status_on_client_status(this), details);

            IntPtr metadataArrayPtr = Native.grpcsharp_batch_context_recv_status_on_client_trailing_metadata(this);
            var metadata = MetadataArraySafeHandle.ReadMetadataFromPtrUnsafe(metadataArrayPtr);

            return new ClientSideStatus(status, metadata);
        }
Beispiel #3
0
        public async Task GetBulkSecretAsync_WrapsRpcException()
        {
            var client = new MockClient();

            var rpcStatus    = new Grpc.Core.Status(StatusCode.Internal, "not gonna work");
            var rpcException = new RpcException(rpcStatus, new Metadata(), "not gonna work");

            // Setup the mock client to throw an Rpc Exception with the expected details info
            client.Mock
            .Setup(m => m.GetBulkSecretAsync(It.IsAny <Autogen.Grpc.v1.GetBulkSecretRequest>(), It.IsAny <CallOptions>()))
            .Throws(rpcException);

            var ex = await Assert.ThrowsAsync <DaprException>(async() =>
            {
                await client.DaprClient.GetBulkSecretAsync("test");
            });

            Assert.Same(rpcException, ex.InnerException);
        }
Beispiel #4
0
        private static RpcException BuildRpcException(TimeSpan?exceptionRetryDelay, StatusCode exceptionStatus, string exceptionMessage)
        {
            var status = new Status(exceptionStatus, exceptionMessage);

            if (!exceptionRetryDelay.HasValue)
            {
                return(new RpcException(status));
            }
            RetryInfo retry = new RetryInfo
            {
                RetryDelay = Duration.FromTimeSpan(exceptionRetryDelay.Value)
            };
            Metadata trailers = new Metadata
            {
                { s_retryInfoMetadataKey, retry.ToByteArray() }
            };

            return(new RpcException(status, trailers));
        }
        public MockServiceHelper(string host = null, Marshaller<string> marshaller = null, IEnumerable<ChannelOption> channelOptions = null)
        {
            this.host = host ?? "localhost";
            this.channelOptions = channelOptions;
            marshaller = marshaller ?? Marshallers.StringMarshaller;

            unaryMethod = new Method<string, string>(
                MethodType.Unary,
                ServiceName,
                "Unary",
                marshaller,
                marshaller);

            clientStreamingMethod = new Method<string, string>(
                MethodType.ClientStreaming,
                ServiceName,
                "ClientStreaming",
                marshaller,
                marshaller);

            serverStreamingMethod = new Method<string, string>(
                MethodType.ServerStreaming,
                ServiceName,
                "ServerStreaming",
                marshaller,
                marshaller);

            duplexStreamingMethod = new Method<string, string>(
                MethodType.DuplexStreaming,
                ServiceName,
                "DuplexStreaming",
                marshaller,
                marshaller);

            serviceDefinition = ServerServiceDefinition.CreateBuilder()
                .AddMethod(unaryMethod, (request, context) => unaryHandler(request, context))
                .AddMethod(clientStreamingMethod, (requestStream, context) => clientStreamingHandler(requestStream, context))
                .AddMethod(serverStreamingMethod, (request, responseStream, context) => serverStreamingHandler(request, responseStream, context))
                .AddMethod(duplexStreamingMethod, (requestStream, responseStream, context) => duplexStreamingHandler(requestStream, responseStream, context))
                .Build();

            var defaultStatus = new Status(StatusCode.Unknown, "Default mock implementation. Please provide your own.");

            unaryHandler = new UnaryServerMethod<string, string>(async (request, context) =>
            {
                context.Status = defaultStatus;
                return "";
            });

            clientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) =>
            {
                context.Status = defaultStatus;
                return "";
            });

            serverStreamingHandler = new ServerStreamingServerMethod<string, string>(async (request, responseStream, context) =>
            {
                context.Status = defaultStatus;
            });

            duplexStreamingHandler = new DuplexStreamingServerMethod<string, string>(async (requestStream, responseStream, context) =>
            {
                context.Status = defaultStatus;
            });
        }
 public ClientSideStatus(Status status, Metadata trailers)
 {
     this.status = status;
     this.trailers = trailers;
 }
        public MockServiceHelper(string host = null)
        {
            this.host = host ?? "localhost";

            serviceDefinition = ServerServiceDefinition.CreateBuilder(ServiceName)
                .AddMethod(UnaryMethod, (request, context) => unaryHandler(request, context))
                .AddMethod(ClientStreamingMethod, (requestStream, context) => clientStreamingHandler(requestStream, context))
                .AddMethod(ServerStreamingMethod, (request, responseStream, context) => serverStreamingHandler(request, responseStream, context))
                .AddMethod(DuplexStreamingMethod, (requestStream, responseStream, context) => duplexStreamingHandler(requestStream, responseStream, context))
                .Build();

            var defaultStatus = new Status(StatusCode.Unknown, "Default mock implementation. Please provide your own.");

            unaryHandler = new UnaryServerMethod<string, string>(async (request, context) =>
            {
                context.Status = defaultStatus;
                return "";
            });

            clientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) =>
            {
                context.Status = defaultStatus;
                return "";
            });

            serverStreamingHandler = new ServerStreamingServerMethod<string, string>(async (request, responseStream, context) =>
            {
                context.Status = defaultStatus;
            });

            duplexStreamingHandler = new DuplexStreamingServerMethod<string, string>(async (requestStream, responseStream, context) =>
            {
                context.Status = defaultStatus;
            });
        }
Beispiel #8
0
 public RpcException(Status status, string message)
     : base(message)
 {
     this.status = status;
 }
Beispiel #9
0
 public void StartSendStatusFromServer(Status status, BatchCompletionDelegate callback)
 {
     var ctx = BatchContextSafeHandle.Create();
     GrpcEnvironment.CompletionRegistry.RegisterBatchCompletion(ctx, callback);
     grpcsharp_call_send_status_from_server(this, ctx, status.StatusCode, status.Detail).CheckOk();
 }
Beispiel #10
0
 public void StartSendStatusFromServer(BatchCompletionDelegate callback, Status status, MetadataArraySafeHandle metadataArray, bool sendEmptyInitialMetadata)
 {
     var ctx = BatchContextSafeHandle.Create();
     completionRegistry.RegisterBatchCompletion(ctx, callback);
     grpcsharp_call_send_status_from_server(this, ctx, status.StatusCode, status.Detail, metadataArray, sendEmptyInitialMetadata).CheckOk();
 }
Beispiel #11
0
 public void StartSendStatusFromServer(SendCompletionHandler callback, Status status, MetadataArraySafeHandle metadataArray, bool sendEmptyInitialMetadata)
 {
     using (completionQueue.NewScope())
     {
         var ctx = BatchContextSafeHandle.Create();
         completionRegistry.RegisterBatchCompletion(ctx, (success, context) => callback(success));
         grpcsharp_call_send_status_from_server(this, ctx, status.StatusCode, status.Detail, metadataArray, sendEmptyInitialMetadata).CheckOk();
     }
 }
 /// <summary>
 /// Creates a new <c>RpcException</c> associated with given status.
 /// </summary>
 /// <param name="status">Resulting status of a call.</param>
 public RpcException(Status status) : base(status.ToString())
 {
     this.status = status;
 }
Beispiel #13
0
 public void CancelWithStatus(Status status)
 {
     AssertCallOk(grpcsharp_call_cancel_with_status(this, status.StatusCode, status.Detail));
 }
Beispiel #14
0
 public void StartSendStatusFromServer(Status status, CompletionCallbackDelegate callback)
 {
     AssertCallOk(grpcsharp_call_send_status_from_server(this, callback, status.StatusCode, status.Detail));
 }
 public void StartSendStatusFromServer(SendCompletionHandler callback, Status status, MetadataArraySafeHandle metadataArray, bool sendEmptyInitialMetadata,
     byte[] optionalPayload, WriteFlags writeFlags)
 {
     using (completionQueue.NewScope())
     {
         var ctx = BatchContextSafeHandle.Create();
         var optionalPayloadLength = optionalPayload != null ? new UIntPtr((ulong)optionalPayload.Length) : UIntPtr.Zero;
         completionQueue.CompletionRegistry.RegisterBatchCompletion(ctx, (success, context) => callback(success));
         Native.grpcsharp_call_send_status_from_server(this, ctx, status.StatusCode, status.Detail, metadataArray, sendEmptyInitialMetadata,
             optionalPayload, optionalPayloadLength, writeFlags).CheckOk();
     }
 }
 public void CancelWithStatus(Status status)
 {
     Native.grpcsharp_call_cancel_with_status(this, status.StatusCode, status.Detail).CheckOk();
 }
Beispiel #17
0
 public RpcException(Status status)
 {
     this.status = status;
 }