yangwwei commented on pull request #320:
URL: 
https://github.com/apache/incubator-yunikorn-core/pull/320#issuecomment-917256634


   hi @0yukali0  sorry for the late response. I just looked more into this PR.
   The priority actually has 2 forms, 1 is with the int value, the other is the 
priorityClass which is a string value, today the latter form is not fully 
implemented, but that's part of the proto, so it will be good to cover that as 
well. And regarding the UT itself, I think it can be simplified for easier 
reading. Below is what I thought in my mind, pls take a look:
   
   ```
   func newPriorityValue(v int32) *si.Priority{
        return &si.Priority{
                Priority: &si.Priority_PriorityValue{
                        PriorityValue: v},
        }
   }
   
   func newPriorityClass(priorityClassName string) *si.Priority {
        return &si.Priority{
                Priority: &si.Priority_PriorityClassName{
                        PriorityClassName: priorityClassName},
        }
   }
   
   func TestSetPriority(t *testing.T) {
        var tests = []struct {
                testMessage           string
                priority              *si.Priority
                out                   int32
        }{
                // Set priorirty via NewAllocationAsk
                {"No priority setting",nil, 0},
                {"Set empty priority", &si.Priority{}, 0},
                {"Set positive priority value", newPriorityValue(1), 1},
                {"Set negative priority value", newPriorityValue(-100), -100},
                {"Set priority class", newPriorityClass("p0"), 0},
        }
   
        for _, tt := range tests {
                res := 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10})
                t.Run(tt.testMessage, func(t *testing.T) {
                        siAsk := &si.AllocationAsk{
                                AllocationKey:  "ask-1",
                                ApplicationID:  "app-1",
                                MaxAllocations: 1,
                                Priority:       tt.priority,
                                ResourceAsk:    res.ToProto(),
                        }
   
                        ask := NewAllocationAsk(siAsk)
                        if ask.priority != tt.out {
                                t.Errorf("result %s, Want %v, got %v", 
tt.testMessage, tt.out, ask.priority)
                        }
                })
        }
   }
   ```


-- 
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.

To unsubscribe, e-mail: [email protected]

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


Reply via email to