@@ -450,6 +450,24 @@ public void testCacheHolderContextConstructor() {
450450 assertEquals (zero , holder .contextCache .get ("baz" ).get ().rate );
451451 }
452452
453+ public void testCompilationRateUnlimitedContextOnly () throws IOException {
454+ IllegalArgumentException illegal = expectThrows (IllegalArgumentException .class , () -> {
455+ buildScriptService (Settings .builder ()
456+ .put (SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING .getKey (), ScriptService .UNLIMITED_COMPILATION_RATE_KEY )
457+ .build ());
458+ });
459+ assertEquals ("parameter must contain a positive integer and a timevalue, i.e. 10/1m, but was [unlimited]" , illegal .getMessage ());
460+
461+ // Should not throw.
462+ buildScriptService (Settings .builder ()
463+ .put (SCRIPT_MAX_COMPILATIONS_RATE_SETTING .getConcreteSettingForNamespace ("ingest" ).getKey (),
464+ ScriptService .UNLIMITED_COMPILATION_RATE_KEY )
465+ .put (SCRIPT_MAX_COMPILATIONS_RATE_SETTING .getConcreteSettingForNamespace ("field" ).getKey (),
466+ ScriptService .UNLIMITED_COMPILATION_RATE_KEY )
467+ .put (SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING .getKey (), ScriptService .USE_CONTEXT_RATE_KEY )
468+ .build ());
469+ }
470+
453471 public void testCacheHolderChangeSettings () {
454472 String fooCompilationRate = "77/5m" ;
455473 String barCompilationRate = "78/6m" ;
@@ -459,7 +477,7 @@ public void testCacheHolderChangeSettings() {
459477 Settings s = Settings .builder ()
460478 .put (SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING .getKey (), compilationRate )
461479 .build ();
462- Set <String > contexts = Set .of ("foo" , "bar" , "baz" );
480+ Set <String > contexts = Set .of ("foo" , "bar" , "baz" , "qux" );
463481 ScriptService .CacheHolder holder = new ScriptService .CacheHolder (s , contexts , true );
464482
465483 assertNotNull (holder .general );
@@ -470,16 +488,19 @@ public void testCacheHolderChangeSettings() {
470488 .put (SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING .getKey (), ScriptService .USE_CONTEXT_RATE_KEY )
471489 .put (SCRIPT_MAX_COMPILATIONS_RATE_SETTING .getConcreteSettingForNamespace ("foo" ).getKey (), fooCompilationRate )
472490 .put (SCRIPT_MAX_COMPILATIONS_RATE_SETTING .getConcreteSettingForNamespace ("bar" ).getKey (), barCompilationRate )
491+ .put (SCRIPT_MAX_COMPILATIONS_RATE_SETTING .getConcreteSettingForNamespace ("qux" ).getKey (),
492+ ScriptService .UNLIMITED_COMPILATION_RATE_KEY )
473493 .build ()
474494 );
475495
476496 assertNull (holder .general );
477497 assertNotNull (holder .contextCache );
478- assertEquals (3 , holder .contextCache .size ());
498+ assertEquals (4 , holder .contextCache .size ());
479499 assertEquals (contexts , holder .contextCache .keySet ());
480500
481501 assertEquals (ScriptService .MAX_COMPILATION_RATE_FUNCTION .apply (fooCompilationRate ), holder .contextCache .get ("foo" ).get ().rate );
482502 assertEquals (ScriptService .MAX_COMPILATION_RATE_FUNCTION .apply (barCompilationRate ), holder .contextCache .get ("bar" ).get ().rate );
503+ assertEquals (ScriptCache .UNLIMITED_COMPILATION_RATE , holder .contextCache .get ("qux" ).get ().rate );
483504 assertEquals (ScriptService .SCRIPT_MAX_COMPILATIONS_RATE_SETTING .getDefault (Settings .EMPTY ),
484505 holder .contextCache .get ("baz" ).get ().rate );
485506
0 commit comments