@@ -465,16 +465,41 @@ private TestingScalingRealizer.Event<JobID, JobAutoScalerContext<JobID>> getEven
465465 }
466466
467467 @ Test
468- void testGetCustomEvaluatorIfRequiredWithCustomEvaluator () {
468+ void testGetCustomEvaluatorIfRequired () {
469469 CustomEvaluator testCustomEvaluator = new TestCustomEvaluator ();
470470 testCustomEvaluator .configure (new Configuration ());
471471 var testCustomEvaluators = Map .of (testCustomEvaluator .getName (), testCustomEvaluator );
472472
473+ var autoscalerWithCustomEvaluator =
474+ new JobAutoScalerImpl <>(
475+ null ,
476+ null ,
477+ null ,
478+ eventCollector ,
479+ scalingRealizer ,
480+ stateStore ,
481+ testCustomEvaluators );
482+
473483 String testCustomEvaluatorName = "test-custom-evaluator" ;
474484
475485 var defaultConf = context .getConfiguration ();
486+
487+ // Case 1: Custom evaluator configured.
476488 defaultConf .set (AutoScalerOptions .CUSTOM_EVALUATOR_NAME , testCustomEvaluatorName );
477489
490+ var customEvaluatorWithConfig =
491+ autoscalerWithCustomEvaluator .getCustomEvaluatorIfRequired (
492+ context .getConfiguration ());
493+ assertNotNull (customEvaluatorWithConfig );
494+ assertInstanceOf (CustomEvaluator .class , customEvaluatorWithConfig .f0 );
495+ var customEvaluatorConfig = customEvaluatorWithConfig .f1 ;
496+ assertNotNull (customEvaluatorConfig );
497+ assertEquals (0 , customEvaluatorConfig .keySet ().size ());
498+
499+ Set <String > expectedKeys = Set .of ();
500+ assertEquals (expectedKeys , customEvaluatorConfig .keySet ());
501+
502+ // Case 2: Custom evaluator configured with additional configs for the plugin.
478503 defaultConf .set (
479504 ConfigOptions .key (
480505 AutoScalerOptions .AUTOSCALER_CONF_PREFIX
@@ -495,32 +520,39 @@ void testGetCustomEvaluatorIfRequiredWithCustomEvaluator() {
495520 .noDefaultValue (),
496521 "v2" );
497522
498- var autoscaler =
499- new JobAutoScalerImpl <>(
500- null ,
501- null ,
502- null ,
503- eventCollector ,
504- scalingRealizer ,
505- stateStore ,
506- testCustomEvaluators );
507-
508- var customEvaluatorWithConfig =
509- autoscaler .getCustomEvaluatorIfRequired (context .getConfiguration ());
510- assertNotNull (customEvaluatorWithConfig );
511- assertInstanceOf (CustomEvaluator .class , customEvaluatorWithConfig .f0 );
512- var customEvaluatorConfig = customEvaluatorWithConfig .f1 ;
513- assertNotNull (customEvaluatorConfig );
514- int expectedKeyCount = 2 ;
515- assertEquals (expectedKeyCount , customEvaluatorConfig .keySet ().size ());
516-
517- Set <String > expectedKeys = Set .of ("k1" , "k2" );
518- assertTrue (customEvaluatorConfig .keySet ().containsAll (expectedKeys ));
519- }
520-
521- @ Test
522- void testGetCustomEvaluatorIfRequiredWithoutCustomEvaluator () {
523- var autoscaler =
523+ var customEvaluatorWithConfigContainingAdditionalKeys =
524+ autoscalerWithCustomEvaluator .getCustomEvaluatorIfRequired (
525+ context .getConfiguration ());
526+ assertNotNull (customEvaluatorWithConfigContainingAdditionalKeys );
527+ assertInstanceOf (
528+ CustomEvaluator .class , customEvaluatorWithConfigContainingAdditionalKeys .f0 );
529+ var customEvaluatorConfigContainingAdditionalKeys =
530+ customEvaluatorWithConfigContainingAdditionalKeys .f1 ;
531+ assertNotNull (customEvaluatorConfigContainingAdditionalKeys );
532+ assertEquals (2 , customEvaluatorConfigContainingAdditionalKeys .keySet ().size ());
533+
534+ expectedKeys = Set .of ("k1" , "k2" );
535+ assertEquals (expectedKeys , customEvaluatorConfigContainingAdditionalKeys .keySet ());
536+
537+ // Case 3: Custom evaluator configured but with a custom evaluator name that is not
538+ // available.
539+ defaultConf .set (AutoScalerOptions .CUSTOM_EVALUATOR_NAME , "test-custom-evaluator-no-match" );
540+
541+ var customEvaluatorWithConfigNoMatch =
542+ autoscalerWithCustomEvaluator .getCustomEvaluatorIfRequired (
543+ context .getConfiguration ());
544+ assertNull (customEvaluatorWithConfigNoMatch );
545+
546+ // Case 4: Custom evaluator not configured.
547+ defaultConf .removeConfig (AutoScalerOptions .CUSTOM_EVALUATOR_NAME );
548+
549+ var customEvaluatorNotConfigured =
550+ autoscalerWithCustomEvaluator .getCustomEvaluatorIfRequired (
551+ context .getConfiguration ());
552+ assertNull (customEvaluatorNotConfigured );
553+
554+ // Case 5: No custom evaluators available.
555+ var autoscalerWithoutCustomEvaluator =
524556 new JobAutoScalerImpl <>(
525557 null ,
526558 null ,
@@ -530,89 +562,9 @@ void testGetCustomEvaluatorIfRequiredWithoutCustomEvaluator() {
530562 stateStore ,
531563 Collections .emptyMap ());
532564
533- var customEvaluatorWithConfig =
534- autoscaler .getCustomEvaluatorIfRequired (context .getConfiguration ());
535- assertNull (customEvaluatorWithConfig );
536- }
537-
538- @ Test
539- void testGetCustomEvaluatorIfRequiredWithCustomEvaluatorButNotConfigured () {
540- CustomEvaluator testCustomEvaluator = new TestCustomEvaluator ();
541- testCustomEvaluator .configure (new Configuration ());
542- var testCustomEvaluators = Map .of (testCustomEvaluator .getName (), testCustomEvaluator );
543-
544- var autoscaler =
545- new JobAutoScalerImpl <>(
546- null ,
547- null ,
548- null ,
549- eventCollector ,
550- scalingRealizer ,
551- stateStore ,
552- testCustomEvaluators );
553-
554- var customEvaluatorWithConfig =
555- autoscaler .getCustomEvaluatorIfRequired (context .getConfiguration ());
556- assertNull (customEvaluatorWithConfig );
557- }
558-
559- @ Test
560- void testGetCustomEvaluatorIfRequiredWithCustomEvaluatorButNoMatches () {
561- CustomEvaluator testCustomEvaluator = new TestCustomEvaluator ();
562- testCustomEvaluator .configure (new Configuration ());
563- var testCustomEvaluators = Map .of (testCustomEvaluator .getName (), testCustomEvaluator );
564-
565- String testCustomEvaluatorName = "test-custom-evaluator-no-match" ;
566-
567- var defaultConf = context .getConfiguration ();
568- defaultConf .set (AutoScalerOptions .CUSTOM_EVALUATOR_NAME , testCustomEvaluatorName );
569-
570- var autoscaler =
571- new JobAutoScalerImpl <>(
572- null ,
573- null ,
574- null ,
575- eventCollector ,
576- scalingRealizer ,
577- stateStore ,
578- testCustomEvaluators );
579-
580- var customEvaluatorWithConfig =
581- autoscaler .getCustomEvaluatorIfRequired (context .getConfiguration ());
582- assertNull (customEvaluatorWithConfig );
583- }
584-
585- @ Test
586- void testGetCustomEvaluatorIfRequiredWithCustomEvaluatorNoConfig () {
587- CustomEvaluator testCustomEvaluator = new TestCustomEvaluator ();
588- testCustomEvaluator .configure (new Configuration ());
589- var testCustomEvaluators = Map .of (testCustomEvaluator .getName (), testCustomEvaluator );
590-
591- String testCustomEvaluatorName = "test-custom-evaluator" ;
592-
593- var defaultConf = context .getConfiguration ();
594- defaultConf .set (AutoScalerOptions .CUSTOM_EVALUATOR_NAME , testCustomEvaluatorName );
595-
596- var autoscaler =
597- new JobAutoScalerImpl <>(
598- null ,
599- null ,
600- null ,
601- eventCollector ,
602- scalingRealizer ,
603- stateStore ,
604- testCustomEvaluators );
605-
606- var customEvaluatorWithConfig =
607- autoscaler .getCustomEvaluatorIfRequired (context .getConfiguration ());
608- assertNotNull (customEvaluatorWithConfig );
609- assertInstanceOf (CustomEvaluator .class , customEvaluatorWithConfig .f0 );
610- var customEvaluatorConfig = customEvaluatorWithConfig .f1 ;
611- assertNotNull (customEvaluatorConfig );
612- int expectedKeyCount = 0 ;
613- assertEquals (expectedKeyCount , customEvaluatorConfig .keySet ().size ());
614-
615- Set <String > expectedKeys = Set .of ();
616- assertTrue (customEvaluatorConfig .keySet ().containsAll (expectedKeys ));
565+ var customEvaluatorConfigNoCustomEvaluators =
566+ autoscalerWithoutCustomEvaluator .getCustomEvaluatorIfRequired (
567+ context .getConfiguration ());
568+ assertNull (customEvaluatorConfigNoCustomEvaluators );
617569 }
618570}
0 commit comments