This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
feat(shell): support resolve IP address in dsn/utility #337
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
b747c9e
fix bugs
Smityz e0eadcc
1
Smityz f01f554
Merge commit 'e0eadccc2c894f0d727ce71b63d6b2e38c4b1359'
Smityz 94a5df4
server_info changed
Smityz 6c83c09
unit test
Smityz 18b4ba8
cpp format
Smityz b451f8b
1
Smityz 21a9bed
add unit test
Smityz a65d8a5
format
Smityz 4101e3a
format4
Smityz 91ee474
format4
Smityz 3698f65
fix run-clang-format.sh
Smityz 4df892f
rollback format.sh
Smityz d24d02e
add unit test
Smityz 75321f6
format
Smityz b5ae5de
add unit tests && fix bugs
Smityz 5852bdf
add unit test && fix some bugs
Smityz 3c1d65f
1
Smityz 126d6ac
1
Smityz 248e890
Update replication_ddl_client.cpp
Smityz 278b291
1
Smityz 9c29853
1
Smityz 5b5b75e
fix commentary
Smityz 9267fee
1
Smityz 88b8ced
fix private unit test
Smityz aadde4d
fix private unit test
Smityz 39f11b8
final
Smityz 5ef75e4
Merge branch 'master' into master
acelyc111 eb92a19
1213
Smityz a85bf06
format
Smityz f9a0acc
fomat again
Smityz dd6d544
delete
Smityz e486ae4
1
Smityz e010b3f
change comment
Smityz 0bd206e
2222
Smityz dd60dbf
1
Smityz 9272cb0
final
Smityz 41d51d3
change private
Smityz 04128bc
change files
Smityz 8765a16
change files
Smityz f92dc5d
1
Smityz 61e4ceb
test change place
Smityz da730df
1
Smityz 039ec48
123
Smityz d5a486b
Update replication_ddl_client.h
Smityz 1524bed
Merge branch 'master' into master
acelyc111 764e244
Update replication_ddl_client.h
Smityz dda574f
Update utils.h
Smityz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) 2017-present, Xiaomi, Inc. All rights reserved. | ||
// This source code is licensed under the Apache License Version 2.0, which | ||
// can be found in the LICENSE file in the root directory of this source tree. | ||
|
||
#include <dsn/utility/utils.h> | ||
|
||
#include <dsn/tool-api/rpc_address.h> | ||
#include <gtest/gtest.h> | ||
|
||
namespace dsn { | ||
namespace replication { | ||
|
||
TEST(ip_to_hostname, localhost) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上,建议改名 hostname_utils_test.cpp |
||
{ | ||
std::string hostname_result; | ||
|
||
const std::string success_ip = "127.0.0.1"; | ||
const std::string expected_hostname = "localhost"; | ||
|
||
const std::string success_ip_port = "127.0.0.1:23010"; | ||
const std::string expected_hostname_port = "localhost:23010"; | ||
|
||
const std::string failed_ip = "123.456.789.111"; | ||
const std::string failed_ip_port = "123.456.789.111:23010"; | ||
|
||
const std::string success_ip_list = "127.0.0.1,127.0.0.1,127.0.0.1"; | ||
const std::string expected_hostname_list = "localhost,localhost,localhost"; | ||
|
||
const std::string success_ip_port_list = "127.0.0.1:8080,127.0.0.1:8080,127.0.0.1:8080"; | ||
const std::string expected_hostname_port_list = "localhost:8080,localhost:8080,localhost:8080"; | ||
|
||
rpc_address rpc_example_success, rpc_example_failed; | ||
rpc_example_success.assign_ipv4(success_ip.c_str(), 23010); | ||
rpc_example_failed.assign_ipv4(failed_ip.c_str(), 23010); | ||
|
||
// static bool hostname(const rpc_address &address,std::string *hostname_result); | ||
ASSERT_TRUE(dsn::utils::hostname(rpc_example_success, &hostname_result)); | ||
ASSERT_STREQ(expected_hostname_port.c_str(), hostname_result.c_str()); | ||
|
||
ASSERT_FALSE(dsn::utils::hostname(rpc_example_failed, &hostname_result)); | ||
|
||
// static bool hostname_from_ip(uint32_t ip, std::string* hostname_result); | ||
ASSERT_TRUE(dsn::utils::hostname_from_ip(htonl(rpc_example_success.ip()), &hostname_result)); | ||
ASSERT_STREQ(expected_hostname.c_str(), hostname_result.c_str()); | ||
|
||
ASSERT_FALSE(dsn::utils::hostname_from_ip(htonl(rpc_example_failed.ip()), &hostname_result)); | ||
|
||
// static bool hostname_from_ip(const char *ip,std::string *hostname_result); | ||
ASSERT_TRUE(dsn::utils::hostname_from_ip(success_ip.c_str(), &hostname_result)); | ||
ASSERT_STREQ(expected_hostname.c_str(), hostname_result.c_str()); | ||
|
||
ASSERT_FALSE(dsn::utils::hostname_from_ip(failed_ip.c_str(), &hostname_result)); | ||
ASSERT_STREQ(failed_ip.c_str(), hostname_result.c_str()); | ||
|
||
// static bool hostname_from_ip_port(const char *ip_port,std::string *hostname_result); | ||
ASSERT_TRUE(dsn::utils::hostname_from_ip_port(success_ip_port.c_str(), &hostname_result)); | ||
ASSERT_STREQ(expected_hostname_port.c_str(), hostname_result.c_str()); | ||
|
||
ASSERT_FALSE(dsn::utils::hostname_from_ip_port(failed_ip_port.c_str(), &hostname_result)); | ||
ASSERT_STREQ(failed_ip_port.c_str(), hostname_result.c_str()); | ||
|
||
// static bool list_hostname_from_ip(const char *ip_port_list,std::string | ||
// *hostname_result_list); | ||
ASSERT_TRUE(dsn::utils::list_hostname_from_ip(success_ip_list.c_str(), &hostname_result)); | ||
ASSERT_STREQ(expected_hostname_list.c_str(), hostname_result.c_str()); | ||
|
||
ASSERT_FALSE(dsn::utils::list_hostname_from_ip("127.0.0.1,127.0.0.23323,111127.0.0.3", | ||
&hostname_result)); | ||
ASSERT_STREQ("localhost,127.0.0.23323,111127.0.0.3", hostname_result.c_str()); | ||
|
||
ASSERT_FALSE(dsn::utils::list_hostname_from_ip("123.456.789.111,127.0.0.1", &hostname_result)); | ||
ASSERT_STREQ("123.456.789.111,localhost", hostname_result.c_str()); | ||
|
||
// static bool list_hostname_from_ip_port(const char *ip_port_list,std::string | ||
// *hostname_result_list); | ||
ASSERT_TRUE( | ||
dsn::utils::list_hostname_from_ip_port(success_ip_port_list.c_str(), &hostname_result)); | ||
ASSERT_STREQ(expected_hostname_port_list.c_str(), hostname_result.c_str()); | ||
|
||
ASSERT_FALSE(dsn::utils::list_hostname_from_ip_port( | ||
"127.0.3333.1:23456,1127.0.0.2:22233,127.0.0.1:8080", &hostname_result)); | ||
ASSERT_STREQ("127.0.3333.1:23456,1127.0.0.2:22233,localhost:8080", hostname_result.c_str()); | ||
} | ||
|
||
} // namespace replication | ||
} // namespace dsn |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么不直接写一个新文件 hostname_utils.h/hostname_utils.cpp 啊,utils.h 里的东西太杂了,很难管理