|
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; |
@@ -212,7 +213,7 @@ public void convertRoute() { |
212 | 213 | new Route( |
213 | 214 | new RouteMatch(PathMatcher.fromPath("/service/method", false), |
214 | 215 | Collections.<HeaderMatcher>emptyList(), null), |
215 | | - new RouteAction(TimeUnit.SECONDS.toNanos(15L), "cluster-foo", null))); |
| 216 | + new RouteAction(null, "cluster-foo", null))); |
216 | 217 |
|
217 | 218 | io.envoyproxy.envoy.config.route.v3.Route unsupportedProto = |
218 | 219 | io.envoyproxy.envoy.config.route.v3.Route.newBuilder() |
@@ -370,74 +371,84 @@ public void convertRouteMatch_withRuntimeFraction() { |
370 | 371 | } |
371 | 372 |
|
372 | 373 | @Test |
373 | | - public void convertRouteAction() { |
374 | | - // cluster_specifier = cluster, default timeout |
375 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto1 = |
| 374 | + public void convertRouteAction_cluster() { |
| 375 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
376 | 376 | io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
377 | 377 | .setCluster("cluster-foo") |
378 | 378 | .build(); |
379 | | - StructOrError<RouteAction> struct1 = RouteAction.fromEnvoyProtoRouteAction(proto1); |
380 | | - assertThat(struct1.getErrorDetail()).isNull(); |
381 | | - assertThat(struct1.getStruct().getTimeoutNano()) |
382 | | - .isEqualTo(TimeUnit.SECONDS.toNanos(15L)); // default value |
383 | | - assertThat(struct1.getStruct().getCluster()).isEqualTo("cluster-foo"); |
384 | | - assertThat(struct1.getStruct().getWeightedCluster()).isNull(); |
| 379 | + StructOrError<RouteAction> struct = RouteAction.fromEnvoyProtoRouteAction(proto); |
| 380 | + assertThat(struct.getErrorDetail()).isNull(); |
| 381 | + assertThat(struct.getStruct().getCluster()).isEqualTo("cluster-foo"); |
| 382 | + assertThat(struct.getStruct().getWeightedCluster()).isNull(); |
| 383 | + } |
385 | 384 |
|
386 | | - // cluster_specifier = cluster, infinity timeout |
387 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto2 = |
| 385 | + @Test |
| 386 | + public void convertRouteAction_weightedCluster() { |
| 387 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
388 | 388 | io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
389 | | - .setMaxGrpcTimeout(Durations.fromNanos(0)) |
390 | | - .setTimeout(Durations.fromMicros(20L)) |
391 | | - .setCluster("cluster-foo") |
| 389 | + .setWeightedClusters( |
| 390 | + WeightedCluster.newBuilder() |
| 391 | + .addClusters( |
| 392 | + WeightedCluster.ClusterWeight |
| 393 | + .newBuilder() |
| 394 | + .setName("cluster-foo") |
| 395 | + .setWeight(UInt32Value.newBuilder().setValue(30))) |
| 396 | + .addClusters(WeightedCluster.ClusterWeight |
| 397 | + .newBuilder() |
| 398 | + .setName("cluster-bar") |
| 399 | + .setWeight(UInt32Value.newBuilder().setValue(70)))) |
392 | 400 | .build(); |
393 | | - StructOrError<RouteAction> struct2 = RouteAction.fromEnvoyProtoRouteAction(proto2); |
394 | | - assertThat(struct2.getStruct().getTimeoutNano()) |
395 | | - .isEqualTo(Long.MAX_VALUE); // infinite |
| 401 | + StructOrError<RouteAction> struct = RouteAction.fromEnvoyProtoRouteAction(proto); |
| 402 | + assertThat(struct.getErrorDetail()).isNull(); |
| 403 | + assertThat(struct.getStruct().getCluster()).isNull(); |
| 404 | + assertThat(struct.getStruct().getWeightedCluster()).containsExactly( |
| 405 | + new ClusterWeight("cluster-foo", 30), new ClusterWeight("cluster-bar", 70)); |
| 406 | + } |
| 407 | + |
| 408 | + @Test |
| 409 | + public void convertRouteAction_unspecifiedClusterError() { |
| 410 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
| 411 | + io.envoyproxy.envoy.config.route.v3.RouteAction.getDefaultInstance(); |
| 412 | + StructOrError<RouteAction> unsetStruct = RouteAction.fromEnvoyProtoRouteAction(proto); |
| 413 | + assertThat(unsetStruct.getStruct()).isNull(); |
| 414 | + assertThat(unsetStruct.getErrorDetail()).isNotNull(); |
| 415 | + } |
396 | 416 |
|
397 | | - // cluster_specifier = cluster, infinity timeout |
398 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto3 = |
| 417 | + @Test |
| 418 | + public void convertRouteAction_timeoutByGrpcTimeoutHeaderMax() { |
| 419 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
399 | 420 | io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
400 | | - .setTimeout(Durations.fromNanos(0)) |
401 | 421 | .setCluster("cluster-foo") |
| 422 | + .setMaxStreamDuration( |
| 423 | + MaxStreamDuration.newBuilder() |
| 424 | + .setGrpcTimeoutHeaderMax(Durations.fromSeconds(5L)) |
| 425 | + .setMaxStreamDuration(Durations.fromMillis(20L))) |
402 | 426 | .build(); |
403 | | - StructOrError<RouteAction> struct3 = RouteAction.fromEnvoyProtoRouteAction(proto3); |
404 | | - assertThat(struct3.getStruct().getTimeoutNano()).isEqualTo(Long.MAX_VALUE); // infinite |
| 427 | + StructOrError<RouteAction> struct = RouteAction.fromEnvoyProtoRouteAction(proto); |
| 428 | + assertThat(struct.getStruct().getTimeoutNano()).isEqualTo(TimeUnit.SECONDS.toNanos(5L)); |
| 429 | + } |
405 | 430 |
|
406 | | - // cluster_specifier = cluster_header |
407 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto4 = |
| 431 | + @Test |
| 432 | + public void convertRouteAction_timeoutByMaxStreamDuration() { |
| 433 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
408 | 434 | io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
409 | | - .setClusterHeader("cluster-bar") |
| 435 | + .setCluster("cluster-foo") |
| 436 | + .setMaxStreamDuration( |
| 437 | + MaxStreamDuration.newBuilder() |
| 438 | + .setMaxStreamDuration(Durations.fromSeconds(5L))) |
410 | 439 | .build(); |
411 | | - StructOrError<RouteAction> struct4 = RouteAction.fromEnvoyProtoRouteAction(proto4); |
412 | | - assertThat(struct4).isNull(); |
| 440 | + StructOrError<RouteAction> struct = RouteAction.fromEnvoyProtoRouteAction(proto); |
| 441 | + assertThat(struct.getStruct().getTimeoutNano()).isEqualTo(TimeUnit.SECONDS.toNanos(5L)); |
| 442 | + } |
413 | 443 |
|
414 | | - // cluster_specifier = weighted_cluster |
415 | | - io.envoyproxy.envoy.config.route.v3.RouteAction proto5 = |
| 444 | + @Test |
| 445 | + public void convertRouteAction_timeoutUnset() { |
| 446 | + io.envoyproxy.envoy.config.route.v3.RouteAction proto = |
416 | 447 | io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() |
417 | | - .setMaxGrpcTimeout(Durations.fromSeconds(6L)) |
418 | | - .setTimeout(Durations.fromMicros(20L)) |
419 | | - .setWeightedClusters( |
420 | | - WeightedCluster.newBuilder() |
421 | | - .addClusters( |
422 | | - WeightedCluster.ClusterWeight |
423 | | - .newBuilder() |
424 | | - .setName("cluster-baz") |
425 | | - .setWeight(UInt32Value.newBuilder().setValue(100)))) |
| 448 | + .setCluster("cluster-foo") |
426 | 449 | .build(); |
427 | | - StructOrError<RouteAction> struct5 = RouteAction.fromEnvoyProtoRouteAction(proto5); |
428 | | - assertThat(struct5.getErrorDetail()).isNull(); |
429 | | - assertThat(struct5.getStruct().getTimeoutNano()) |
430 | | - .isEqualTo(TimeUnit.SECONDS.toNanos(6L)); |
431 | | - assertThat(struct5.getStruct().getCluster()).isNull(); |
432 | | - assertThat(struct5.getStruct().getWeightedCluster()) |
433 | | - .containsExactly(new ClusterWeight("cluster-baz", 100)); |
434 | | - |
435 | | - // cluster_specifier unset |
436 | | - io.envoyproxy.envoy.config.route.v3.RouteAction unsetProto = |
437 | | - io.envoyproxy.envoy.config.route.v3.RouteAction.getDefaultInstance(); |
438 | | - StructOrError<RouteAction> unsetStruct = RouteAction.fromEnvoyProtoRouteAction(unsetProto); |
439 | | - assertThat(unsetStruct.getErrorDetail()).isNotNull(); |
440 | | - assertThat(unsetStruct.getStruct()).isNull(); |
| 450 | + StructOrError<RouteAction> struct = RouteAction.fromEnvoyProtoRouteAction(proto); |
| 451 | + assertThat(struct.getStruct().getTimeoutNano()).isNull(); |
441 | 452 | } |
442 | 453 |
|
443 | 454 | @Test |
|
0 commit comments