/// <summary> /// Handles the logging of asynchronous unary calls. /// </summary> /// <typeparam name="TRequest">The type of the request.</typeparam> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The request.</param> /// <param name="context">The context.</param> /// <param name="oldTask">The old task.</param> /// <param name="call">The call.</param> internal void HandleAsyncUnaryLogging <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, Task <TResponse> oldTask, AsyncUnaryCall <TResponse> call) where TRequest : class where TResponse : class { // Generating log entry is expensive, so let's do that only if the log source // has been configured to do so. if (TraceUtilities.ShouldGenerateRequestLogs()) { LogEntry logEntry = new LogEntry() { Host = config.ServerUrl, Method = context.Method.FullName, RequestHeaders = context.Options.Headers, Request = request, ResponseHeaders = Merge(GetResponseHeader(call.ResponseHeadersAsync), call.GetTrailers()), Response = (oldTask.IsFaulted) ? default : oldTask.Result, Exception = UnaryRpcInterceptor.ParseTaskException(oldTask.Exception), IsFailure = oldTask.IsFaulted, CustomerId = GetCustomerId(request), PartialFailures = (oldTask.IsFaulted) ? "" : GetPartialFailures(oldTask.Result) }; WriteLogs(logEntry); } }
public void TestExtractRpcException() { AggregateException ae = new AggregateException(TEST_EXCEPTION); RpcException innerException = UnaryRpcInterceptor.ExtractRpcException(ae); Assert.IsInstanceOf <AdsBaseException>(innerException); }
/// <summary> /// Handles the logging of asynchronous server streaming calls. /// </summary> /// <typeparam name="TRequest">The type of the request.</typeparam> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The request.</param> /// <param name="response">The response.</param> /// <param name="context">The context.</param> /// <param name="rpcException">The RPC exception.</param> /// <param name="call">The call.</param> internal void HandleAsyncServerStreamingLogging <TRequest, TResponse>(TRequest request, TResponse response, ClientInterceptorContext <TRequest, TResponse> context, AggregateException rpcException, AsyncServerStreamingCall <TResponse> call) where TRequest : class where TResponse : class { // Generating log entry is expensive, so let's do that only if the log source // has been configured to do so. if (TraceUtilities.ShouldGenerateRequestLogs()) { LogEntry logEntry = new LogEntry() { Host = config.ServerUrl, Method = context.Method.FullName, RequestHeaders = context.Options.Headers, Request = request, ResponseHeaders = Merge(GetResponseHeader(call.ResponseHeadersAsync), TryGetCallTrailers(call)), Response = response, Exception = UnaryRpcInterceptor.ParseTaskException(rpcException), IsFailure = (rpcException != null), CustomerId = GetCustomerId(request), PartialFailures = (rpcException != null) ? "" : GetPartialFailures(response) }; WriteLogs(logEntry); } }
public void TestInterceptStreamWithException() { TestStreamReader <object> testStreamReader = new TestStreamReader <object>( new object[] { }, TEST_EXCEPTION); StreamingRpcInterceptor <object> interceptor = new StreamingRpcInterceptor <object>(testStreamReader, delegate(object foo, AggregateException e) { RpcException innerException = UnaryRpcInterceptor.ExtractRpcException(e); Assert.IsInstanceOf <GoogleAdsBaseException>(innerException); return; }); Assert.Throws <AggregateException>(delegate() { bool hasMoreItems = true; while (hasMoreItems) { Task <bool> task = interceptor.MoveNext(); task.Wait(); hasMoreItems = task.Result; object temp = interceptor.Current; } }); }
public void TestInterceptFuncDelegateNoException() { Func <int> interceptedFunc = UnaryRpcInterceptor.Intercept(returnIntFunc); Assert.DoesNotThrow(delegate() { interceptedFunc(); }); }
public void TestInterceptTaskNoException() { Task <int> interceptedTask = UnaryRpcInterceptor.Intercept(Task.Run(returnIntFunc)); Assert.DoesNotThrow(delegate() { interceptedTask.Wait(); }); }
public void TestInterceptActionNoException() { Action interceptedAction = UnaryRpcInterceptor.Intercept(returnAction); Assert.DoesNotThrow(delegate() { interceptedAction(); }); }
public void TestInterceptTaskWithException() { Task <int> interceptedTask = UnaryRpcInterceptor.Intercept <int, HelloException>( Task.Run(throwExceptionFunc)); try { interceptedTask.Wait(); } catch (AggregateException ae) { CheckForHelloException(ae); } }
public void TestInterceptActionWithException() { Action interceptedTask = UnaryRpcInterceptor.Intercept(throwExceptionAction); try { interceptedTask(); } catch (GoogleAdsException) { Assert.Pass("Exception parsed correctly."); } catch { Assert.Pass("Exception could not be parsed."); } }
public void TestInterceptFuncDelegateWithException() { Func <int> interceptedFunc = UnaryRpcInterceptor.Intercept(throwExceptionFunc); try { interceptedFunc(); } catch (GoogleAdsException) { Assert.Pass("Exception parsed correctly."); } catch { Assert.Pass("Exception could not be parsed."); } }
public void TestParseTaskException() { Assert.NotNull(UnaryRpcInterceptor.ParseTaskException <HelloException>( new AggregateException(TEST_EXCEPTION))); }
public void TestParseRpcException() { Assert.NotNull(UnaryRpcInterceptor.ParseRpcException <HelloException>( TEST_EXCEPTION)); }