15 from typing
import Tuple
17 from absl
import flags
18 from absl.testing
import absltest
20 from framework
import xds_url_map_testcase
25 HostRule = xds_url_map_testcase.HostRule
26 PathMatcher = xds_url_map_testcase.PathMatcher
27 GcpResourceManager = xds_url_map_testcase.GcpResourceManager
28 DumpedXdsConfig = xds_url_map_testcase.DumpedXdsConfig
29 RpcTypeUnaryCall = xds_url_map_testcase.RpcTypeUnaryCall
30 RpcTypeEmptyCall = xds_url_map_testcase.RpcTypeEmptyCall
31 XdsTestClient = client_app.XdsTestClient
34 logger = logging.getLogger(__name__)
35 flags.adopt_module_key_flags(xds_url_map_testcase)
41 if config.client_lang == _Lang.NODE:
42 return config.version_gte(
'v1.3.x')
55 path_matcher: PathMatcher) -> Tuple[HostRule, PathMatcher]:
56 path_matcher[
"routeRules"] = [{
60 'fullPathMatch':
'/grpc.testing.TestService/EmptyCall'
64 return host_rule, path_matcher
67 self.assertNumEndpoints(xds_config, 2)
69 xds_config.rds[
'virtualHosts'][0][
'routes'][0][
'match'][
'path'],
70 "/grpc.testing.TestService/EmptyCall")
73 rpc_distribution = self.configure_and_send(test_client,
74 rpc_types=[RpcTypeEmptyCall],
78 rpc_distribution.empty_call_alternative_service_rpc_count)
90 path_matcher: PathMatcher) -> Tuple[HostRule, PathMatcher]:
91 path_matcher[
"routeRules"] = [{
95 'fullPathMatch':
'/grpc.testing.TestService/UnaryCall'
99 return host_rule, path_matcher
102 self.assertNumEndpoints(xds_config, 2)
104 xds_config.rds[
'virtualHosts'][0][
'routes'][0][
'match'][
'path'],
105 "/grpc.testing.TestService/UnaryCall")
108 rpc_distribution = self.configure_and_send(
109 test_client, rpc_types=(RpcTypeUnaryCall,), num_rpcs=_NUM_RPCS)
112 rpc_distribution.unary_call_alternative_service_rpc_count)
116 """This test case is similar to the one above (but with route services
117 swapped). This test has two routes (full_path and the default) to match
118 EmptyCall, and both routes set alternative_backend_service as the action.
119 This forces the client to handle duplicate Clusters in the RDS response."""
128 path_matcher: PathMatcher) -> Tuple[HostRule, PathMatcher]:
129 path_matcher[
"routeRules"] = [
134 'prefixMatch':
'/grpc.testing.TestService/Unary'
142 'fullPathMatch':
'/grpc.testing.TestService/EmptyCall'
147 return host_rule, path_matcher
150 self.assertNumEndpoints(xds_config, 2)
152 xds_config.rds[
'virtualHosts'][0][
'routes'][0][
'match'][
'prefix'],
153 "/grpc.testing.TestService/Unary")
155 xds_config.rds[
'virtualHosts'][0][
'routes'][1][
'match'][
'path'],
156 "/grpc.testing.TestService/EmptyCall")
159 rpc_distribution = self.configure_and_send(
161 rpc_types=[RpcTypeUnaryCall, RpcTypeEmptyCall],
163 self.assertEqual(0, rpc_distribution.num_failures)
165 0, rpc_distribution.unary_call_alternative_service_rpc_count)
167 rpc_distribution.empty_call_default_service_rpc_count)
179 path_matcher: PathMatcher) -> Tuple[HostRule, PathMatcher]:
180 path_matcher[
"routeRules"] = [{
189 return host_rule, path_matcher
192 self.assertNumEndpoints(xds_config, 2)
194 xds_config.rds[
'virtualHosts'][0][
'routes'][0][
'match'][
'safeRegex']
195 [
'regex'],
r'^\/.*\/UnaryCall$')
198 rpc_distribution = self.configure_and_send(
199 test_client, rpc_types=(RpcTypeUnaryCall,), num_rpcs=_NUM_RPCS)
202 rpc_distribution.unary_call_alternative_service_rpc_count)
214 path_matcher: PathMatcher) -> Tuple[HostRule, PathMatcher]:
215 path_matcher[
"routeRules"] = [{
220 'fullPathMatch':
'/gRpC.tEsTinG.tEstseRvice/empTycaLl',
225 return host_rule, path_matcher
228 self.assertNumEndpoints(xds_config, 2)
230 xds_config.rds[
'virtualHosts'][0][
'routes'][0][
'match'][
'path'],
231 '/gRpC.tEsTinG.tEstseRvice/empTycaLl')
233 xds_config.rds[
'virtualHosts'][0][
'routes'][0][
'match']
234 [
'caseSensitive'],
False)
237 rpc_distribution = self.configure_and_send(test_client,
238 rpc_types=[RpcTypeEmptyCall],
242 rpc_distribution.empty_call_alternative_service_rpc_count)
245 if __name__ ==
'__main__':