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