/// <exception cref="System.Exception"/> public virtual void ReadWithTracing() { string fileName = "testReadTraceHooks.dat"; WriteTestFile(fileName); long startTime = Runtime.CurrentTimeMillis(); TraceScope ts = Trace.StartSpan("testReadTraceHooks", Sampler.Always); ReadTestFile(fileName); ts.Close(); long endTime = Runtime.CurrentTimeMillis(); string[] expectedSpanNames = new string[] { "testReadTraceHooks", "org.apache.hadoop.hdfs.protocol.ClientProtocol.getBlockLocations" , "ClientNamenodeProtocol#getBlockLocations", "OpReadBlockProto" }; AssertSpanNamesFound(expectedSpanNames); // The trace should last about the same amount of time as the test IDictionary <string, IList <Span> > map = TestTracing.SetSpanReceiver.SetHolder.GetMap (); Span s = map["testReadTraceHooks"][0]; NUnit.Framework.Assert.IsNotNull(s); long spanStart = s.GetStartTimeMillis(); long spanEnd = s.GetStopTimeMillis(); NUnit.Framework.Assert.IsTrue(spanStart - startTime < 100); NUnit.Framework.Assert.IsTrue(spanEnd - endTime < 100); // There should only be one trace id as it should all be homed in the // top trace. foreach (Span span in TestTracing.SetSpanReceiver.SetHolder.spans.Values) { NUnit.Framework.Assert.AreEqual(ts.GetSpan().GetTraceId(), span.GetTraceId()); } TestTracing.SetSpanReceiver.SetHolder.spans.Clear(); }
/// <exception cref="System.Exception"/> public virtual void WriteWithTracing() { long startTime = Runtime.CurrentTimeMillis(); TraceScope ts = Trace.StartSpan("testWriteTraceHooks", Sampler.Always); WriteTestFile("testWriteTraceHooks.dat"); long endTime = Runtime.CurrentTimeMillis(); ts.Close(); string[] expectedSpanNames = new string[] { "testWriteTraceHooks", "org.apache.hadoop.hdfs.protocol.ClientProtocol.create" , "ClientNamenodeProtocol#create", "org.apache.hadoop.hdfs.protocol.ClientProtocol.fsync" , "ClientNamenodeProtocol#fsync", "org.apache.hadoop.hdfs.protocol.ClientProtocol.complete" , "ClientNamenodeProtocol#complete", "newStreamForCreate", "DFSOutputStream#writeChunk" , "DFSOutputStream#close", "dataStreamer", "OpWriteBlockProto", "org.apache.hadoop.hdfs.protocol.ClientProtocol.addBlock" , "ClientNamenodeProtocol#addBlock" }; AssertSpanNamesFound(expectedSpanNames); // The trace should last about the same amount of time as the test IDictionary <string, IList <Span> > map = TestTracing.SetSpanReceiver.SetHolder.GetMap (); Span s = map["testWriteTraceHooks"][0]; NUnit.Framework.Assert.IsNotNull(s); long spanStart = s.GetStartTimeMillis(); long spanEnd = s.GetStopTimeMillis(); // Spans homed in the top trace shoud have same trace id. // Spans having multiple parents (e.g. "dataStreamer" added by HDFS-7054) // and children of them are exception. string[] spansInTopTrace = new string[] { "testWriteTraceHooks", "org.apache.hadoop.hdfs.protocol.ClientProtocol.create" , "ClientNamenodeProtocol#create", "org.apache.hadoop.hdfs.protocol.ClientProtocol.fsync" , "ClientNamenodeProtocol#fsync", "org.apache.hadoop.hdfs.protocol.ClientProtocol.complete" , "ClientNamenodeProtocol#complete", "newStreamForCreate", "DFSOutputStream#writeChunk" , "DFSOutputStream#close" }; foreach (string desc in spansInTopTrace) { foreach (Span span in map[desc]) { NUnit.Framework.Assert.AreEqual(ts.GetSpan().GetTraceId(), span.GetTraceId()); } } TestTracing.SetSpanReceiver.SetHolder.spans.Clear(); }
/// <summary>This is the client side invoker of RPC method.</summary> /// <remarks> /// This is the client side invoker of RPC method. It only throws /// ServiceException, since the invocation proxy expects only /// ServiceException to be thrown by the method in case protobuf service. /// ServiceException has the following causes: /// <ol> /// <li>Exceptions encountered on the client side in this method are /// set as cause in ServiceException as is.</li> /// <li>Exceptions from the server are wrapped in RemoteException and are /// set as cause in ServiceException</li> /// </ol> /// Note that the client calling protobuf RPC methods, must handle /// ServiceException by getting the cause from the ServiceException. If the /// cause is RemoteException, then unwrap it to get the exception thrown by /// the server. /// </remarks> /// <exception cref="Com.Google.Protobuf.ServiceException"/> public virtual object Invoke(object proxy, MethodInfo method, object[] args) { long startTime = 0; if (Log.IsDebugEnabled()) { startTime = Time.Now(); } if (args.Length != 2) { // RpcController + Message throw new ServiceException("Too many parameters for request. Method: [" + method. Name + "]" + ", Expected: 2, Actual: " + args.Length); } if (args[1] == null) { throw new ServiceException("null param while calling Method: [" + method.Name + "]" ); } TraceScope traceScope = null; // if Tracing is on then start a new span for this rpc. // guard it in the if statement to make sure there isn't // any extra string manipulation. if (Trace.IsTracing()) { traceScope = Trace.StartSpan(RpcClientUtil.MethodToTraceString(method)); } ProtobufRpcEngineProtos.RequestHeaderProto rpcRequestHeader = ConstructRpcRequestHeader (method); if (Log.IsTraceEnabled()) { Log.Trace(Thread.CurrentThread().GetId() + ": Call -> " + remoteId + ": " + method.Name + " {" + TextFormat.ShortDebugString((Message)args[1]) + "}"); } Message theRequest = (Message)args[1]; ProtobufRpcEngine.RpcResponseWrapper val; try { val = (ProtobufRpcEngine.RpcResponseWrapper)client.Call(RPC.RpcKind.RpcProtocolBuffer , new ProtobufRpcEngine.RpcRequestWrapper(rpcRequestHeader, theRequest), remoteId , fallbackToSimpleAuth); } catch (Exception e) { if (Log.IsTraceEnabled()) { Log.Trace(Thread.CurrentThread().GetId() + ": Exception <- " + remoteId + ": " + method.Name + " {" + e + "}"); } if (Trace.IsTracing()) { traceScope.GetSpan().AddTimelineAnnotation("Call got exception: " + e.Message); } throw new ServiceException(e); } finally { if (traceScope != null) { traceScope.Close(); } } if (Log.IsDebugEnabled()) { long callTime = Time.Now() - startTime; Log.Debug("Call: " + method.Name + " took " + callTime + "ms"); } Message prototype = null; try { prototype = GetReturnProtoType(method); } catch (Exception e) { throw new ServiceException(e); } Message returnMessage; try { returnMessage = prototype.NewBuilderForType().MergeFrom(val.theResponseRead).Build (); if (Log.IsTraceEnabled()) { Log.Trace(Thread.CurrentThread().GetId() + ": Response <- " + remoteId + ": " + method.Name + " {" + TextFormat.ShortDebugString(returnMessage) + "}"); } } catch (Exception e) { throw new ServiceException(e); } return(returnMessage); }