aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2018-12-11 11:08:32 -0800
committerGravatar GitHub <noreply@github.com>2018-12-11 11:08:32 -0800
commit01afcb4feeae09e6db22bcc54112a1e10d61c8ac (patch)
treebe24d632efc34338b318b6321ed48741c13103da /test
parent6f675abe85927a2f6f18babc4445b7f210e41d5e (diff)
parentc5f344deaf84bd074419d42ed4af47e7c9ca6b42 (diff)
Merge pull request #17459 from grpc/revert-17450-revert-17343-server_address_list
Revert "Revert "Allow encoding arbitrary channel args on a per-address basis.""
Diffstat (limited to 'test')
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc12
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc15
-rw-r--r--test/core/client_channel/resolvers/fake_resolver_test.cc42
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer.cc28
-rw-r--r--test/core/end2end/goaway_server_test.cc29
-rw-r--r--test/core/end2end/no_server_test.cc1
-rw-r--r--test/core/util/ubsan_suppressions.txt3
-rw-r--r--test/cpp/client/client_channel_stress_test.cc28
-rw-r--r--test/cpp/end2end/client_lb_end2end_test.cc18
-rw-r--r--test/cpp/end2end/grpclb_end2end_test.cc37
-rw-r--r--test/cpp/naming/address_sorting_test.cc127
-rw-r--r--test/cpp/naming/resolver_component_test.cc21
12 files changed, 192 insertions, 169 deletions
diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc
index 76769b2b64..1a7a7c9ccc 100644
--- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc
+++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc
@@ -21,10 +21,10 @@
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
-#include "src/core/ext/filters/client_channel/lb_policy_factory.h"
#include "src/core/ext/filters/client_channel/resolver.h"
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include "src/core/ext/filters/client_channel/resolver_registry.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/resolve_address.h"
@@ -63,8 +63,9 @@ static grpc_address_resolver_vtable test_resolver = {my_resolve_address,
static grpc_ares_request* my_dns_lookup_ares_locked(
const char* dns_server, const char* addr, const char* default_port,
grpc_pollset_set* interested_parties, grpc_closure* on_done,
- grpc_lb_addresses** lb_addrs, bool check_grpclb, char** service_config_json,
- int query_timeout_ms, grpc_combiner* combiner) {
+ grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses,
+ bool check_grpclb, char** service_config_json, int query_timeout_ms,
+ grpc_combiner* combiner) {
gpr_mu_lock(&g_mu);
GPR_ASSERT(0 == strcmp("test", addr));
grpc_error* error = GRPC_ERROR_NONE;
@@ -74,9 +75,8 @@ static grpc_ares_request* my_dns_lookup_ares_locked(
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Failure");
} else {
gpr_mu_unlock(&g_mu);
- *lb_addrs = grpc_lb_addresses_create(1, nullptr);
- grpc_lb_addresses_set_address(*lb_addrs, 0, nullptr, 0, false, nullptr,
- nullptr);
+ *addresses = grpc_core::MakeUnique<grpc_core::ServerAddressList>();
+ (*addresses)->emplace_back(nullptr, 0, nullptr);
}
GRPC_CLOSURE_SCHED(on_done, error);
return nullptr;
diff --git a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc
index cdbe33dbe7..16210b8164 100644
--- a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc
+++ b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc
@@ -22,6 +22,7 @@
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include "src/core/ext/filters/client_channel/resolver_registry.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/combiner.h"
@@ -40,8 +41,9 @@ static grpc_combiner* g_combiner;
static grpc_ares_request* (*g_default_dns_lookup_ares_locked)(
const char* dns_server, const char* name, const char* default_port,
grpc_pollset_set* interested_parties, grpc_closure* on_done,
- grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json,
- int query_timeout_ms, grpc_combiner* combiner);
+ grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses,
+ bool check_grpclb, char** service_config_json, int query_timeout_ms,
+ grpc_combiner* combiner);
// Counter incremented by test_resolve_address_impl indicating the number of
// times a system-level resolution has happened.
@@ -90,11 +92,12 @@ static grpc_address_resolver_vtable test_resolver = {
static grpc_ares_request* test_dns_lookup_ares_locked(
const char* dns_server, const char* name, const char* default_port,
grpc_pollset_set* interested_parties, grpc_closure* on_done,
- grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json,
- int query_timeout_ms, grpc_combiner* combiner) {
+ grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses,
+ bool check_grpclb, char** service_config_json, int query_timeout_ms,
+ grpc_combiner* combiner) {
grpc_ares_request* result = g_default_dns_lookup_ares_locked(
- dns_server, name, default_port, g_iomgr_args.pollset_set, on_done, addrs,
- check_grpclb, service_config_json, query_timeout_ms, combiner);
+ dns_server, name, default_port, g_iomgr_args.pollset_set, on_done,
+ addresses, check_grpclb, service_config_json, query_timeout_ms, combiner);
++g_resolution_count;
static grpc_millis last_resolution_time = 0;
if (last_resolution_time == 0) {
diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc
index 6362b95e50..3b06fe063a 100644
--- a/test/core/client_channel/resolvers/fake_resolver_test.cc
+++ b/test/core/client_channel/resolvers/fake_resolver_test.cc
@@ -22,10 +22,10 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include "src/core/ext/filters/client_channel/lb_policy_factory.h"
#include "src/core/ext/filters/client_channel/parse_address.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/ext/filters/client_channel/resolver_registry.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/combiner.h"
@@ -63,12 +63,14 @@ void on_resolution_cb(void* arg, grpc_error* error) {
// We only check the addresses channel arg because that's the only one
// explicitly set by the test via
// FakeResolverResponseGenerator::SetResponse().
- const grpc_lb_addresses* actual_lb_addresses =
- grpc_lb_addresses_find_channel_arg(res->resolver_result);
- const grpc_lb_addresses* expected_lb_addresses =
- grpc_lb_addresses_find_channel_arg(res->expected_resolver_result);
- GPR_ASSERT(
- grpc_lb_addresses_cmp(actual_lb_addresses, expected_lb_addresses) == 0);
+ const grpc_core::ServerAddressList* actual_addresses =
+ grpc_core::FindServerAddressListChannelArg(res->resolver_result);
+ const grpc_core::ServerAddressList* expected_addresses =
+ grpc_core::FindServerAddressListChannelArg(res->expected_resolver_result);
+ GPR_ASSERT(actual_addresses->size() == expected_addresses->size());
+ for (size_t i = 0; i < expected_addresses->size(); ++i) {
+ GPR_ASSERT((*actual_addresses)[i] == (*expected_addresses)[i]);
+ }
grpc_channel_args_destroy(res->resolver_result);
grpc_channel_args_destroy(res->expected_resolver_result);
gpr_event_set(&res->ev, (void*)1);
@@ -80,27 +82,35 @@ static grpc_channel_args* create_new_resolver_result() {
const size_t num_addresses = 2;
char* uri_string;
char* balancer_name;
- // Create grpc_lb_addresses.
- grpc_lb_addresses* addresses =
- grpc_lb_addresses_create(num_addresses, nullptr);
+ // Create address list.
+ grpc_core::ServerAddressList addresses;
for (size_t i = 0; i < num_addresses; ++i) {
gpr_asprintf(&uri_string, "ipv4:127.0.0.1:100%" PRIuPTR,
test_counter * num_addresses + i);
grpc_uri* uri = grpc_uri_parse(uri_string, true);
gpr_asprintf(&balancer_name, "balancer%" PRIuPTR,
test_counter * num_addresses + i);
- grpc_lb_addresses_set_address_from_uri(
- addresses, i, uri, bool(num_addresses % 2), balancer_name, nullptr);
+ grpc_resolved_address address;
+ GPR_ASSERT(grpc_parse_uri(uri, &address));
+ grpc_core::InlinedVector<grpc_arg, 2> args_to_add;
+ const bool is_balancer = num_addresses % 2;
+ if (is_balancer) {
+ args_to_add.emplace_back(grpc_channel_arg_integer_create(
+ const_cast<char*>(GRPC_ARG_ADDRESS_IS_BALANCER), 1));
+ args_to_add.emplace_back(grpc_channel_arg_string_create(
+ const_cast<char*>(GRPC_ARG_ADDRESS_BALANCER_NAME), balancer_name));
+ }
+ grpc_channel_args* args = grpc_channel_args_copy_and_add(
+ nullptr, args_to_add.data(), args_to_add.size());
+ addresses.emplace_back(address.addr, address.len, args);
gpr_free(balancer_name);
grpc_uri_destroy(uri);
gpr_free(uri_string);
}
- // Convert grpc_lb_addresses to grpc_channel_args.
- const grpc_arg addresses_arg =
- grpc_lb_addresses_create_channel_arg(addresses);
+ // Embed the address list in channel args.
+ const grpc_arg addresses_arg = CreateServerAddressListChannelArg(&addresses);
grpc_channel_args* results =
grpc_channel_args_copy_and_add(nullptr, &addresses_arg, 1);
- grpc_lb_addresses_destroy(addresses);
++test_counter;
return results;
}
diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc
index a3de56d4f9..fe47127984 100644
--- a/test/core/end2end/fuzzers/api_fuzzer.cc
+++ b/test/core/end2end/fuzzers/api_fuzzer.cc
@@ -24,8 +24,8 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include "src/core/ext/filters/client_channel/lb_policy_factory.h"
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/env.h"
@@ -325,7 +325,7 @@ typedef struct addr_req {
char* addr;
grpc_closure* on_done;
grpc_resolved_addresses** addrs;
- grpc_lb_addresses** lb_addrs;
+ grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses;
} addr_req;
static void finish_resolve(void* arg, grpc_error* error) {
@@ -340,11 +340,9 @@ static void finish_resolve(void* arg, grpc_error* error) {
gpr_malloc(sizeof(*addrs->addrs)));
addrs->addrs[0].len = 0;
*r->addrs = addrs;
- } else if (r->lb_addrs != nullptr) {
- grpc_lb_addresses* lb_addrs = grpc_lb_addresses_create(1, nullptr);
- grpc_lb_addresses_set_address(lb_addrs, 0, nullptr, 0, false, nullptr,
- nullptr);
- *r->lb_addrs = lb_addrs;
+ } else if (r->addresses != nullptr) {
+ *r->addresses = grpc_core::MakeUnique<grpc_core::ServerAddressList>();
+ (*r->addresses)->emplace_back(nullptr, 0, nullptr);
}
GRPC_CLOSURE_SCHED(r->on_done, GRPC_ERROR_NONE);
} else {
@@ -354,18 +352,17 @@ static void finish_resolve(void* arg, grpc_error* error) {
}
gpr_free(r->addr);
- gpr_free(r);
+ grpc_core::Delete(r);
}
void my_resolve_address(const char* addr, const char* default_port,
grpc_pollset_set* interested_parties,
grpc_closure* on_done,
- grpc_resolved_addresses** addresses) {
- addr_req* r = static_cast<addr_req*>(gpr_malloc(sizeof(*r)));
+ grpc_resolved_addresses** addrs) {
+ addr_req* r = grpc_core::New<addr_req>();
r->addr = gpr_strdup(addr);
r->on_done = on_done;
- r->addrs = addresses;
- r->lb_addrs = nullptr;
+ r->addrs = addrs;
grpc_timer_init(
&r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(),
GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx));
@@ -377,13 +374,14 @@ static grpc_address_resolver_vtable fuzzer_resolver = {my_resolve_address,
grpc_ares_request* my_dns_lookup_ares_locked(
const char* dns_server, const char* addr, const char* default_port,
grpc_pollset_set* interested_parties, grpc_closure* on_done,
- grpc_lb_addresses** lb_addrs, bool check_grpclb, char** service_config_json,
- int query_timeout, grpc_combiner* combiner) {
+ grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses,
+ bool check_grpclb, char** service_config_json, int query_timeout,
+ grpc_combiner* combiner) {
addr_req* r = static_cast<addr_req*>(gpr_malloc(sizeof(*r)));
r->addr = gpr_strdup(addr);
r->on_done = on_done;
r->addrs = nullptr;
- r->lb_addrs = lb_addrs;
+ r->addresses = addresses;
grpc_timer_init(
&r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(),
GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx));
diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc
index 66e8ca5161..7e3b418cd9 100644
--- a/test/core/end2end/goaway_server_test.cc
+++ b/test/core/end2end/goaway_server_test.cc
@@ -28,8 +28,8 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <string.h>
-#include "src/core/ext/filters/client_channel/lb_policy_factory.h"
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "test/core/end2end/cq_verifier.h"
@@ -47,8 +47,9 @@ static int g_resolve_port = -1;
static grpc_ares_request* (*iomgr_dns_lookup_ares_locked)(
const char* dns_server, const char* addr, const char* default_port,
grpc_pollset_set* interested_parties, grpc_closure* on_done,
- grpc_lb_addresses** addresses, bool check_grpclb,
- char** service_config_json, int query_timeout_ms, grpc_combiner* combiner);
+ grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses,
+ bool check_grpclb, char** service_config_json, int query_timeout_ms,
+ grpc_combiner* combiner);
static void (*iomgr_cancel_ares_request_locked)(grpc_ares_request* request);
@@ -103,11 +104,12 @@ static grpc_address_resolver_vtable test_resolver = {
static grpc_ares_request* my_dns_lookup_ares_locked(
const char* dns_server, const char* addr, const char* default_port,
grpc_pollset_set* interested_parties, grpc_closure* on_done,
- grpc_lb_addresses** lb_addrs, bool check_grpclb, char** service_config_json,
- int query_timeout_ms, grpc_combiner* combiner) {
+ grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses,
+ bool check_grpclb, char** service_config_json, int query_timeout_ms,
+ grpc_combiner* combiner) {
if (0 != strcmp(addr, "test")) {
return iomgr_dns_lookup_ares_locked(
- dns_server, addr, default_port, interested_parties, on_done, lb_addrs,
+ dns_server, addr, default_port, interested_parties, on_done, addresses,
check_grpclb, service_config_json, query_timeout_ms, combiner);
}
@@ -117,15 +119,12 @@ static grpc_ares_request* my_dns_lookup_ares_locked(
gpr_mu_unlock(&g_mu);
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Failure");
} else {
- *lb_addrs = grpc_lb_addresses_create(1, nullptr);
- grpc_sockaddr_in* sa =
- static_cast<grpc_sockaddr_in*>(gpr_zalloc(sizeof(grpc_sockaddr_in)));
- sa->sin_family = GRPC_AF_INET;
- sa->sin_addr.s_addr = 0x100007f;
- sa->sin_port = grpc_htons(static_cast<uint16_t>(g_resolve_port));
- grpc_lb_addresses_set_address(*lb_addrs, 0, sa, sizeof(*sa), false, nullptr,
- nullptr);
- gpr_free(sa);
+ *addresses = grpc_core::MakeUnique<grpc_core::ServerAddressList>();
+ grpc_sockaddr_in sa;
+ sa.sin_family = GRPC_AF_INET;
+ sa.sin_addr.s_addr = 0x100007f;
+ sa.sin_port = grpc_htons(static_cast<uint16_t>(g_resolve_port));
+ (*addresses)->emplace_back(&sa, sizeof(sa), nullptr);
gpr_mu_unlock(&g_mu);
}
GRPC_CLOSURE_SCHED(on_done, error);
diff --git a/test/core/end2end/no_server_test.cc b/test/core/end2end/no_server_test.cc
index 5dda748f5a..c289e719ee 100644
--- a/test/core/end2end/no_server_test.cc
+++ b/test/core/end2end/no_server_test.cc
@@ -23,6 +23,7 @@
#include <grpc/support/log.h>
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
+#include "src/core/lib/iomgr/exec_ctx.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/util/ubsan_suppressions.txt b/test/core/util/ubsan_suppressions.txt
index 63898ea3b1..8ed7d4d7fb 100644
--- a/test/core/util/ubsan_suppressions.txt
+++ b/test/core/util/ubsan_suppressions.txt
@@ -25,7 +25,6 @@ alignment:absl::little_endian::Store64
alignment:absl::little_endian::Load64
float-divide-by-zero:grpc::testing::postprocess_scenario_result
enum:grpc_op_string
-nonnull-attribute:grpc_lb_addresses_copy
signed-integer-overflow:chrono
enum:grpc_http2_error_to_grpc_status
-enum:grpc_chttp2_cancel_stream \ No newline at end of file
+enum:grpc_chttp2_cancel_stream
diff --git a/test/cpp/client/client_channel_stress_test.cc b/test/cpp/client/client_channel_stress_test.cc
index bf321d8a89..124557eb56 100644
--- a/test/cpp/client/client_channel_stress_test.cc
+++ b/test/cpp/client/client_channel_stress_test.cc
@@ -34,7 +34,9 @@
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
+#include "src/core/ext/filters/client_channel/parse_address.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/sockaddr.h"
@@ -216,23 +218,31 @@ class ClientChannelStressTest {
void SetNextResolution(const std::vector<AddressData>& address_data) {
grpc_core::ExecCtx exec_ctx;
- grpc_lb_addresses* addresses =
- grpc_lb_addresses_create(address_data.size(), nullptr);
- for (size_t i = 0; i < address_data.size(); ++i) {
+ grpc_core::ServerAddressList addresses;
+ for (const auto& addr : address_data) {
char* lb_uri_str;
- gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", address_data[i].port);
+ gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", addr.port);
grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true);
GPR_ASSERT(lb_uri != nullptr);
- grpc_lb_addresses_set_address_from_uri(
- addresses, i, lb_uri, address_data[i].is_balancer,
- address_data[i].balancer_name.c_str(), nullptr);
+ grpc_resolved_address address;
+ GPR_ASSERT(grpc_parse_uri(lb_uri, &address));
+ std::vector<grpc_arg> args_to_add;
+ if (addr.is_balancer) {
+ args_to_add.emplace_back(grpc_channel_arg_integer_create(
+ const_cast<char*>(GRPC_ARG_ADDRESS_IS_BALANCER), 1));
+ args_to_add.emplace_back(grpc_channel_arg_string_create(
+ const_cast<char*>(GRPC_ARG_ADDRESS_BALANCER_NAME),
+ const_cast<char*>(addr.balancer_name.c_str())));
+ }
+ grpc_channel_args* args = grpc_channel_args_copy_and_add(
+ nullptr, args_to_add.data(), args_to_add.size());
+ addresses.emplace_back(address.addr, address.len, args);
grpc_uri_destroy(lb_uri);
gpr_free(lb_uri_str);
}
- grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses);
+ grpc_arg fake_addresses = CreateServerAddressListChannelArg(&addresses);
grpc_channel_args fake_result = {1, &fake_addresses};
response_generator_->SetResponse(&fake_result);
- grpc_lb_addresses_destroy(addresses);
}
void KeepSendingRequests() {
diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc
index 1dfa91a76c..929c2bb589 100644
--- a/test/cpp/end2end/client_lb_end2end_test.cc
+++ b/test/cpp/end2end/client_lb_end2end_test.cc
@@ -35,7 +35,9 @@
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
+#include "src/core/ext/filters/client_channel/parse_address.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/ext/filters/client_channel/subchannel_index.h"
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/gpr/env.h"
@@ -159,24 +161,22 @@ class ClientLbEnd2endTest : public ::testing::Test {
}
grpc_channel_args* BuildFakeResults(const std::vector<int>& ports) {
- grpc_lb_addresses* addresses =
- grpc_lb_addresses_create(ports.size(), nullptr);
- for (size_t i = 0; i < ports.size(); ++i) {
+ grpc_core::ServerAddressList addresses;
+ for (const int& port : ports) {
char* lb_uri_str;
- gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", ports[i]);
+ gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", port);
grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true);
GPR_ASSERT(lb_uri != nullptr);
- grpc_lb_addresses_set_address_from_uri(addresses, i, lb_uri,
- false /* is balancer */,
- "" /* balancer name */, nullptr);
+ grpc_resolved_address address;
+ GPR_ASSERT(grpc_parse_uri(lb_uri, &address));
+ addresses.emplace_back(address.addr, address.len, nullptr /* args */);
grpc_uri_destroy(lb_uri);
gpr_free(lb_uri_str);
}
const grpc_arg fake_addresses =
- grpc_lb_addresses_create_channel_arg(addresses);
+ CreateServerAddressListChannelArg(&addresses);
grpc_channel_args* fake_results =
grpc_channel_args_copy_and_add(nullptr, &fake_addresses, 1);
- grpc_lb_addresses_destroy(addresses);
return fake_results;
}
diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc
index 9c4cd05061..bf990a07b5 100644
--- a/test/cpp/end2end/grpclb_end2end_test.cc
+++ b/test/cpp/end2end/grpclb_end2end_test.cc
@@ -32,7 +32,9 @@
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
+#include "src/core/ext/filters/client_channel/parse_address.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/sockaddr.h"
@@ -486,18 +488,27 @@ class GrpclbEnd2endTest : public ::testing::Test {
grpc::string balancer_name;
};
- grpc_lb_addresses* CreateLbAddressesFromAddressDataList(
+ grpc_core::ServerAddressList CreateLbAddressesFromAddressDataList(
const std::vector<AddressData>& address_data) {
- grpc_lb_addresses* addresses =
- grpc_lb_addresses_create(address_data.size(), nullptr);
- for (size_t i = 0; i < address_data.size(); ++i) {
+ grpc_core::ServerAddressList addresses;
+ for (const auto& addr : address_data) {
char* lb_uri_str;
- gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", address_data[i].port);
+ gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", addr.port);
grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true);
GPR_ASSERT(lb_uri != nullptr);
- grpc_lb_addresses_set_address_from_uri(
- addresses, i, lb_uri, address_data[i].is_balancer,
- address_data[i].balancer_name.c_str(), nullptr);
+ grpc_resolved_address address;
+ GPR_ASSERT(grpc_parse_uri(lb_uri, &address));
+ std::vector<grpc_arg> args_to_add;
+ if (addr.is_balancer) {
+ args_to_add.emplace_back(grpc_channel_arg_integer_create(
+ const_cast<char*>(GRPC_ARG_ADDRESS_IS_BALANCER), 1));
+ args_to_add.emplace_back(grpc_channel_arg_string_create(
+ const_cast<char*>(GRPC_ARG_ADDRESS_BALANCER_NAME),
+ const_cast<char*>(addr.balancer_name.c_str())));
+ }
+ grpc_channel_args* args = grpc_channel_args_copy_and_add(
+ nullptr, args_to_add.data(), args_to_add.size());
+ addresses.emplace_back(address.addr, address.len, args);
grpc_uri_destroy(lb_uri);
gpr_free(lb_uri_str);
}
@@ -506,23 +517,21 @@ class GrpclbEnd2endTest : public ::testing::Test {
void SetNextResolution(const std::vector<AddressData>& address_data) {
grpc_core::ExecCtx exec_ctx;
- grpc_lb_addresses* addresses =
+ grpc_core::ServerAddressList addresses =
CreateLbAddressesFromAddressDataList(address_data);
- grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses);
+ grpc_arg fake_addresses = CreateServerAddressListChannelArg(&addresses);
grpc_channel_args fake_result = {1, &fake_addresses};
response_generator_->SetResponse(&fake_result);
- grpc_lb_addresses_destroy(addresses);
}
void SetNextReresolutionResponse(
const std::vector<AddressData>& address_data) {
grpc_core::ExecCtx exec_ctx;
- grpc_lb_addresses* addresses =
+ grpc_core::ServerAddressList addresses =
CreateLbAddressesFromAddressDataList(address_data);
- grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses);
+ grpc_arg fake_addresses = CreateServerAddressListChannelArg(&addresses);
grpc_channel_args fake_result = {1, &fake_addresses};
response_generator_->SetReresolutionResponse(&fake_result);
- grpc_lb_addresses_destroy(addresses);
}
const std::vector<int> GetBackendPorts(const size_t start_index = 0) const {
diff --git a/test/cpp/naming/address_sorting_test.cc b/test/cpp/naming/address_sorting_test.cc
index 3eb0e7d725..09e705df78 100644
--- a/test/cpp/naming/address_sorting_test.cc
+++ b/test/cpp/naming/address_sorting_test.cc
@@ -37,6 +37,7 @@
#include "src/core/ext/filters/client_channel/resolver.h"
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include "src/core/ext/filters/client_channel/resolver_registry.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
@@ -167,30 +168,26 @@ void OverrideAddressSortingSourceAddrFactory(
address_sorting_override_source_addr_factory_for_testing(factory);
}
-grpc_lb_addresses* BuildLbAddrInputs(std::vector<TestAddress> test_addrs) {
- grpc_lb_addresses* lb_addrs = grpc_lb_addresses_create(0, nullptr);
- lb_addrs->addresses =
- (grpc_lb_address*)gpr_zalloc(sizeof(grpc_lb_address) * test_addrs.size());
- lb_addrs->num_addresses = test_addrs.size();
- for (size_t i = 0; i < test_addrs.size(); i++) {
- lb_addrs->addresses[i].address =
- TestAddressToGrpcResolvedAddress(test_addrs[i]);
+grpc_core::ServerAddressList BuildLbAddrInputs(
+ const std::vector<TestAddress>& test_addrs) {
+ grpc_core::ServerAddressList addresses;
+ for (const auto& addr : test_addrs) {
+ addresses.emplace_back(TestAddressToGrpcResolvedAddress(addr), nullptr);
}
- return lb_addrs;
+ return addresses;
}
-void VerifyLbAddrOutputs(grpc_lb_addresses* lb_addrs,
+void VerifyLbAddrOutputs(const grpc_core::ServerAddressList addresses,
std::vector<std::string> expected_addrs) {
- EXPECT_EQ(lb_addrs->num_addresses, expected_addrs.size());
- for (size_t i = 0; i < lb_addrs->num_addresses; i++) {
+ EXPECT_EQ(addresses.size(), expected_addrs.size());
+ for (size_t i = 0; i < addresses.size(); ++i) {
char* ip_addr_str;
- grpc_sockaddr_to_string(&ip_addr_str, &lb_addrs->addresses[i].address,
+ grpc_sockaddr_to_string(&ip_addr_str, &addresses[i].address(),
false /* normalize */);
EXPECT_EQ(expected_addrs[i], ip_addr_str);
gpr_free(ip_addr_str);
}
grpc_core::ExecCtx exec_ctx;
- grpc_lb_addresses_destroy(lb_addrs);
}
/* We need to run each test case inside of its own
@@ -212,11 +209,11 @@ TEST_F(AddressSortingTest, TestDepriotizesUnreachableAddresses) {
{
{"1.2.3.4:443", {"4.3.2.1:443", AF_INET}},
});
- auto* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"1.2.3.4:443", AF_INET},
{"5.6.7.8:443", AF_INET},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"1.2.3.4:443",
"5.6.7.8:443",
@@ -235,7 +232,7 @@ TEST_F(AddressSortingTest, TestDepriotizesUnsupportedDomainIpv6) {
{"[2607:f8b0:400a:801::1002]:443", AF_INET6},
{"1.2.3.4:443", AF_INET},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"1.2.3.4:443",
"[2607:f8b0:400a:801::1002]:443",
@@ -251,11 +248,11 @@ TEST_F(AddressSortingTest, TestDepriotizesUnsupportedDomainIpv4) {
{"1.2.3.4:443", {"4.3.2.1:0", AF_INET}},
{"[2607:f8b0:400a:801::1002]:443", {"[fec0::1234]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[2607:f8b0:400a:801::1002]:443", AF_INET6},
{"1.2.3.4:443", AF_INET},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[2607:f8b0:400a:801::1002]:443",
"1.2.3.4:443",
@@ -275,11 +272,11 @@ TEST_F(AddressSortingTest, TestDepriotizesNonMatchingScope) {
{"[fec0::5000]:443",
{"[fec0::5001]:0", AF_INET6}}, // site-local and site-local scope
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[2000:f8b0:400a:801::1002]:443", AF_INET6},
{"[fec0::5000]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[fec0::5000]:443",
"[2000:f8b0:400a:801::1002]:443",
@@ -298,11 +295,11 @@ TEST_F(AddressSortingTest, TestUsesLabelFromDefaultTable) {
{"[2001::5001]:443",
{"[2001::5002]:0", AF_INET6}}, // matching labels
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[2002::5001]:443", AF_INET6},
{"[2001::5001]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[2001::5001]:443",
"[2002::5001]:443",
@@ -321,11 +318,11 @@ TEST_F(AddressSortingTest, TestUsesLabelFromDefaultTableInputFlipped) {
{"[2001::5001]:443",
{"[2001::5002]:0", AF_INET6}}, // matching labels
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[2001::5001]:443", AF_INET6},
{"[2002::5001]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[2001::5001]:443",
"[2002::5001]:443",
@@ -344,11 +341,11 @@ TEST_F(AddressSortingTest,
{"[3ffe::5001]:443", {"[3ffe::5002]:0", AF_INET6}},
{"1.2.3.4:443", {"5.6.7.8:0", AF_INET}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe::5001]:443", AF_INET6},
{"1.2.3.4:443", AF_INET},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(
lb_addrs, {
// The AF_INET address should be IPv4-mapped by the sort,
@@ -377,11 +374,11 @@ TEST_F(AddressSortingTest,
{"[::1]:443", {"[::1]:0", AF_INET6}},
{v4_compat_dest, {v4_compat_src, AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{v4_compat_dest, AF_INET6},
{"[::1]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[::1]:443",
v4_compat_dest,
@@ -400,11 +397,11 @@ TEST_F(AddressSortingTest,
{"[1234::2]:443", {"[1234::2]:0", AF_INET6}},
{"[::1]:443", {"[::1]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[1234::2]:443", AF_INET6},
{"[::1]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(
lb_addrs,
{
@@ -424,11 +421,11 @@ TEST_F(AddressSortingTest,
{"[2001::1234]:443", {"[2001::5678]:0", AF_INET6}},
{"[2000::5001]:443", {"[2000::5002]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[2001::1234]:443", AF_INET6},
{"[2000::5001]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(
lb_addrs, {
// The 2000::/16 address should match the ::/0 prefix rule
@@ -448,11 +445,11 @@ TEST_F(
{"[2001::1231]:443", {"[2001::1232]:0", AF_INET6}},
{"[2000::5001]:443", {"[2000::5002]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[2001::1231]:443", AF_INET6},
{"[2000::5001]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[2000::5001]:443",
"[2001::1231]:443",
@@ -469,11 +466,11 @@ TEST_F(AddressSortingTest,
{"[fec0::1234]:443", {"[fec0::5678]:0", AF_INET6}},
{"[fc00::5001]:443", {"[fc00::5002]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[fec0::1234]:443", AF_INET6},
{"[fc00::5001]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[fc00::5001]:443",
"[fec0::1234]:443",
@@ -494,11 +491,11 @@ TEST_F(
{"[::ffff:1.1.1.2]:443", {"[::ffff:1.1.1.3]:0", AF_INET6}},
{"[1234::2]:443", {"[1234::3]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[::ffff:1.1.1.2]:443", AF_INET6},
{"[1234::2]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
// ::ffff:0:2 should match the v4-mapped
// precedence entry and be deprioritized.
@@ -521,11 +518,11 @@ TEST_F(AddressSortingTest, TestPrefersSmallerScope) {
{"[fec0::1234]:443", {"[fec0::5678]:0", AF_INET6}},
{"[3ffe::5001]:443", {"[3ffe::5002]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe::5001]:443", AF_INET6},
{"[fec0::1234]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[fec0::1234]:443",
"[3ffe::5001]:443",
@@ -546,11 +543,11 @@ TEST_F(AddressSortingTest, TestPrefersLongestMatchingSrcDstPrefix) {
{"[3ffe:1234::]:443", {"[3ffe:1235::]:0", AF_INET6}},
{"[3ffe:5001::]:443", {"[3ffe:4321::]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe:5001::]:443", AF_INET6},
{"[3ffe:1234::]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[3ffe:1234::]:443",
"[3ffe:5001::]:443",
@@ -567,11 +564,11 @@ TEST_F(AddressSortingTest,
{"[3ffe::1234]:443", {"[3ffe::1235]:0", AF_INET6}},
{"[3ffe::5001]:443", {"[3ffe::4321]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe::5001]:443", AF_INET6},
{"[3ffe::1234]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[3ffe::1234]:443",
"[3ffe::5001]:443",
@@ -587,11 +584,11 @@ TEST_F(AddressSortingTest, TestPrefersLongestPrefixStressInnerBytePrefix) {
{"[3ffe:8000::]:443", {"[3ffe:C000::]:0", AF_INET6}},
{"[3ffe:2000::]:443", {"[3ffe:3000::]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe:8000::]:443", AF_INET6},
{"[3ffe:2000::]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[3ffe:2000::]:443",
"[3ffe:8000::]:443",
@@ -607,11 +604,11 @@ TEST_F(AddressSortingTest, TestPrefersLongestPrefixDiffersOnHighestBitOfByte) {
{"[3ffe:6::]:443", {"[3ffe:8::]:0", AF_INET6}},
{"[3ffe:c::]:443", {"[3ffe:8::]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe:6::]:443", AF_INET6},
{"[3ffe:c::]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[3ffe:c::]:443",
"[3ffe:6::]:443",
@@ -629,11 +626,11 @@ TEST_F(AddressSortingTest, TestPrefersLongestPrefixDiffersByLastBit) {
{"[3ffe:1111:1111:1110::]:443",
{"[3ffe:1111:1111:1111::]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe:1111:1111:1110::]:443", AF_INET6},
{"[3ffe:1111:1111:1111::]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[3ffe:1111:1111:1111::]:443",
"[3ffe:1111:1111:1110::]:443",
@@ -651,11 +648,11 @@ TEST_F(AddressSortingTest, TestStableSort) {
{"[3ffe::1234]:443", {"[3ffe::1236]:0", AF_INET6}},
{"[3ffe::1235]:443", {"[3ffe::1237]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe::1234]:443", AF_INET6},
{"[3ffe::1235]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[3ffe::1234]:443",
"[3ffe::1235]:443",
@@ -674,14 +671,14 @@ TEST_F(AddressSortingTest, TestStableSortFiveElements) {
{"[3ffe::1234]:443", {"[3ffe::1204]:0", AF_INET6}},
{"[3ffe::1235]:443", {"[3ffe::1205]:0", AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe::1231]:443", AF_INET6},
{"[3ffe::1232]:443", AF_INET6},
{"[3ffe::1233]:443", AF_INET6},
{"[3ffe::1234]:443", AF_INET6},
{"[3ffe::1235]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[3ffe::1231]:443",
"[3ffe::1232]:443",
@@ -695,14 +692,14 @@ TEST_F(AddressSortingTest, TestStableSortNoSrcAddrsExist) {
bool ipv4_supported = true;
bool ipv6_supported = true;
OverrideAddressSortingSourceAddrFactory(ipv4_supported, ipv6_supported, {});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[3ffe::1231]:443", AF_INET6},
{"[3ffe::1232]:443", AF_INET6},
{"[3ffe::1233]:443", AF_INET6},
{"[3ffe::1234]:443", AF_INET6},
{"[3ffe::1235]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[3ffe::1231]:443",
"[3ffe::1232]:443",
@@ -716,11 +713,11 @@ TEST_F(AddressSortingTest, TestStableSortNoSrcAddrsExistWithIpv4) {
bool ipv4_supported = true;
bool ipv6_supported = true;
OverrideAddressSortingSourceAddrFactory(ipv4_supported, ipv6_supported, {});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[::ffff:5.6.7.8]:443", AF_INET6},
{"1.2.3.4:443", AF_INET},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[::ffff:5.6.7.8]:443",
"1.2.3.4:443",
@@ -744,11 +741,11 @@ TEST_F(AddressSortingTest, TestStableSortV4CompatAndSiteLocalAddresses) {
{"[fec0::2000]:443", {"[fec0::2001]:0", AF_INET6}},
{v4_compat_dest, {v4_compat_src, AF_INET6}},
});
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[fec0::2000]:443", AF_INET6},
{v4_compat_dest, AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs,
{
// The sort should be stable since
@@ -765,11 +762,11 @@ TEST_F(AddressSortingTest, TestStableSortV4CompatAndSiteLocalAddresses) {
* (whether ipv4 loopback is available or not, an available ipv6
* loopback should be preferred). */
TEST_F(AddressSortingTest, TestPrefersIpv6Loopback) {
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"[::1]:443", AF_INET6},
{"127.0.0.1:443", AF_INET},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[::1]:443",
"127.0.0.1:443",
@@ -779,11 +776,11 @@ TEST_F(AddressSortingTest, TestPrefersIpv6Loopback) {
/* Flip the order of the inputs above and expect the same output order
* (try to rule out influence of arbitrary qsort ordering) */
TEST_F(AddressSortingTest, TestPrefersIpv6LoopbackInputsFlipped) {
- grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ auto lb_addrs = BuildLbAddrInputs({
{"127.0.0.1:443", AF_INET},
{"[::1]:443", AF_INET6},
});
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ grpc_cares_wrapper_address_sorting_sort(&lb_addrs);
VerifyLbAddrOutputs(lb_addrs, {
"[::1]:443",
"127.0.0.1:443",
diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc
index fe6fcb8d9c..2ac2c237ce 100644
--- a/test/cpp/naming/resolver_component_test.cc
+++ b/test/cpp/naming/resolver_component_test.cc
@@ -41,6 +41,7 @@
#include "src/core/ext/filters/client_channel/resolver.h"
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include "src/core/ext/filters/client_channel/resolver_registry.h"
+#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
@@ -382,23 +383,19 @@ void CheckResolverResultLocked(void* argsp, grpc_error* err) {
EXPECT_EQ(err, GRPC_ERROR_NONE);
ArgsStruct* args = (ArgsStruct*)argsp;
grpc_channel_args* channel_args = args->channel_args;
- const grpc_arg* channel_arg =
- grpc_channel_args_find(channel_args, GRPC_ARG_LB_ADDRESSES);
- GPR_ASSERT(channel_arg != nullptr);
- GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER);
- grpc_lb_addresses* addresses =
- (grpc_lb_addresses*)channel_arg->value.pointer.p;
+ grpc_core::ServerAddressList* addresses =
+ grpc_core::FindServerAddressListChannelArg(channel_args);
gpr_log(GPR_INFO, "num addrs found: %" PRIdPTR ". expected %" PRIdPTR,
- addresses->num_addresses, args->expected_addrs.size());
- GPR_ASSERT(addresses->num_addresses == args->expected_addrs.size());
+ addresses->size(), args->expected_addrs.size());
+ GPR_ASSERT(addresses->size() == args->expected_addrs.size());
std::vector<GrpcLBAddress> found_lb_addrs;
- for (size_t i = 0; i < addresses->num_addresses; i++) {
- grpc_lb_address addr = addresses->addresses[i];
+ for (size_t i = 0; i < addresses->size(); i++) {
+ grpc_core::ServerAddress& addr = (*addresses)[i];
char* str;
- grpc_sockaddr_to_string(&str, &addr.address, 1 /* normalize */);
+ grpc_sockaddr_to_string(&str, &addr.address(), 1 /* normalize */);
gpr_log(GPR_INFO, "%s", str);
found_lb_addrs.emplace_back(
- GrpcLBAddress(std::string(str), addr.is_balancer));
+ GrpcLBAddress(std::string(str), addr.IsBalancer()));
gpr_free(str);
}
if (args->expected_addrs.size() != found_lb_addrs.size()) {