|
29 | 29 | import io.envoyproxy.envoy.config.core.v3.RuntimeFractionalPercent; |
30 | 30 | import io.envoyproxy.envoy.config.route.v3.QueryParameterMatcher; |
31 | 31 | import io.envoyproxy.envoy.config.route.v3.RedirectAction; |
| 32 | +import io.envoyproxy.envoy.config.route.v3.RouteAction.MaxStreamDuration; |
32 | 33 | import io.envoyproxy.envoy.config.route.v3.WeightedCluster; |
33 | 34 | import io.envoyproxy.envoy.type.matcher.v3.RegexMatcher; |
34 | 35 | import io.envoyproxy.envoy.type.v3.FractionalPercent; |
|
49 | 50 | import io.grpc.xds.RouteMatch.PathMatcher; |
50 | 51 | import java.util.Arrays; |
51 | 52 | import java.util.Collections; |
52 | | -import java.util.concurrent.TimeUnit; |
53 | 53 | import javax.annotation.Nullable; |
54 | 54 | import org.junit.Test; |
55 | 55 | import org.junit.runner.RunWith; |
@@ -213,7 +213,7 @@ public void convertRoute() { |
213 | 213 | new Route( |
214 | 214 | new RouteMatch(new PathMatcher("/service/method", null, null), |
215 | 215 | Collections.<HeaderMatcher>emptyList(), null), |
216 | | - new RouteAction(TimeUnit.SECONDS.toNanos(15L), "cluster-foo", null))); |
| 216 | + new RouteAction(0, "cluster-foo", null))); |
217 | 217 |
|
218 | 218 | io.envoyproxy.envoy.config.route.v3.Route unsupportedProto = |
219 | 219 | io.envoyproxy.envoy.config.route.v3.Route.newBuilder() |
@@ -399,74 +399,71 @@ public void convertRouteMatch_withRuntimeFraction() { |
399 | 399 | } |
400 | 400 |
|
401 | 401 | @Test |
402 | | - public void convertRouteAction() { |
403 | | - // cluster_specifier = cluster, default timeout |
404 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto1 = |
| 402 | + public void convertRouteAction_cluster() { |
| 403 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
405 | 404 | io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
406 | 405 | .setCluster("cluster-foo") |
407 | 406 | .build(); |
408 | | - StructOrError<RouteAction> struct1 = RouteAction.fromEnvoyProtoRouteAction(proto1); |
| 407 | + StructOrError<RouteAction> struct1 = RouteAction.fromEnvoyProtoRouteAction(proto); |
409 | 408 | assertThat(struct1.getErrorDetail()).isNull(); |
410 | | - assertThat(struct1.getStruct().getTimeoutNano()) |
411 | | - .isEqualTo(TimeUnit.SECONDS.toNanos(15L)); // default value |
412 | 409 | assertThat(struct1.getStruct().getCluster()).isEqualTo("cluster-foo"); |
413 | 410 | assertThat(struct1.getStruct().getWeightedCluster()).isNull(); |
| 411 | + } |
414 | 412 |
|
415 | | - // cluster_specifier = cluster, infinity timeout |
416 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto2 = |
417 | | - io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
418 | | - .setMaxGrpcTimeout(Durations.fromNanos(0)) |
419 | | - .setTimeout(Durations.fromMicros(20L)) |
420 | | - .setCluster("cluster-foo") |
421 | | - .build(); |
422 | | - StructOrError<RouteAction> struct2 = RouteAction.fromEnvoyProtoRouteAction(proto2); |
423 | | - assertThat(struct2.getStruct().getTimeoutNano()) |
424 | | - .isEqualTo(Long.MAX_VALUE); // infinite |
425 | | - |
426 | | - // cluster_specifier = cluster, infinity timeout |
427 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto3 = |
428 | | - io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
429 | | - .setTimeout(Durations.fromNanos(0)) |
430 | | - .setCluster("cluster-foo") |
431 | | - .build(); |
432 | | - StructOrError<RouteAction> struct3 = RouteAction.fromEnvoyProtoRouteAction(proto3); |
433 | | - assertThat(struct3.getStruct().getTimeoutNano()).isEqualTo(Long.MAX_VALUE); // infinite |
434 | | - |
435 | | - // cluster_specifier = cluster_header |
436 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto4 = |
437 | | - io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
438 | | - .setClusterHeader("cluster-bar") |
439 | | - .build(); |
440 | | - StructOrError<RouteAction> struct4 = RouteAction.fromEnvoyProtoRouteAction(proto4); |
441 | | - assertThat(struct4).isNull(); |
442 | | - |
443 | | - // cluster_specifier = weighted_cluster |
444 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto5 = |
| 413 | + @Test |
| 414 | + public void convertRouteAction_weightedCluster() { |
| 415 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
445 | 416 | io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
446 | | - .setMaxGrpcTimeout(Durations.fromSeconds(6L)) |
447 | | - .setTimeout(Durations.fromMicros(20L)) |
448 | 417 | .setWeightedClusters( |
449 | 418 | WeightedCluster.newBuilder() |
450 | 419 | .addClusters( |
451 | 420 | WeightedCluster.ClusterWeight |
452 | 421 | .newBuilder() |
453 | | - .setName("cluster-baz") |
454 | | - .setWeight(UInt32Value.newBuilder().setValue(100)))) |
| 422 | + .setName("cluster-foo") |
| 423 | + .setWeight(UInt32Value.newBuilder().setValue(30))) |
| 424 | + .addClusters(WeightedCluster.ClusterWeight |
| 425 | + .newBuilder() |
| 426 | + .setName("cluster-bar") |
| 427 | + .setWeight(UInt32Value.newBuilder().setValue(70)))) |
455 | 428 | .build(); |
456 | | - StructOrError<RouteAction> struct5 = RouteAction.fromEnvoyProtoRouteAction(proto5); |
| 429 | + StructOrError<RouteAction> struct5 = RouteAction.fromEnvoyProtoRouteAction(proto); |
457 | 430 | assertThat(struct5.getErrorDetail()).isNull(); |
458 | | - assertThat(struct5.getStruct().getTimeoutNano()) |
459 | | - .isEqualTo(TimeUnit.SECONDS.toNanos(6L)); |
460 | 431 | assertThat(struct5.getStruct().getCluster()).isNull(); |
461 | | - assertThat(struct5.getStruct().getWeightedCluster()) |
462 | | - .containsExactly(new ClusterWeight("cluster-baz", 100)); |
| 432 | + assertThat(struct5.getStruct().getWeightedCluster()).containsExactly( |
| 433 | + new ClusterWeight("cluster-foo", 30), new ClusterWeight("cluster-bar", 70)); |
| 434 | + } |
463 | 435 |
|
464 | | - // cluster_specifier unset |
465 | | - io.envoyproxy.envoy.config.route.v3.RouteAction unsetProto = |
| 436 | + @Test |
| 437 | + public void convertRouteAction_unspecifiedClusterError() { |
| 438 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
466 | 439 | io.envoyproxy.envoy.config.route.v3.RouteAction.getDefaultInstance(); |
467 | | - StructOrError<RouteAction> unsetStruct = RouteAction.fromEnvoyProtoRouteAction(unsetProto); |
468 | | - assertThat(unsetStruct.getErrorDetail()).isNotNull(); |
| 440 | + StructOrError<RouteAction> unsetStruct = RouteAction.fromEnvoyProtoRouteAction(proto); |
469 | 441 | assertThat(unsetStruct.getStruct()).isNull(); |
| 442 | + assertThat(unsetStruct.getErrorDetail()).isNotNull(); |
| 443 | + } |
| 444 | + |
| 445 | + @Test |
| 446 | + public void convertRouteAction_timeoutByMaxStreamDuration() { |
| 447 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
| 448 | + io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
| 449 | + .setCluster("cluster-foo") |
| 450 | + .setMaxStreamDuration( |
| 451 | + MaxStreamDuration.newBuilder() |
| 452 | + .setGrpcTimeoutHeaderMax(Durations.fromMicros(20L)) |
| 453 | + .setMaxStreamDuration(Durations.fromSeconds(5L))) |
| 454 | + .build(); |
| 455 | + StructOrError<RouteAction> struct2 = RouteAction.fromEnvoyProtoRouteAction(proto); |
| 456 | + assertThat(struct2.getStruct().getTimeoutNano()).isEqualTo(Durations.fromSeconds(5L)); |
| 457 | + } |
| 458 | + |
| 459 | + @Test |
| 460 | + public void convertRouteAction_timeoutUnset() { |
| 461 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
| 462 | + io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
| 463 | + .setCluster("cluster-foo") |
| 464 | + .build(); |
| 465 | + StructOrError<RouteAction> struct2 = RouteAction.fromEnvoyProtoRouteAction(proto); |
| 466 | + assertThat(struct2.getStruct().getTimeoutNano()).isEqualTo(0); |
470 | 467 | } |
471 | 468 |
|
472 | 469 | @Test |
|
0 commit comments