yangwwei commented on a change in pull request #173:
URL: 
https://github.com/apache/incubator-yunikorn-core/pull/173#discussion_r450699806



##########
File path: pkg/scheduler/scheduling_queue_test.go
##########
@@ -827,3 +1118,157 @@ func TestIsEmpty(t *testing.T) {
        leaf.addSchedulingApplication(app)
        assert.Equal(t, leaf.isEmpty(), false, "queue with registered app 
should not be empty")
 }
+
+func TestGetOutstandingRequest(t *testing.T) {
+       const app1ID = "app1"
+       const app2ID = "app1"
+
+       // queue structure:
+       // root
+       //   - queue1 (max.cpu = 10)
+       //   - queue2 (max.cpu = 5)
+       //
+       // submit app1 to root.queue1, app2 to root.queue2
+       // app1 asks for 20 1x1CPU requests, app2 asks for 20 1x1CPU requests
+       // verify the outstanding requests for each of the queue is up to its 
max capacity, 10/5 respectively
+       root, err := createRootQueue(nil)
+       assert.NilError(t, err, "failed to create root queue with limit")
+       var queue1, queue2 *SchedulingQueue
+       queue1, err = createManagedQueue(root, "queue1", false, 
map[string]string{"cpu": "10"})
+       assert.NilError(t, err, "failed to create queue1 queue")
+       queue2, err = createManagedQueue(root, "queue2", false, 
map[string]string{"cpu": "5"})
+       assert.NilError(t, err, "failed to create queue2 queue")
+
+       app1Info := cache.NewApplicationInfo(app1ID, "default", "root.queue1", 
security.UserGroup{}, nil)
+       app1 := newSchedulingApplication(app1Info)
+       app1.queue = queue1
+       queue1.addSchedulingApplication(app1)
+       res, err := resources.NewResourceFromConf(map[string]string{"cpu": "1"})
+       assert.NilError(t, err, "failed to create basic resource")
+       for i := 0; i < 20; i++ {
+               _, err = app1.addAllocationAsk(
+                       newAllocationAsk(fmt.Sprintf("alloc-%d", i), app1ID, 
res))
+               assert.NilError(t, err, "failed to add allocation ask")
+       }
+
+       app2Info := cache.NewApplicationInfo(app2ID, "default", "root.queue2", 
security.UserGroup{}, nil)
+       app2 := newSchedulingApplication(app2Info)
+       app2.queue = queue2
+       queue2.addSchedulingApplication(app2)
+       for i := 0; i < 20; i++ {
+               _, err = app2.addAllocationAsk(
+                       newAllocationAsk(fmt.Sprintf("alloc-%d", i), app2ID, 
res))
+               assert.NilError(t, err, "failed to add allocation ask")
+       }
+
+       // verify get outstanding requests for root, and child queues
+       rootTotal := newOutstandingRequests()
+       root.getQueueOutstandingRequests(rootTotal)
+       assert.Equal(t, len(rootTotal.getRequests()), 15)
+
+       queue1Total := newOutstandingRequests()
+       queue1.getQueueOutstandingRequests(queue1Total)
+       assert.Equal(t, len(queue1Total.getRequests()), 10)
+
+       queue2Total := newOutstandingRequests()
+       queue2.getQueueOutstandingRequests(queue2Total)
+       assert.Equal(t, len(queue2Total.getRequests()), 5)
+
+       // simulate queue1 has some allocating resources
+       // after allocation, the max available becomes to be 5
+       allocatingRest := map[string]string{"cpu": "5"}
+       allocation, err := resources.NewResourceFromConf(allocatingRest)
+       assert.NilError(t, err, "failed to create basic resource")
+       queue1.incAllocatingResource(allocation)
+
+       queue1Total = newOutstandingRequests()
+       queue1.getQueueOutstandingRequests(queue1Total)
+       assert.Equal(t, len(queue1Total.getRequests()), 5)
+
+       queue2Total = newOutstandingRequests()
+       queue2.getQueueOutstandingRequests(queue2Total)
+       assert.Equal(t, len(queue2Total.getRequests()), 5)
+
+       rootTotal = newOutstandingRequests()
+       root.getQueueOutstandingRequests(rootTotal)
+       assert.Equal(t, len(rootTotal.getRequests()), 10)
+
+       // remove app2 from queue2
+       queue2.removeSchedulingApplication(app2)
+       queue2Total = newOutstandingRequests()
+       queue2.getQueueOutstandingRequests(queue2Total)
+       assert.Equal(t, len(queue2Total.getRequests()), 0)
+
+       rootTotal = newOutstandingRequests()
+       root.getQueueOutstandingRequests(rootTotal)
+       assert.Equal(t, len(rootTotal.getRequests()), 5)
+}
+
+func TestGetOutstandingRequestWithStateAwareSortingPolicy(t *testing.T) {
+       const app1ID = "app1"
+       const app2ID = "app2"

Review comment:
       Removed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to