You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by jd...@apache.org on 2016/07/13 04:12:48 UTC

[2/2] incubator-kudu git commit: Add a ToString() method to Proxy

Add a ToString() method to Proxy

ReplicatedRpc takes the server proxy type as a template argument and
uses its ToString() method to print out details in case of error. Usually
this is RemoteTablet, which has a ToString() method, but that might
not always be the case.

In fact, in a test in a follow up patch ReplicatedRpc takes Proxy as the
server proxy type and compilation would fail due to a missing ToString().
We could make ReplicatedRpc not use the ToString() method, but it seems
very helpful to have it so this patch adds it to Proxy instead.

Change-Id: Ia1e158db09e6e3c188b2725424681187a4b8c72e
Reviewed-on: http://gerrit.cloudera.org:8080/3502
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/3c01d4c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/3c01d4c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/3c01d4c0

Branch: refs/heads/master
Commit: 3c01d4c058ab07f2346d83a8750bcb0839a4bd97
Parents: 90d610f
Author: David Alves <da...@cloudera.com>
Authored: Sun Jun 26 18:06:03 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Wed Jul 13 03:54:57 2016 +0000

----------------------------------------------------------------------
 src/kudu/rpc/proxy.cc    | 6 ++++++
 src/kudu/rpc/proxy.h     | 2 ++
 src/kudu/rpc/rpc-test.cc | 4 ++++
 3 files changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/3c01d4c0/src/kudu/rpc/proxy.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/proxy.cc b/src/kudu/rpc/proxy.cc
index 8337e31..c8e5017 100644
--- a/src/kudu/rpc/proxy.cc
+++ b/src/kudu/rpc/proxy.cc
@@ -27,6 +27,8 @@
 #include <sstream>
 #include <vector>
 
+#include "kudu/gutil/stringprintf.h"
+#include "kudu/gutil/strings/substitute.h"
 #include "kudu/rpc/outbound_call.h"
 #include "kudu/rpc/messenger.h"
 #include "kudu/rpc/remote_method.h"
@@ -105,5 +107,9 @@ void Proxy::set_user_credentials(const UserCredentials& user_credentials) {
   conn_id_.set_user_credentials(user_credentials);
 }
 
+std::string Proxy::ToString() const {
+  return strings::Substitute("$0@$1", service_name_, conn_id_.ToString());
+}
+
 } // namespace rpc
 } // namespace kudu

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/3c01d4c0/src/kudu/rpc/proxy.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/proxy.h b/src/kudu/rpc/proxy.h
index 7e27d55..b1bc350 100644
--- a/src/kudu/rpc/proxy.h
+++ b/src/kudu/rpc/proxy.h
@@ -104,6 +104,8 @@ class Proxy {
   // Get the user credentials which should be used to log in.
   const UserCredentials& user_credentials() const { return conn_id_.user_credentials(); }
 
+  std::string ToString() const;
+
  private:
   const std::string service_name_;
   std::shared_ptr<Messenger> messenger_;

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/3c01d4c0/src/kudu/rpc/rpc-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/rpc-test.cc b/src/kudu/rpc/rpc-test.cc
index e4f7969..dd8c265 100644
--- a/src/kudu/rpc/rpc-test.cc
+++ b/src/kudu/rpc/rpc-test.cc
@@ -27,6 +27,7 @@
 
 #include "kudu/gutil/map-util.h"
 #include "kudu/gutil/strings/join.h"
+#include "kudu/gutil/strings/substitute.h"
 #include "kudu/rpc/constants.h"
 #include "kudu/rpc/serialization.h"
 #include "kudu/util/countdown_latch.h"
@@ -108,6 +109,9 @@ TEST_F(TestRpc, TestCall) {
   LOG(INFO) << "Connecting to " << server_addr.ToString();
   shared_ptr<Messenger> client_messenger(CreateMessenger("Client"));
   Proxy p(client_messenger, server_addr, GenericCalculatorService::static_service_name());
+  ASSERT_STR_CONTAINS(p.ToString(), strings::Substitute("kudu.rpc.GenericCalculatorService@"
+                                                            "{remote=$0, user_credentials=",
+                                                        server_addr.ToString()));
 
   for (int i = 0; i < 10; i++) {
     ASSERT_OK(DoTestSyncCall(p, GenericCalculatorService::kAddMethodName));