/Users/deen/code/yugabyte-db/src/yb/integration-tests/tablet_server-itest.cc
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include <glog/logging.h> |
15 | | |
16 | | #include "yb/integration-tests/external_mini_cluster.h" |
17 | | #include "yb/integration-tests/ts_itest-base.h" |
18 | | |
19 | | #include "yb/util/status_log.h" |
20 | | |
21 | | namespace yb { |
22 | | namespace tserver { |
23 | | |
24 | | class TabletServerITest : public TabletServerIntegrationTestBase { |
25 | | }; |
26 | | |
27 | | // Given a host:port string, return the host part as a string. |
28 | 24 | std::string GetHost(const std::string& val) { |
29 | 24 | return CHECK_RESULT(HostPort::FromString(val, 0)).host(); |
30 | 24 | } |
31 | | |
32 | 1 | TEST_F(TabletServerITest, TestProxyAddrs) { |
33 | 1 | CreateCluster("tablet_server-itest-cluster"); |
34 | | |
35 | 4 | for (int i = 0; i < FLAGS_num_tablet_servers; i++) { |
36 | 3 | auto tserver = cluster_->tablet_server(i); |
37 | 3 | auto rpc_host = GetHost(ASSERT_RESULT(tserver->GetFlag("rpc_bind_addresses"))); |
38 | 3 | for (auto flag : {"cql_proxy_bind_address", |
39 | 3 | "redis_proxy_bind_address", |
40 | 9 | "pgsql_proxy_bind_address"}) { |
41 | 9 | auto host = GetHost(ASSERT_RESULT(tserver->GetFlag(flag))); |
42 | 9 | ASSERT_EQ(host, rpc_host); |
43 | 9 | } |
44 | 3 | } |
45 | 1 | } |
46 | | |
47 | 1 | TEST_F(TabletServerITest, TestProxyAddrsNonDefault) { |
48 | 1 | std::vector<string> ts_flags, master_flags; |
49 | 1 | ts_flags.push_back("--cql_proxy_bind_address=127.0.0.1${index}"); |
50 | 1 | std::unique_ptr<FileLock> redis_port_file_lock; |
51 | 1 | auto redis_port = GetFreePort(&redis_port_file_lock); |
52 | 1 | ts_flags.push_back("--redis_proxy_bind_address=127.0.0.2${index}:" + std::to_string(redis_port)); |
53 | 1 | std::unique_ptr<FileLock> pgsql_port_file_lock; |
54 | 1 | auto pgsql_port = GetFreePort(&pgsql_port_file_lock); |
55 | 1 | ts_flags.push_back("--pgsql_proxy_bind_address=127.0.0.3${index}:" + std::to_string(pgsql_port)); |
56 | | |
57 | 1 | CreateCluster("ts-itest-cluster-nd", ts_flags, master_flags); |
58 | | |
59 | 4 | for (int i = 0; i < FLAGS_num_tablet_servers; i++) { |
60 | 3 | auto tserver = cluster_->tablet_server(i); |
61 | 3 | auto rpc_host = GetHost(ASSERT_RESULT(tserver->GetFlag("rpc_bind_addresses"))); |
62 | | |
63 | 3 | auto res = GetHost(ASSERT_RESULT(tserver->GetFlag("cql_proxy_bind_address"))); |
64 | 3 | ASSERT_EQ(res, Format("127.0.0.1$0", i)); |
65 | 3 | ASSERT_NE(res, rpc_host); |
66 | | |
67 | 3 | res = GetHost(ASSERT_RESULT(tserver->GetFlag("redis_proxy_bind_address"))); |
68 | 3 | ASSERT_EQ(res, Format("127.0.0.2$0", i)); |
69 | 3 | ASSERT_NE(res, rpc_host); |
70 | | |
71 | 3 | res = GetHost(ASSERT_RESULT(tserver->GetFlag("pgsql_proxy_bind_address"))); |
72 | 3 | ASSERT_EQ(res, Format("127.0.0.3$0", i)); |
73 | 3 | ASSERT_NE(res, rpc_host); |
74 | 3 | } |
75 | 1 | } |
76 | | |
77 | | } // namespace tserver |
78 | | } // namespace yb |