@@ -3016,6 +3016,119 @@ func TestSetMaxRESTResponseSize(t *testing.T) {
30163016 assert .Equal (t , uint64 (10000 ), maxRESTResponseSize .Load ())
30173017}
30183018
3019+ func TestGetPartitionSchedulingOrderHandler (t * testing.T ) {
3020+ // Setup partition with default configuration
3021+ part := setup (t , configDefault , 1 )
3022+
3023+ // Create applications with pending requests to trigger scheduling order
3024+ app1 := addApp (t , "app-1" , part , "root.default" , false )
3025+ app2 := addApp (t , "app-2" , part , "root.default" , false )
3026+ app3 := addApp (t , "app-3" , part , "root.default" , false )
3027+
3028+ // Add pending allocation requests to applications
3029+ res1 := & si.Resource {
3030+ Resources : map [string ]* si.Quantity {"memory" : {Value : 100 }, "vcore" : {Value : 1 }},
3031+ }
3032+ ask1 := objects .NewAllocationFromSI (& si.Allocation {
3033+ ApplicationID : "app-1" ,
3034+ PartitionName : part .Name ,
3035+ ResourcePerAlloc : res1 })
3036+ err := app1 .AddAllocationAsk (ask1 )
3037+ assert .NilError (t , err , "ask should have been added to app-1" )
3038+
3039+ res2 := & si.Resource {
3040+ Resources : map [string ]* si.Quantity {"memory" : {Value : 200 }, "vcore" : {Value : 2 }},
3041+ }
3042+ ask2 := objects .NewAllocationFromSI (& si.Allocation {
3043+ ApplicationID : "app-2" ,
3044+ PartitionName : part .Name ,
3045+ ResourcePerAlloc : res2 })
3046+ err = app2 .AddAllocationAsk (ask2 )
3047+ assert .NilError (t , err , "ask should have been added to app-2" )
3048+
3049+ res3 := & si.Resource {
3050+ Resources : map [string ]* si.Quantity {"memory" : {Value : 150 }, "vcore" : {Value : 1 }},
3051+ }
3052+ ask3 := objects .NewAllocationFromSI (& si.Allocation {
3053+ ApplicationID : "app-3" ,
3054+ PartitionName : part .Name ,
3055+ ResourcePerAlloc : res3 })
3056+ err = app3 .AddAllocationAsk (ask3 )
3057+ assert .NilError (t , err , "ask should have been added to app-3" )
3058+
3059+ NewWebApp (schedulerContext .Load (), nil )
3060+
3061+ // Test successful scheduling order retrieval
3062+ var req * http.Request
3063+ req , err = createRequest (t , "/ws/v1/partition/default/schedulingorder" , map [string ]string {"partition" : partitionNameWithoutClusterID })
3064+ assert .NilError (t , err , "Get Scheduling Order Handler request failed" )
3065+ resp := & MockResponseWriter {}
3066+ var schedulingOrderDao []* dao.SchedulingOrderDAO
3067+ getPartitionSchedulingOrder (resp , req )
3068+ err = json .Unmarshal (resp .outputBytes , & schedulingOrderDao )
3069+ assert .NilError (t , err , unmarshalError )
3070+
3071+ // Validate response structure and content
3072+ assert .Assert (t , len (schedulingOrderDao ) > 0 , "scheduling order should contain at least one queue" )
3073+
3074+ // Verify that queues with pending resources are included
3075+ queueFound := false
3076+ for _ , queueOrder := range schedulingOrderDao {
3077+ if queueOrder .QueueName == "root.default" {
3078+ queueFound = true
3079+ // Verify that applications with pending requests are included
3080+ assert .Assert (t , len (queueOrder .ApplicationIDs ) >= 3 , "queue root.default should have at least 3 applications" )
3081+ // Check that our test applications are in the list
3082+ appFound1 , appFound2 , appFound3 := false , false , false
3083+ for _ , appID := range queueOrder .ApplicationIDs {
3084+ if appID == "app-1" {
3085+ appFound1 = true
3086+ }
3087+ if appID == "app-2" {
3088+ appFound2 = true
3089+ }
3090+ if appID == "app-3" {
3091+ appFound3 = true
3092+ }
3093+ }
3094+ assert .Assert (t , appFound1 , "app-1 should be in scheduling order" )
3095+ assert .Assert (t , appFound2 , "app-2 should be in scheduling order" )
3096+ assert .Assert (t , appFound3 , "app-3 should be in scheduling order" )
3097+ }
3098+ }
3099+ assert .Assert (t , queueFound , "queue root.default should be found in scheduling order" )
3100+
3101+ // Test nonexistent partition
3102+ req , err = createRequest (t , "/ws/v1/partition/default/schedulingorder" , map [string ]string {"partition" : "notexists" })
3103+ assert .NilError (t , err , "Get Scheduling Order Handler request failed" )
3104+ resp = & MockResponseWriter {}
3105+ getPartitionSchedulingOrder (resp , req )
3106+ assertPartitionNotExists (t , resp )
3107+
3108+ // Test missing params name
3109+ req , err = http .NewRequest ("GET" , "/ws/v1/partition/default/schedulingorder" , strings .NewReader ("" ))
3110+ assert .NilError (t , err , "Get Scheduling Order Handler request failed" )
3111+ resp = & MockResponseWriter {}
3112+ getPartitionSchedulingOrder (resp , req )
3113+ assertParamsMissing (t , resp )
3114+
3115+ // Test empty scheduling order (partition with no pending requests)
3116+ // Create a new partition with no applications
3117+ emptyPart := setup (t , configDefault , 1 )
3118+ // Add an application but without pending requests
3119+ addApp (t , "app-empty" , emptyPart , "root.default" , false )
3120+
3121+ req , err = createRequest (t , "/ws/v1/partition/default/schedulingorder" , map [string ]string {"partition" : partitionNameWithoutClusterID })
3122+ assert .NilError (t , err , "Get Scheduling Order Handler request failed" )
3123+ resp = & MockResponseWriter {}
3124+ var emptySchedulingOrderDao []* dao.SchedulingOrderDAO
3125+ getPartitionSchedulingOrder (resp , req )
3126+ err = json .Unmarshal (resp .outputBytes , & emptySchedulingOrderDao )
3127+ assert .NilError (t , err , unmarshalError )
3128+ // Should return empty array when no queues have pending resources
3129+ assert .Equal (t , len (emptySchedulingOrderDao ), 0 , "scheduling order should be empty when no pending requests exist" )
3130+ }
3131+
30193132type ResponseRecorderWithDeadline struct {
30203133 * httptest.ResponseRecorder
30213134 setWriteFails bool
0 commit comments