|
|
@ -18,6 +18,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <regex> |
|
|
|
#include <regex> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h> |
|
|
|
#include <gtest/gtest.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <grpc/grpc.h> |
|
|
|
#include <grpc/grpc.h> |
|
|
@ -127,10 +129,10 @@ class ErrorParser : public ServiceConfig::Parser { |
|
|
|
static const char* GlobalError() { return "ErrorParser : globalError"; } |
|
|
|
static const char* GlobalError() { return "ErrorParser : globalError"; } |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void VerifyRegexMatch(grpc_error* error, const std::regex& e) { |
|
|
|
void VerifyRegexMatch(grpc_error* error, const std::regex& regex) { |
|
|
|
std::smatch match; |
|
|
|
std::smatch match; |
|
|
|
std::string s(grpc_error_string(error)); |
|
|
|
std::string error_str = grpc_error_string(error); |
|
|
|
EXPECT_TRUE(std::regex_search(s, match, e)); |
|
|
|
EXPECT_TRUE(std::regex_search(error_str, match, regex)) << error_str; |
|
|
|
GRPC_ERROR_UNREF(error); |
|
|
|
GRPC_ERROR_UNREF(error); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -139,10 +141,10 @@ class ServiceConfigTest : public ::testing::Test { |
|
|
|
void SetUp() override { |
|
|
|
void SetUp() override { |
|
|
|
ServiceConfig::Shutdown(); |
|
|
|
ServiceConfig::Shutdown(); |
|
|
|
ServiceConfig::Init(); |
|
|
|
ServiceConfig::Init(); |
|
|
|
EXPECT_TRUE( |
|
|
|
EXPECT_EQ(ServiceConfig::RegisterParser(absl::make_unique<TestParser1>()), |
|
|
|
ServiceConfig::RegisterParser(absl::make_unique<TestParser1>()) == 0); |
|
|
|
0); |
|
|
|
EXPECT_TRUE( |
|
|
|
EXPECT_EQ(ServiceConfig::RegisterParser(absl::make_unique<TestParser2>()), |
|
|
|
ServiceConfig::RegisterParser(absl::make_unique<TestParser2>()) == 1); |
|
|
|
1); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -150,46 +152,128 @@ TEST_F(ServiceConfigTest, ErrorCheck1) { |
|
|
|
const char* test_json = ""; |
|
|
|
const char* test_json = ""; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex(std::string("JSON parse error")); |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
std::regex e(std::string("JSON parse error")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, BasicTest1) { |
|
|
|
TEST_F(ServiceConfigTest, BasicTest1) { |
|
|
|
const char* test_json = "{}"; |
|
|
|
const char* test_json = "{}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
EXPECT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
EXPECT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, SkipMethodConfigWithNoNameOrEmptyName) { |
|
|
|
|
|
|
|
const char* test_json = |
|
|
|
|
|
|
|
"{\"methodConfig\": [" |
|
|
|
|
|
|
|
" {\"method_param\":1}," |
|
|
|
|
|
|
|
" {\"name\":[], \"method_param\":1}," |
|
|
|
|
|
|
|
" {\"name\":[{\"service\":\"TestServ\"}], \"method_param\":2}" |
|
|
|
|
|
|
|
"]}"; |
|
|
|
|
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
|
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
|
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
|
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
|
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
|
|
|
|
ASSERT_NE(vector_ptr, nullptr); |
|
|
|
|
|
|
|
auto parsed_config = ((*vector_ptr)[1]).get(); |
|
|
|
|
|
|
|
EXPECT_EQ(static_cast<TestParsedConfig1*>(parsed_config)->value(), 2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, ErrorDuplicateMethodConfigNames) { |
|
|
|
|
|
|
|
const char* test_json = |
|
|
|
|
|
|
|
"{\"methodConfig\": [" |
|
|
|
|
|
|
|
" {\"name\":[{\"service\":\"TestServ\"}]}," |
|
|
|
|
|
|
|
" {\"name\":[{\"service\":\"TestServ\"}]}" |
|
|
|
|
|
|
|
"]}"; |
|
|
|
|
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
|
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
|
|
|
|
std::regex regex( |
|
|
|
|
|
|
|
std::string("Service config parsing error.*referenced_errors" |
|
|
|
|
|
|
|
".*Method Params.*referenced_errors" |
|
|
|
|
|
|
|
".*methodConfig.*referenced_errors" |
|
|
|
|
|
|
|
".*multiple method configs with same name")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, ErrorNoNames) { |
|
|
|
TEST_F(ServiceConfigTest, ErrorDuplicateMethodConfigNamesWithNullMethod) { |
|
|
|
const char* test_json = "{\"methodConfig\": [{\"blah\":1}]}"; |
|
|
|
const char* test_json = |
|
|
|
|
|
|
|
"{\"methodConfig\": [" |
|
|
|
|
|
|
|
" {\"name\":[{\"service\":\"TestServ\",\"method\":null}]}," |
|
|
|
|
|
|
|
" {\"name\":[{\"service\":\"TestServ\"}]}" |
|
|
|
|
|
|
|
"]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
std::string("Service config parsing error.*referenced_errors" |
|
|
|
std::regex e( |
|
|
|
".*Method Params.*referenced_errors" |
|
|
|
std::string("(Service config parsing error)(.*)(referenced_errors)" |
|
|
|
".*methodConfig.*referenced_errors" |
|
|
|
"(.*)(Method Params)(.*)(referenced_errors)" |
|
|
|
".*multiple method configs with same name")); |
|
|
|
"(.*)(methodConfig)(.*)(referenced_errors)" |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"(.*)(No names specified)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, ErrorNoNamesWithMultipleMethodConfigs) { |
|
|
|
TEST_F(ServiceConfigTest, ErrorDuplicateMethodConfigNamesWithEmptyMethod) { |
|
|
|
const char* test_json = |
|
|
|
const char* test_json = |
|
|
|
"{\"methodConfig\": [{}, {\"name\":[{\"service\":\"TestServ\"}]}]}"; |
|
|
|
"{\"methodConfig\": [" |
|
|
|
|
|
|
|
" {\"name\":[{\"service\":\"TestServ\",\"method\":\"\"}]}," |
|
|
|
|
|
|
|
" {\"name\":[{\"service\":\"TestServ\"}]}" |
|
|
|
|
|
|
|
"]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
std::string("Service config parsing error.*referenced_errors" |
|
|
|
std::regex e( |
|
|
|
".*Method Params.*referenced_errors" |
|
|
|
std::string("(Service config parsing error)(.*)(referenced_errors)" |
|
|
|
".*methodConfig.*referenced_errors" |
|
|
|
"(.*)(Method Params)(.*)(referenced_errors)" |
|
|
|
".*multiple method configs with same name")); |
|
|
|
"(.*)(methodConfig)(.*)(referenced_errors)" |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"(.*)(No names specified)")); |
|
|
|
} |
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, ErrorDuplicateDefaultMethodConfigs) { |
|
|
|
|
|
|
|
const char* test_json = |
|
|
|
|
|
|
|
"{\"methodConfig\": [" |
|
|
|
|
|
|
|
" {\"name\":[{}]}," |
|
|
|
|
|
|
|
" {\"name\":[{}]}" |
|
|
|
|
|
|
|
"]}"; |
|
|
|
|
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
|
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
|
|
|
|
std::regex regex( |
|
|
|
|
|
|
|
std::string("Service config parsing error.*referenced_errors" |
|
|
|
|
|
|
|
".*Method Params.*referenced_errors" |
|
|
|
|
|
|
|
".*methodConfig.*referenced_errors" |
|
|
|
|
|
|
|
".*multiple default method configs")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, ErrorDuplicateDefaultMethodConfigsWithNullService) { |
|
|
|
|
|
|
|
const char* test_json = |
|
|
|
|
|
|
|
"{\"methodConfig\": [" |
|
|
|
|
|
|
|
" {\"name\":[{\"service\":null}]}," |
|
|
|
|
|
|
|
" {\"name\":[{}]}" |
|
|
|
|
|
|
|
"]}"; |
|
|
|
|
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
|
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
|
|
|
|
std::regex regex( |
|
|
|
|
|
|
|
std::string("Service config parsing error.*referenced_errors" |
|
|
|
|
|
|
|
".*Method Params.*referenced_errors" |
|
|
|
|
|
|
|
".*methodConfig.*referenced_errors" |
|
|
|
|
|
|
|
".*multiple default method configs")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, ErrorDuplicateDefaultMethodConfigsWithEmptyService) { |
|
|
|
|
|
|
|
const char* test_json = |
|
|
|
|
|
|
|
"{\"methodConfig\": [" |
|
|
|
|
|
|
|
" {\"name\":[{\"service\":\"\"}]}," |
|
|
|
|
|
|
|
" {\"name\":[{}]}" |
|
|
|
|
|
|
|
"]}"; |
|
|
|
|
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
|
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
|
|
|
|
std::regex regex( |
|
|
|
|
|
|
|
std::string("Service config parsing error.*referenced_errors" |
|
|
|
|
|
|
|
".*Method Params.*referenced_errors" |
|
|
|
|
|
|
|
".*methodConfig.*referenced_errors" |
|
|
|
|
|
|
|
".*multiple default method configs")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, ValidMethodConfig) { |
|
|
|
TEST_F(ServiceConfigTest, ValidMethodConfig) { |
|
|
@ -197,19 +281,19 @@ TEST_F(ServiceConfigTest, ValidMethodConfig) { |
|
|
|
"{\"methodConfig\": [{\"name\":[{\"service\":\"TestServ\"}]}]}"; |
|
|
|
"{\"methodConfig\": [{\"name\":[{\"service\":\"TestServ\"}]}]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
EXPECT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
EXPECT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, Parser1BasicTest1) { |
|
|
|
TEST_F(ServiceConfigTest, Parser1BasicTest1) { |
|
|
|
const char* test_json = "{\"global_param\":5}"; |
|
|
|
const char* test_json = "{\"global_param\":5}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
EXPECT_TRUE( |
|
|
|
EXPECT_EQ((static_cast<TestParsedConfig1*>(svc_cfg->GetGlobalParsedConfig(0))) |
|
|
|
(static_cast<TestParsedConfig1*>(svc_cfg->GetGlobalParsedConfig(0))) |
|
|
|
->value(), |
|
|
|
->value() == 5); |
|
|
|
5); |
|
|
|
EXPECT_TRUE(svc_cfg->GetMethodParsedConfigVector( |
|
|
|
EXPECT_EQ(svc_cfg->GetMethodParsedConfigVector( |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")) == |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")), |
|
|
|
nullptr); |
|
|
|
nullptr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -217,36 +301,32 @@ TEST_F(ServiceConfigTest, Parser1BasicTest2) { |
|
|
|
const char* test_json = "{\"global_param\":1000}"; |
|
|
|
const char* test_json = "{\"global_param\":1000}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
EXPECT_TRUE( |
|
|
|
EXPECT_EQ((static_cast<TestParsedConfig1*>(svc_cfg->GetGlobalParsedConfig(0))) |
|
|
|
(static_cast<TestParsedConfig1*>(svc_cfg->GetGlobalParsedConfig(0))) |
|
|
|
->value(), |
|
|
|
->value() == 1000); |
|
|
|
1000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, Parser1ErrorInvalidType) { |
|
|
|
TEST_F(ServiceConfigTest, Parser1ErrorInvalidType) { |
|
|
|
const char* test_json = "{\"global_param\":\"5\"}"; |
|
|
|
const char* test_json = "{\"global_param\":\"5\"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
absl::StrCat("Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e(std::string("(Service config parsing " |
|
|
|
"Global Params.*referenced_errors.*", |
|
|
|
"error)(.*)(referenced_errors)(.*)(Global " |
|
|
|
TestParser1::InvalidTypeErrorMessage())); |
|
|
|
"Params)(.*)(referenced_errors)(.*)") + |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
TestParser1::InvalidTypeErrorMessage()); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, Parser1ErrorInvalidValue) { |
|
|
|
TEST_F(ServiceConfigTest, Parser1ErrorInvalidValue) { |
|
|
|
const char* test_json = "{\"global_param\":-5}"; |
|
|
|
const char* test_json = "{\"global_param\":-5}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
absl::StrCat("Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e(std::string("(Service config parsing " |
|
|
|
"Global Params.*referenced_errors.*", |
|
|
|
"error)(.*)(referenced_errors)(.*)(Global " |
|
|
|
TestParser1::InvalidValueErrorMessage())); |
|
|
|
"Params)(.*)(referenced_errors)(.*)") + |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
TestParser1::InvalidValueErrorMessage()); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, Parser2BasicTest) { |
|
|
|
TEST_F(ServiceConfigTest, Parser2BasicTest) { |
|
|
@ -255,12 +335,12 @@ TEST_F(ServiceConfigTest, Parser2BasicTest) { |
|
|
|
"\"method_param\":5}]}"; |
|
|
|
"\"method_param\":5}]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
EXPECT_TRUE(vector_ptr != nullptr); |
|
|
|
ASSERT_NE(vector_ptr, nullptr); |
|
|
|
auto parsed_config = ((*vector_ptr)[1]).get(); |
|
|
|
auto parsed_config = ((*vector_ptr)[1]).get(); |
|
|
|
EXPECT_TRUE(static_cast<TestParsedConfig1*>(parsed_config)->value() == 5); |
|
|
|
EXPECT_EQ(static_cast<TestParsedConfig1*>(parsed_config)->value(), 5); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, Parser2ErrorInvalidType) { |
|
|
|
TEST_F(ServiceConfigTest, Parser2ErrorInvalidType) { |
|
|
@ -269,14 +349,12 @@ TEST_F(ServiceConfigTest, Parser2ErrorInvalidType) { |
|
|
|
"\"method_param\":\"5\"}]}"; |
|
|
|
"\"method_param\":\"5\"}]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
std::regex regex( |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
absl::StrCat("Service config parsing error.*referenced_errors\":\\[.*" |
|
|
|
std::regex e(std::string("(Service config parsing " |
|
|
|
"Method Params.*referenced_errors.*methodConfig.*" |
|
|
|
"error)(.*)(referenced_errors\":\\[)(.*)(Method " |
|
|
|
"referenced_errors.*", |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(" |
|
|
|
TestParser2::InvalidTypeErrorMessage())); |
|
|
|
".*)(referenced_errors)(.*)") + |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
TestParser2::InvalidTypeErrorMessage()); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ServiceConfigTest, Parser2ErrorInvalidValue) { |
|
|
|
TEST_F(ServiceConfigTest, Parser2ErrorInvalidValue) { |
|
|
@ -285,14 +363,12 @@ TEST_F(ServiceConfigTest, Parser2ErrorInvalidValue) { |
|
|
|
"\"method_param\":-5}]}"; |
|
|
|
"\"method_param\":-5}]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
std::regex regex( |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
absl::StrCat("Service config parsing error.*referenced_errors\":\\[.*" |
|
|
|
std::regex e(std::string("(Service config parsing " |
|
|
|
"Method Params.*referenced_errors.*methodConfig.*" |
|
|
|
"error)(.*)(referenced_errors\":\\[)(.*)(Method " |
|
|
|
"referenced_errors.*", |
|
|
|
"Params)(.*)(referenced_errors)()(.*)(methodConfig)(" |
|
|
|
TestParser2::InvalidValueErrorMessage())); |
|
|
|
".*)(referenced_errors)(.*)") + |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
TestParser2::InvalidValueErrorMessage()); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Test parsing with ErrorParsers which always add errors
|
|
|
|
// Test parsing with ErrorParsers which always add errors
|
|
|
@ -301,10 +377,10 @@ class ErroredParsersScopingTest : public ::testing::Test { |
|
|
|
void SetUp() override { |
|
|
|
void SetUp() override { |
|
|
|
ServiceConfig::Shutdown(); |
|
|
|
ServiceConfig::Shutdown(); |
|
|
|
ServiceConfig::Init(); |
|
|
|
ServiceConfig::Init(); |
|
|
|
EXPECT_TRUE( |
|
|
|
EXPECT_EQ(ServiceConfig::RegisterParser(absl::make_unique<ErrorParser>()), |
|
|
|
ServiceConfig::RegisterParser(absl::make_unique<ErrorParser>()) == 0); |
|
|
|
0); |
|
|
|
EXPECT_TRUE( |
|
|
|
EXPECT_EQ(ServiceConfig::RegisterParser(absl::make_unique<ErrorParser>()), |
|
|
|
ServiceConfig::RegisterParser(absl::make_unique<ErrorParser>()) == 1); |
|
|
|
1); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -312,33 +388,24 @@ TEST_F(ErroredParsersScopingTest, GlobalParams) { |
|
|
|
const char* test_json = "{}"; |
|
|
|
const char* test_json = "{}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
std::regex regex(absl::StrCat( |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
"Service config parsing error.*referenced_errors\":\\[.*" |
|
|
|
std::regex e(std::string("(Service config parsing " |
|
|
|
"Global Params.*referenced_errors.*", |
|
|
|
"error)(.*)(referenced_errors\":\\[)(.*)(Global " |
|
|
|
ErrorParser::GlobalError(), ".*", ErrorParser::GlobalError())); |
|
|
|
"Params)(.*)(referenced_errors)()(.*)") + |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
ErrorParser::GlobalError() + std::string("(.*)") + |
|
|
|
|
|
|
|
ErrorParser::GlobalError()); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ErroredParsersScopingTest, MethodParams) { |
|
|
|
TEST_F(ErroredParsersScopingTest, MethodParams) { |
|
|
|
const char* test_json = "{\"methodConfig\": [{}]}"; |
|
|
|
const char* test_json = "{\"methodConfig\": [{}]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
std::regex regex(absl::StrCat( |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
"Service config parsing error.*referenced_errors\":\\[.*" |
|
|
|
std::regex e(std::string("(Service config parsing " |
|
|
|
"Global Params.*referenced_errors.*", |
|
|
|
"error)(.*)(referenced_errors\":\\[)(.*)(Global " |
|
|
|
ErrorParser::GlobalError(), ".*", ErrorParser::GlobalError(), |
|
|
|
"Params)(.*)(referenced_errors)()(.*)") + |
|
|
|
".*Method Params.*referenced_errors.*methodConfig.*referenced_errors.*", |
|
|
|
ErrorParser::GlobalError() + std::string("(.*)") + |
|
|
|
ErrorParser::MethodError(), ".*", ErrorParser::MethodError())); |
|
|
|
ErrorParser::GlobalError() + |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
std::string("(.*)(Method Params)(.*)(referenced_errors)" |
|
|
|
|
|
|
|
"(.*)(methodConfig)(.*)(referenced_errors)(.*)") + |
|
|
|
|
|
|
|
ErrorParser::MethodError() + std::string("(.*)") + |
|
|
|
|
|
|
|
ErrorParser::MethodError() + |
|
|
|
|
|
|
|
std::string("(.*)(No names specified)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class ClientChannelParserTest : public ::testing::Test { |
|
|
|
class ClientChannelParserTest : public ::testing::Test { |
|
|
@ -346,9 +413,9 @@ class ClientChannelParserTest : public ::testing::Test { |
|
|
|
void SetUp() override { |
|
|
|
void SetUp() override { |
|
|
|
ServiceConfig::Shutdown(); |
|
|
|
ServiceConfig::Shutdown(); |
|
|
|
ServiceConfig::Init(); |
|
|
|
ServiceConfig::Init(); |
|
|
|
EXPECT_TRUE( |
|
|
|
EXPECT_EQ( |
|
|
|
ServiceConfig::RegisterParser( |
|
|
|
ServiceConfig::RegisterParser( |
|
|
|
absl::make_unique<internal::ClientChannelServiceConfigParser>()) == |
|
|
|
absl::make_unique<internal::ClientChannelServiceConfigParser>()), |
|
|
|
0); |
|
|
|
0); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -357,12 +424,12 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigPickFirst) { |
|
|
|
const char* test_json = "{\"loadBalancingConfig\": [{\"pick_first\":{}}]}"; |
|
|
|
const char* test_json = "{\"loadBalancingConfig\": [{\"pick_first\":{}}]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
const auto* parsed_config = |
|
|
|
const auto* parsed_config = |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
auto lb_config = parsed_config->parsed_lb_config(); |
|
|
|
auto lb_config = parsed_config->parsed_lb_config(); |
|
|
|
EXPECT_TRUE(strcmp(lb_config->name(), "pick_first") == 0); |
|
|
|
EXPECT_STREQ(lb_config->name(), "pick_first"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigRoundRobin) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigRoundRobin) { |
|
|
@ -370,12 +437,12 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigRoundRobin) { |
|
|
|
"{\"loadBalancingConfig\": [{\"round_robin\":{}}, {}]}"; |
|
|
|
"{\"loadBalancingConfig\": [{\"round_robin\":{}}, {}]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
auto parsed_config = |
|
|
|
auto parsed_config = |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
auto lb_config = parsed_config->parsed_lb_config(); |
|
|
|
auto lb_config = parsed_config->parsed_lb_config(); |
|
|
|
EXPECT_TRUE(strcmp(lb_config->name(), "round_robin") == 0); |
|
|
|
EXPECT_STREQ(lb_config->name(), "round_robin"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigGrpclb) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigGrpclb) { |
|
|
@ -384,12 +451,12 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigGrpclb) { |
|
|
|
"[{\"grpclb\":{\"childPolicy\":[{\"pick_first\":{}}]}}]}"; |
|
|
|
"[{\"grpclb\":{\"childPolicy\":[{\"pick_first\":{}}]}}]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
const auto* parsed_config = |
|
|
|
const auto* parsed_config = |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
auto lb_config = parsed_config->parsed_lb_config(); |
|
|
|
auto lb_config = parsed_config->parsed_lb_config(); |
|
|
|
EXPECT_TRUE(strcmp(lb_config->name(), "grpclb") == 0); |
|
|
|
EXPECT_STREQ(lb_config->name(), "grpclb"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigXds) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigXds) { |
|
|
@ -402,105 +469,91 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigXds) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
|
|
|
|
const auto* parsed_config = |
|
|
|
const auto* parsed_config = |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
auto lb_config = parsed_config->parsed_lb_config(); |
|
|
|
auto lb_config = parsed_config->parsed_lb_config(); |
|
|
|
EXPECT_TRUE(strcmp(lb_config->name(), "xds_experimental") == 0); |
|
|
|
EXPECT_STREQ(lb_config->name(), "xds_experimental"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, UnknownLoadBalancingConfig) { |
|
|
|
TEST_F(ClientChannelParserTest, UnknownLoadBalancingConfig) { |
|
|
|
const char* test_json = "{\"loadBalancingConfig\": [{\"unknown\":{}}]}"; |
|
|
|
const char* test_json = "{\"loadBalancingConfig\": [{\"unknown\":{}}]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Global Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing error)(.*)(referenced_errors)" |
|
|
|
"Client channel global parser.*referenced_errors.*" |
|
|
|
"(.*)(Global Params)(.*)(referenced_errors)" |
|
|
|
"field:loadBalancingConfig.*referenced_errors.*" |
|
|
|
"(.*)(Client channel global parser)(.*)(referenced_errors)" |
|
|
|
"No known policy"); |
|
|
|
"(.*)(field:loadBalancingConfig)(.*)(referenced_errors)" |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"(.*)(No known policy)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, InvalidGrpclbLoadBalancingConfig) { |
|
|
|
TEST_F(ClientChannelParserTest, InvalidGrpclbLoadBalancingConfig) { |
|
|
|
const char* test_json = |
|
|
|
const char* test_json = |
|
|
|
"{\"loadBalancingConfig\": " |
|
|
|
"{\"loadBalancingConfig\": [" |
|
|
|
"[{\"grpclb\":{\"childPolicy\":[{\"unknown\":{}}]}}]}"; |
|
|
|
" {\"grpclb\":{\"childPolicy\":1}}," |
|
|
|
|
|
|
|
" {\"round_robin\":{}}" |
|
|
|
|
|
|
|
"]}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Global Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing error)(.*)(referenced_errors)" |
|
|
|
"Client channel global parser.*referenced_errors.*" |
|
|
|
"(.*)(Global Params)(.*)(referenced_errors)" |
|
|
|
"field:loadBalancingConfig.*referenced_errors.*" |
|
|
|
"(.*)(Client channel global parser)(.*)(referenced_errors)" |
|
|
|
"GrpcLb Parser.*referenced_errors.*" |
|
|
|
"(.*)(field:loadBalancingConfig)(.*)(referenced_errors)" |
|
|
|
"field:childPolicy.*referenced_errors.*" |
|
|
|
"(.*)(GrpcLb Parser)(.*)(referenced_errors)" |
|
|
|
"type should be array"); |
|
|
|
"(.*)(field:childPolicy)(.*)(referenced_errors)" |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"(.*)(No known policy)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingPolicy) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingPolicy) { |
|
|
|
const char* test_json = "{\"loadBalancingPolicy\":\"pick_first\"}"; |
|
|
|
const char* test_json = "{\"loadBalancingPolicy\":\"pick_first\"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
const auto* parsed_config = |
|
|
|
const auto* parsed_config = |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
const auto* lb_policy = parsed_config->parsed_deprecated_lb_policy(); |
|
|
|
EXPECT_EQ(parsed_config->parsed_deprecated_lb_policy(), "pick_first"); |
|
|
|
ASSERT_TRUE(lb_policy != nullptr); |
|
|
|
|
|
|
|
EXPECT_TRUE(strcmp(lb_policy, "pick_first") == 0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingPolicyAllCaps) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidLoadBalancingPolicyAllCaps) { |
|
|
|
const char* test_json = "{\"loadBalancingPolicy\":\"PICK_FIRST\"}"; |
|
|
|
const char* test_json = "{\"loadBalancingPolicy\":\"PICK_FIRST\"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
|
|
|
|
const auto* parsed_config = |
|
|
|
const auto* parsed_config = |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
const auto* lb_policy = parsed_config->parsed_deprecated_lb_policy(); |
|
|
|
EXPECT_EQ(parsed_config->parsed_deprecated_lb_policy(), "pick_first"); |
|
|
|
ASSERT_TRUE(lb_policy != nullptr); |
|
|
|
|
|
|
|
EXPECT_TRUE(strcmp(lb_policy, "pick_first") == 0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, UnknownLoadBalancingPolicy) { |
|
|
|
TEST_F(ClientChannelParserTest, UnknownLoadBalancingPolicy) { |
|
|
|
const char* test_json = "{\"loadBalancingPolicy\":\"unknown\"}"; |
|
|
|
const char* test_json = "{\"loadBalancingPolicy\":\"unknown\"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Global Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing " |
|
|
|
"Client channel global parser.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Global " |
|
|
|
"field:loadBalancingPolicy error:Unknown lb policy"); |
|
|
|
"Params)(.*)(referenced_errors)(.*)(Client channel global " |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(field:" |
|
|
|
|
|
|
|
"loadBalancingPolicy error:Unknown lb policy)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, LoadBalancingPolicyXdsNotAllowed) { |
|
|
|
TEST_F(ClientChannelParserTest, LoadBalancingPolicyXdsNotAllowed) { |
|
|
|
const char* test_json = "{\"loadBalancingPolicy\":\"xds_experimental\"}"; |
|
|
|
const char* test_json = "{\"loadBalancingPolicy\":\"xds_experimental\"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Global Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing " |
|
|
|
"Client channel global parser.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Global " |
|
|
|
"field:loadBalancingPolicy error:xds_experimental requires " |
|
|
|
"Params)(.*)(referenced_errors)(.*)(Client channel global " |
|
|
|
"a config. Please use loadBalancingConfig instead."); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(field:" |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"loadBalancingPolicy error:xds_experimental requires a " |
|
|
|
|
|
|
|
"config. Please use loadBalancingConfig instead.)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidRetryThrottling) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidRetryThrottling) { |
|
|
@ -513,8 +566,7 @@ TEST_F(ClientChannelParserTest, ValidRetryThrottling) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
|
|
|
|
const auto* parsed_config = |
|
|
|
const auto* parsed_config = |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
@ -532,16 +584,13 @@ TEST_F(ClientChannelParserTest, RetryThrottlingMissingFields) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Global Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing " |
|
|
|
"Client channel global parser.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Global " |
|
|
|
"field:retryThrottling field:maxTokens error:Not found.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(Client channel global " |
|
|
|
"field:retryThrottling field:tokenRatio error:Not found"); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(field:retryThrottling " |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"field:maxTokens error:Not found)(.*)(field:retryThrottling " |
|
|
|
|
|
|
|
"field:tokenRatio error:Not found)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryThrottlingNegativeMaxTokens) { |
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryThrottlingNegativeMaxTokens) { |
|
|
@ -554,15 +603,13 @@ TEST_F(ClientChannelParserTest, InvalidRetryThrottlingNegativeMaxTokens) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Global Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing " |
|
|
|
"Client channel global parser.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Global " |
|
|
|
"field:retryThrottling field:maxTokens error:should " |
|
|
|
"Params)(.*)(referenced_errors)(.*)(Client channel global " |
|
|
|
"be greater than zero"); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(field:retryThrottling " |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"field:maxTokens error:should be greater than zero)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryThrottlingInvalidTokenRatio) { |
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryThrottlingInvalidTokenRatio) { |
|
|
@ -575,15 +622,13 @@ TEST_F(ClientChannelParserTest, InvalidRetryThrottlingInvalidTokenRatio) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Global Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing " |
|
|
|
"Client channel global parser.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Global " |
|
|
|
"field:retryThrottling field:tokenRatio " |
|
|
|
"Params)(.*)(referenced_errors)(.*)(Client channel global " |
|
|
|
"error:Failed parsing"); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(field:retryThrottling " |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"field:tokenRatio error:Failed parsing)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidTimeout) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidTimeout) { |
|
|
@ -598,10 +643,10 @@ TEST_F(ClientChannelParserTest, ValidTimeout) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
EXPECT_TRUE(vector_ptr != nullptr); |
|
|
|
ASSERT_NE(vector_ptr, nullptr); |
|
|
|
auto parsed_config = ((*vector_ptr)[0]).get(); |
|
|
|
auto parsed_config = ((*vector_ptr)[0]).get(); |
|
|
|
EXPECT_EQ((static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>( |
|
|
|
EXPECT_EQ((static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>( |
|
|
|
parsed_config)) |
|
|
|
parsed_config)) |
|
|
@ -621,16 +666,13 @@ TEST_F(ClientChannelParserTest, InvalidTimeout) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Method Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing " |
|
|
|
"methodConfig.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Method " |
|
|
|
"Client channel parser.*referenced_errors.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(.*)(" |
|
|
|
"field:timeout error:Failed parsing"); |
|
|
|
"referenced_errors)(.*)(Client channel " |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(field:timeout " |
|
|
|
|
|
|
|
"error:Failed parsing)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidWaitForReady) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidWaitForReady) { |
|
|
@ -645,12 +687,12 @@ TEST_F(ClientChannelParserTest, ValidWaitForReady) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
EXPECT_TRUE(vector_ptr != nullptr); |
|
|
|
ASSERT_NE(vector_ptr, nullptr); |
|
|
|
auto parsed_config = ((*vector_ptr)[0]).get(); |
|
|
|
auto parsed_config = ((*vector_ptr)[0]).get(); |
|
|
|
EXPECT_TRUE( |
|
|
|
ASSERT_TRUE( |
|
|
|
(static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>( |
|
|
|
(static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>( |
|
|
|
parsed_config)) |
|
|
|
parsed_config)) |
|
|
|
->wait_for_ready() |
|
|
|
->wait_for_ready() |
|
|
@ -674,16 +716,13 @@ TEST_F(ClientChannelParserTest, InvalidWaitForReady) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Method Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing " |
|
|
|
"methodConfig.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Method " |
|
|
|
"Client channel parser.*referenced_errors.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(.*)(" |
|
|
|
"field:waitForReady error:Type should be true/false"); |
|
|
|
"referenced_errors)(.*)(Client channel " |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(field:waitForReady " |
|
|
|
|
|
|
|
"error:Type should be true/false)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidRetryPolicy) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidRetryPolicy) { |
|
|
@ -704,15 +743,14 @@ TEST_F(ClientChannelParserTest, ValidRetryPolicy) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
|
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
EXPECT_TRUE(vector_ptr != nullptr); |
|
|
|
ASSERT_NE(vector_ptr, nullptr); |
|
|
|
const auto* parsed_config = |
|
|
|
const auto* parsed_config = |
|
|
|
static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>( |
|
|
|
static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>( |
|
|
|
((*vector_ptr)[0]).get()); |
|
|
|
((*vector_ptr)[0]).get()); |
|
|
|
EXPECT_TRUE(parsed_config->retry_policy() != nullptr); |
|
|
|
ASSERT_NE(parsed_config->retry_policy(), nullptr); |
|
|
|
EXPECT_EQ(parsed_config->retry_policy()->max_attempts, 3); |
|
|
|
EXPECT_EQ(parsed_config->retry_policy()->max_attempts, 3); |
|
|
|
EXPECT_EQ(parsed_config->retry_policy()->initial_backoff, 1000); |
|
|
|
EXPECT_EQ(parsed_config->retry_policy()->initial_backoff, 1000); |
|
|
|
EXPECT_EQ(parsed_config->retry_policy()->max_backoff, 120000); |
|
|
|
EXPECT_EQ(parsed_config->retry_policy()->max_backoff, 120000); |
|
|
@ -739,16 +777,14 @@ TEST_F(ClientChannelParserTest, InvalidRetryPolicyMaxAttempts) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e(std::string( |
|
|
|
"Method Params.*referenced_errors.*" |
|
|
|
"(Service config parsing " |
|
|
|
"methodConfig.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Method " |
|
|
|
"Client channel parser.*referenced_errors.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(.*)(referenced_errors)(" |
|
|
|
"retryPolicy.*referenced_errors.*" |
|
|
|
".*)(Client channel " |
|
|
|
"field:maxAttempts error:should be at least 2"); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(retryPolicy)(.*)(referenced_errors)(." |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"*)(field:maxAttempts error:should be at least 2)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryPolicyInitialBackoff) { |
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryPolicyInitialBackoff) { |
|
|
@ -769,16 +805,14 @@ TEST_F(ClientChannelParserTest, InvalidRetryPolicyInitialBackoff) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e(std::string( |
|
|
|
"Method Params.*referenced_errors.*" |
|
|
|
"(Service config parsing " |
|
|
|
"methodConfig.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Method " |
|
|
|
"Client channel parser.*referenced_errors.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(.*)(referenced_errors)(" |
|
|
|
"retryPolicy.*referenced_errors.*" |
|
|
|
".*)(Client channel " |
|
|
|
"field:initialBackoff error:Failed to parse"); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(retryPolicy)(.*)(referenced_errors)(." |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"*)(field:initialBackoff error:Failed to parse)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryPolicyMaxBackoff) { |
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryPolicyMaxBackoff) { |
|
|
@ -799,16 +833,14 @@ TEST_F(ClientChannelParserTest, InvalidRetryPolicyMaxBackoff) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e(std::string( |
|
|
|
"Method Params.*referenced_errors.*" |
|
|
|
"(Service config parsing " |
|
|
|
"methodConfig.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Method " |
|
|
|
"Client channel parser.*referenced_errors.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(.*)(referenced_errors)(" |
|
|
|
"retryPolicy.*referenced_errors.*" |
|
|
|
".*)(Client channel " |
|
|
|
"field:maxBackoff error:failed to parse"); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(retryPolicy)(.*)(referenced_errors)(." |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"*)(field:maxBackoff error:failed to parse)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryPolicyBackoffMultiplier) { |
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryPolicyBackoffMultiplier) { |
|
|
@ -829,16 +861,14 @@ TEST_F(ClientChannelParserTest, InvalidRetryPolicyBackoffMultiplier) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e(std::string( |
|
|
|
"Method Params.*referenced_errors.*" |
|
|
|
"(Service config parsing " |
|
|
|
"methodConfig.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Method " |
|
|
|
"Client channel parser.*referenced_errors.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(.*)(referenced_errors)(" |
|
|
|
"retryPolicy.*referenced_errors.*" |
|
|
|
".*)(Client channel " |
|
|
|
"field:backoffMultiplier error:should be of type number"); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(retryPolicy)(.*)(referenced_errors)(." |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"*)(field:backoffMultiplier error:should be of type number)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryPolicyRetryableStatusCodes) { |
|
|
|
TEST_F(ClientChannelParserTest, InvalidRetryPolicyRetryableStatusCodes) { |
|
|
@ -859,16 +889,14 @@ TEST_F(ClientChannelParserTest, InvalidRetryPolicyRetryableStatusCodes) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e(std::string( |
|
|
|
"Method Params.*referenced_errors.*" |
|
|
|
"(Service config parsing " |
|
|
|
"methodConfig.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Method " |
|
|
|
"Client channel parser.*referenced_errors.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(.*)(referenced_errors)(" |
|
|
|
"retryPolicy.*referenced_errors.*" |
|
|
|
".*)(Client channel " |
|
|
|
"field:retryableStatusCodes error:should be non-empty"); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(retryPolicy)(.*)(referenced_errors)(." |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"*)(field:retryableStatusCodes error:should be non-empty)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, ValidHealthCheck) { |
|
|
|
TEST_F(ClientChannelParserTest, ValidHealthCheck) { |
|
|
@ -880,14 +908,13 @@ TEST_F(ClientChannelParserTest, ValidHealthCheck) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
const auto* parsed_config = |
|
|
|
const auto* parsed_config = |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>( |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
svc_cfg->GetGlobalParsedConfig(0)); |
|
|
|
ASSERT_TRUE(parsed_config != nullptr); |
|
|
|
ASSERT_NE(parsed_config, nullptr); |
|
|
|
EXPECT_EQ(strcmp(parsed_config->health_check_service_name(), |
|
|
|
EXPECT_STREQ(parsed_config->health_check_service_name(), |
|
|
|
"health_check_service_name"), |
|
|
|
"health_check_service_name"); |
|
|
|
0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientChannelParserTest, InvalidHealthCheckMultipleEntries) { |
|
|
|
TEST_F(ClientChannelParserTest, InvalidHealthCheckMultipleEntries) { |
|
|
@ -902,12 +929,10 @@ TEST_F(ClientChannelParserTest, InvalidHealthCheckMultipleEntries) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"JSON parsing failed.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"duplicate key \"healthCheckConfig\" at index 104"); |
|
|
|
std::string("(JSON parsing failed)(.*)(referenced_errors)" |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"(.*)(duplicate key \"healthCheckConfig\" at index 104)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MessageSizeParserTest : public ::testing::Test { |
|
|
|
class MessageSizeParserTest : public ::testing::Test { |
|
|
@ -915,8 +940,9 @@ class MessageSizeParserTest : public ::testing::Test { |
|
|
|
void SetUp() override { |
|
|
|
void SetUp() override { |
|
|
|
ServiceConfig::Shutdown(); |
|
|
|
ServiceConfig::Shutdown(); |
|
|
|
ServiceConfig::Init(); |
|
|
|
ServiceConfig::Init(); |
|
|
|
EXPECT_TRUE(ServiceConfig::RegisterParser( |
|
|
|
EXPECT_EQ( |
|
|
|
absl::make_unique<MessageSizeParser>()) == 0); |
|
|
|
ServiceConfig::RegisterParser(absl::make_unique<MessageSizeParser>()), |
|
|
|
|
|
|
|
0); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -933,14 +959,13 @@ TEST_F(MessageSizeParserTest, Valid) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); |
|
|
|
ASSERT_TRUE(error == GRPC_ERROR_NONE); |
|
|
|
|
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector( |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
grpc_slice_from_static_string("/TestServ/TestMethod")); |
|
|
|
EXPECT_TRUE(vector_ptr != nullptr); |
|
|
|
ASSERT_NE(vector_ptr, nullptr); |
|
|
|
auto parsed_config = |
|
|
|
auto parsed_config = |
|
|
|
static_cast<MessageSizeParsedConfig*>(((*vector_ptr)[0]).get()); |
|
|
|
static_cast<MessageSizeParsedConfig*>(((*vector_ptr)[0]).get()); |
|
|
|
ASSERT_TRUE(parsed_config != nullptr); |
|
|
|
ASSERT_NE(parsed_config, nullptr); |
|
|
|
EXPECT_EQ(parsed_config->limits().max_send_size, 1024); |
|
|
|
EXPECT_EQ(parsed_config->limits().max_send_size, 1024); |
|
|
|
EXPECT_EQ(parsed_config->limits().max_recv_size, 1024); |
|
|
|
EXPECT_EQ(parsed_config->limits().max_recv_size, 1024); |
|
|
|
} |
|
|
|
} |
|
|
@ -957,16 +982,13 @@ TEST_F(MessageSizeParserTest, InvalidMaxRequestMessageBytes) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Method Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing " |
|
|
|
"methodConfig.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Method " |
|
|
|
"Message size parser.*referenced_errors.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(.*)(" |
|
|
|
"field:maxRequestMessageBytes error:should be non-negative"); |
|
|
|
"referenced_errors)(.*)(Message size " |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(field:" |
|
|
|
|
|
|
|
"maxRequestMessageBytes error:should be non-negative)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(MessageSizeParserTest, InvalidMaxResponseMessageBytes) { |
|
|
|
TEST_F(MessageSizeParserTest, InvalidMaxResponseMessageBytes) { |
|
|
@ -981,16 +1003,14 @@ TEST_F(MessageSizeParserTest, InvalidMaxResponseMessageBytes) { |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
auto svc_cfg = ServiceConfig::Create(test_json, &error); |
|
|
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(error)); |
|
|
|
std::regex regex( |
|
|
|
ASSERT_TRUE(error != GRPC_ERROR_NONE); |
|
|
|
"Service config parsing error.*referenced_errors.*" |
|
|
|
std::regex e( |
|
|
|
"Method Params.*referenced_errors.*" |
|
|
|
std::string("(Service config parsing " |
|
|
|
"methodConfig.*referenced_errors.*" |
|
|
|
"error)(.*)(referenced_errors)(.*)(Method " |
|
|
|
"Message size parser.*referenced_errors.*" |
|
|
|
"Params)(.*)(referenced_errors)(.*)(methodConfig)(.*)(" |
|
|
|
"field:maxResponseMessageBytes error:should be of type " |
|
|
|
"referenced_errors)(.*)(Message size " |
|
|
|
"number"); |
|
|
|
"parser)(.*)(referenced_errors)(.*)(field:" |
|
|
|
VerifyRegexMatch(error, regex); |
|
|
|
"maxResponseMessageBytes error:should be of type number)")); |
|
|
|
|
|
|
|
VerifyRegexMatch(error, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
} // namespace testing
|
|
|
|