This is an automated email from the ASF dual-hosted git repository.

laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new cd1682d5e refactor(FQDN): Add some convenient macros and update 
idl/duplication.thrift related code (#1983)
cd1682d5e is described below

commit cd1682d5e2e4668f4263073d5ddb04b8bd7574c4
Author: Yingchun Lai <[email protected]>
AuthorDate: Tue Apr 23 11:15:26 2024 +0800

    refactor(FQDN): Add some convenient macros and update 
idl/duplication.thrift related code (#1983)
    
    Add new convenient macros ASSERT_IP_AND_HOST_PORT for convenient using in 
tests.
---
 src/meta/duplication/meta_duplication_service.cpp     |  6 ++++--
 src/meta/test/meta_duplication_service_test.cpp       | 19 +++++++------------
 src/replica/duplication/duplication_sync_timer.cpp    |  4 ++--
 .../duplication/test/duplication_sync_timer_test.cpp  |  5 +++--
 src/runtime/rpc/rpc_host_port.h                       |  9 +++++++++
 5 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/src/meta/duplication/meta_duplication_service.cpp 
b/src/meta/duplication/meta_duplication_service.cpp
index 6c4d1a1dd..14602ee7d 100644
--- a/src/meta/duplication/meta_duplication_service.cpp
+++ b/src/meta/duplication/meta_duplication_service.cpp
@@ -361,9 +361,11 @@ void 
meta_duplication_service::duplication_sync(duplication_sync_rpc rpc)
     auto &response = rpc.response();
     response.err = ERR_OK;
 
-    node_state *ns = get_node_state(_state->_nodes, 
host_port::from_address(request.node), false);
+    host_port src_hp;
+    GET_HOST_PORT(request, node, src_hp);
+    const auto *ns = get_node_state(_state->_nodes, src_hp, false);
     if (ns == nullptr) {
-        LOG_WARNING("node({}) is not found in meta server", request.node);
+        LOG_WARNING("node({}) is not found in meta server", 
FMT_HOST_PORT_AND_IP(request, node));
         response.err = ERR_OBJECT_NOT_FOUND;
         return;
     }
diff --git a/src/meta/test/meta_duplication_service_test.cpp 
b/src/meta/test/meta_duplication_service_test.cpp
index df0a34d99..5f7600312 100644
--- a/src/meta/test/meta_duplication_service_test.cpp
+++ b/src/meta/test/meta_duplication_service_test.cpp
@@ -57,7 +57,6 @@
 #include "meta/server_state.h"
 #include "meta/test/misc/misc.h"
 #include "meta_test_base.h"
-#include "runtime/rpc/dns_resolver.h"
 #include "runtime/rpc/rpc_address.h"
 #include "runtime/rpc/rpc_host_port.h"
 #include "utils/blob.h"
@@ -145,13 +144,11 @@ public:
     }
 
     duplication_sync_response
-    duplication_sync(const rpc_address &addr,
-                     const host_port &hp,
+    duplication_sync(const host_port &hp,
                      std::map<gpid, std::vector<duplication_confirm_entry>> 
confirm_list)
     {
         auto req = std::make_unique<duplication_sync_request>();
-        req->node = addr;
-        req->__set_hp_node(hp);
+        SET_IP_AND_HOST_PORT_BY_DNS(*req, node, hp);
         req->confirm_list = confirm_list;
 
         duplication_sync_rpc rpc(std::move(req), RPC_CM_DUPLICATION_SYNC);
@@ -601,7 +598,6 @@ TEST_F(meta_duplication_service_test, duplication_sync)
     initialize_node_state();
 
     const auto &node = server_nodes[0];
-    const auto &addr = 
dsn::dns_resolver::instance().resolve_address(server_nodes[0]);
     const dupid_t dupid = create_dup(test_app).dupid;
     auto dup = app->duplications[dupid];
     for (int i = 0; i < app->partition_count; i++) {
@@ -622,7 +618,7 @@ TEST_F(meta_duplication_service_test, duplication_sync)
         ce.confirmed_decree = 7;
         confirm_list[gpid(app->app_id, 3)].push_back(ce);
 
-        duplication_sync_response resp = duplication_sync(addr, node, 
confirm_list);
+        duplication_sync_response resp = duplication_sync(node, confirm_list);
         ASSERT_EQ(resp.err, ERR_OK);
         ASSERT_EQ(resp.dup_map.size(), 1);
         ASSERT_EQ(resp.dup_map[app->app_id].size(), 1);
@@ -653,7 +649,7 @@ TEST_F(meta_duplication_service_test, duplication_sync)
         ce.confirmed_decree = 5;
         confirm_list[gpid(app->app_id, 1)].push_back(ce);
 
-        duplication_sync_response resp = duplication_sync(addr, node, 
confirm_list);
+        duplication_sync_response resp = duplication_sync(node, confirm_list);
         ASSERT_EQ(resp.err, ERR_OK);
         ASSERT_EQ(resp.dup_map.size(), 1);
         ASSERT_TRUE(resp.dup_map[app->app_id].find(dupid + 1) == 
resp.dup_map[app->app_id].end());
@@ -667,7 +663,7 @@ TEST_F(meta_duplication_service_test, duplication_sync)
         ce.confirmed_decree = 5;
         confirm_list[gpid(app->app_id + 1, 1)].push_back(ce);
 
-        const auto resp = duplication_sync(addr, node, confirm_list);
+        const auto resp = duplication_sync(node, confirm_list);
         ASSERT_EQ(resp.err, ERR_OK);
         ASSERT_EQ(resp.dup_map.size(), 1);
         ASSERT_TRUE(resp.dup_map.find(app->app_id + 1) == resp.dup_map.end());
@@ -683,7 +679,7 @@ TEST_F(meta_duplication_service_test, duplication_sync)
         ce.confirmed_decree = 5;
         confirm_list[gpid(app->app_id, 1)].push_back(ce);
 
-        const auto resp = duplication_sync(addr, node, confirm_list);
+        const auto resp = duplication_sync(node, confirm_list);
         ASSERT_EQ(resp.err, ERR_OK);
         ASSERT_EQ(resp.dup_map.size(), 0);
     }
@@ -819,8 +815,7 @@ TEST_F(meta_duplication_service_test, fail_mode)
         SET_IP_AND_HOST_PORT_BY_DNS(pc, primary, hp);
     }
     initialize_node_state();
-    const auto addr = dsn::dns_resolver::instance().resolve_address(hp);
-    auto sync_resp = duplication_sync(addr, hp, {});
+    auto sync_resp = duplication_sync(hp, {});
     ASSERT_TRUE(sync_resp.dup_map[app->app_id][dup->id].__isset.fail_mode);
     ASSERT_EQ(sync_resp.dup_map[app->app_id][dup->id].fail_mode, 
duplication_fail_mode::FAIL_SKIP);
 
diff --git a/src/replica/duplication/duplication_sync_timer.cpp 
b/src/replica/duplication/duplication_sync_timer.cpp
index d7254c939..3d0df01aa 100644
--- a/src/replica/duplication/duplication_sync_timer.cpp
+++ b/src/replica/duplication/duplication_sync_timer.cpp
@@ -29,6 +29,7 @@
 #include "replica/replica_stub.h"
 #include "replica_duplicator_manager.h"
 #include "runtime/rpc/rpc_address.h"
+#include "runtime/rpc/rpc_host_port.h"
 #include "runtime/task/async_calls.h"
 #include "runtime/task/task_code.h"
 #include "utils/autoref_ptr.h"
@@ -69,8 +70,7 @@ void duplication_sync_timer::run()
     }
 
     auto req = std::make_unique<duplication_sync_request>();
-    req->node = _stub->primary_address();
-    req->__set_hp_node(_stub->primary_host_port());
+    SET_IP_AND_HOST_PORT(*req, node, _stub->primary_address(), 
_stub->primary_host_port());
 
     // collects confirm points from all primaries on this server
     for (const replica_ptr &r : _stub->get_all_primaries()) {
diff --git a/src/replica/duplication/test/duplication_sync_timer_test.cpp 
b/src/replica/duplication/test/duplication_sync_timer_test.cpp
index 7ac1b19a4..0f7855ed7 100644
--- a/src/replica/duplication/test/duplication_sync_timer_test.cpp
+++ b/src/replica/duplication/test/duplication_sync_timer_test.cpp
@@ -32,6 +32,7 @@
 #include "replica/duplication/replica_duplicator_manager.h"
 #include "replica/test/mock_utils.h"
 #include "runtime/rpc/rpc_holder.h"
+#include "runtime/rpc/rpc_host_port.h"
 #include "runtime/rpc/rpc_message.h"
 #include "utils/error_code.h"
 
@@ -119,7 +120,7 @@ public:
             ASSERT_EQ(duplication_sync_rpc::mail_box().size(), 1);
 
             auto &req = duplication_sync_rpc::mail_box().back().request();
-            ASSERT_EQ(req.node, stub->primary_address());
+            ASSERT_IP_AND_HOST_PORT(req, node, stub->primary_address(), 
stub->primary_host_port());
 
             // ensure confirm list is empty when no progress
             ASSERT_EQ(0, req.confirm_list.size());
@@ -142,7 +143,7 @@ public:
             ASSERT_EQ(duplication_sync_rpc::mail_box().size(), 1);
 
             auto &req = 
*duplication_sync_rpc::mail_box().back().mutable_request();
-            ASSERT_EQ(req.node, stub->primary_address());
+            ASSERT_IP_AND_HOST_PORT(req, node, stub->primary_address(), 
stub->primary_host_port());
             ASSERT_EQ(req.confirm_list.size(), total_app_num);
 
             for (int appid = 1; appid <= total_app_num; appid++) {
diff --git a/src/runtime/rpc/rpc_host_port.h b/src/runtime/rpc/rpc_host_port.h
index 1b8cc70b5..9e8b7a580 100644
--- a/src/runtime/rpc/rpc_host_port.h
+++ b/src/runtime/rpc/rpc_host_port.h
@@ -66,6 +66,15 @@ class TProtocol;
         _obj.__set_hp_##field(hp);                                             
                    \
     } while (0)
 
+// GTest check whether the '<field>' and 'hp_<field>' of 'obj' equal to 'addr' 
and 'hp'. The types
+// of the fields are rpc_address and host_port, respectively.
+#define ASSERT_IP_AND_HOST_PORT(obj, field, addr, hp)                          
                    \
+    do {                                                                       
                    \
+        auto &_obj = (obj);                                                    
                    \
+        ASSERT_EQ((addr), _obj.field);                                         
                    \
+        ASSERT_EQ((hp), _obj.hp_##field);                                      
                    \
+    } while (0)
+
 // Set 'hp' and its DNS resolved rpc_address to the optional 'hp_<field>' and 
'<field>' of 'obj'.
 // The types of the fields are host_port and rpc_address, respectively.
 #define SET_IP_AND_HOST_PORT_BY_DNS(obj, field, hp)                            
                    \


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to