@@ -469,6 +469,65 @@ public void convert_jsonRlsConfig_staleAgeGivenWithoutMaxAge() throws IOExceptio
469469 }
470470 }
471471
472+ @ Test
473+ public void convert_jsonRlsConfig_doNotClampMaxAgeIfStaleAgeIsSet () throws IOException {
474+ String jsonStr = "{\n "
475+ + " \" grpcKeybuilders\" : [\n "
476+ + " {\n "
477+ + " \" names\" : [\n "
478+ + " {\n "
479+ + " \" service\" : \" service1\" ,\n "
480+ + " \" method\" : \" create\" \n "
481+ + " }\n "
482+ + " ],\n "
483+ + " \" headers\" : [\n "
484+ + " {\n "
485+ + " \" key\" : \" user\" ,"
486+ + " \" names\" : [\" User\" , \" Parent\" ],\n "
487+ + " \" optional\" : true\n "
488+ + " },\n "
489+ + " {\n "
490+ + " \" key\" : \" id\" ,"
491+ + " \" names\" : [\" X-Google-Id\" ],\n "
492+ + " \" optional\" : true\n "
493+ + " }\n "
494+ + " ]\n "
495+ + " }\n "
496+ + " ],\n "
497+ + " \" lookupService\" : \" service1\" ,\n "
498+ + " \" lookupServiceTimeout\" : \" 2s\" ,\n "
499+ + " \" maxAge\" : \" 350s\" ,\n "
500+ + " \" staleAge\" : \" 310s\" ,\n "
501+ + " \" validTargets\" : [\" a valid target\" ],"
502+ + " \" cacheSizeBytes\" : \" 1000\" ,\n "
503+ + " \" defaultTarget\" : \" us_east_1.cloudbigtable.googleapis.com\" \n "
504+ + "}" ;
505+
506+ RouteLookupConfig expectedConfig =
507+ RouteLookupConfig .builder ()
508+ .grpcKeybuilders (ImmutableList .of (
509+ GrpcKeyBuilder .create (
510+ ImmutableList .of (Name .create ("service1" , "create" )),
511+ ImmutableList .of (
512+ NameMatcher .create ("user" , ImmutableList .of ("User" , "Parent" )),
513+ NameMatcher .create ("id" , ImmutableList .of ("X-Google-Id" ))),
514+ ExtraKeys .DEFAULT ,
515+ ImmutableMap .<String , String >of ())))
516+ .lookupService ("service1" )
517+ .lookupServiceTimeoutInNanos (TimeUnit .SECONDS .toNanos (2 ))
518+ .maxAgeInNanos (TimeUnit .SECONDS .toNanos (350 )) // Should not be clamped
519+ .staleAgeInNanos (TimeUnit .SECONDS .toNanos (300 )) // Should be clamped to max 300s
520+ .cacheSizeBytes (1000 )
521+ .defaultTarget ("us_east_1.cloudbigtable.googleapis.com" )
522+ .build ();
523+
524+ RouteLookupConfigConverter converter = new RouteLookupConfigConverter ();
525+ @ SuppressWarnings ("unchecked" )
526+ Map <String , ?> parsedJson = (Map <String , ?>) JsonParser .parse (jsonStr );
527+ RouteLookupConfig converted = converter .convert (parsedJson );
528+ assertThat (converted ).isEqualTo (expectedConfig );
529+ }
530+
472531 @ Test
473532 public void convert_jsonRlsConfig_keyBuilderWithoutName () throws IOException {
474533 String jsonStr = "{\n "
0 commit comments