craigcondit commented on code in PR #923:
URL: https://github.com/apache/yunikorn-core/pull/923#discussion_r1709603797


##########
pkg/common/resources/resources.go:
##########
@@ -884,6 +909,29 @@ func ComponentWiseMinPermissive(left, right *Resource) 
*Resource {
        return out
 }
 
+// MergeIfNotPresent Returns a new Resource by merging resource type values 
present in right with left
+// only if resource type not present in left.
+// If either Resource passed in is nil the other Resource is returned
+// If a Resource type is missing from one of the Resource, it is considered 
empty and the quantity from the other Resource is returned
+func MergeIfNotPresent(left, right *Resource) *Resource {
+       if right == nil && left == nil {
+               return nil
+       }
+       if left == nil {
+               return right.Clone()
+       }
+       if right == nil {
+               return left.Clone()
+       }
+       out := left

Review Comment:
   I think this should be `out := left.Clone()`, otherwise you are mutating the 
original resource. This seems wrong, since you're returning a new one.



##########
pkg/scheduler/objects/preemption_queue_test.go:
##########
@@ -123,113 +123,185 @@ func TestGetPreemptableResource(t *testing.T) {
 
 func TestGetRemainingGuaranteedResource(t *testing.T) {
        // no guaranteed and no usage. so no remaining
+       rootQ, parentQ, childQ1, childQ2, childQ3 := setup(t)
+       smallestRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5})
+       childRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{"second": 5})
+       expectedSmallestRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 3})
+       expectedSmallestRes1 := smallestRes.Clone()
+       expectedSmallestRes1.MultiplyTo(float64(0))
+       var tests = []struct {
+               testName          string
+               askQueue          *Queue
+               childQ2Remaining  *resources.Resource
+               childQ2Remaining1 *resources.Resource
+       }{
+               
{"UnderGuaranteedChildQueue_Under_OverGuaranteedParentQueue_Does_Not_Have_Higher_Precedence_When_AskQueue_Is_Different_From_UnderGuaranteedChildQueue",
 childQ3,
+                       resources.Multiply(smallestRes, -1), 
resources.Add(expectedSmallestRes1, resources.Multiply(childRes, -1))},
+               
{"UnderGuaranteedChildQueue_Under_OverGuaranteedParentQueue_Has_Higher_Precedence_When_AskQueue_Is_Same_As_UnderGuaranteedChildQueue",
 childQ2,
+                       resources.Multiply(smallestRes, 0), 
resources.Add(expectedSmallestRes, resources.Multiply(childRes, -1))},
+       }
+       for _, tt := range tests {
+               var rootRemaining, pRemaining, cRemaining1, cRemaining2 
*resources.Resource
+               resetQueueResources(rootQ, parentQ, childQ1, childQ2)
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, 
map[string]*resources.Resource{rootQ.QueuePath: nil, parentQ.QueuePath: nil, 
childQ1.QueuePath: nil, childQ2.QueuePath: nil}, tt.askQueue)
+               assertZeroRemaining(t, rootRemaining, pRemaining, cRemaining1, 
cRemaining2)
+
+               // no guaranteed and no usage, but max res set. so min of 
guaranteed and max should be remaining
+               smallestRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5})
+               rootQ.maxResource = resources.Multiply(smallestRes, 4)
+               parentQ.maxResource = resources.Multiply(smallestRes, 2)
+               childQ1.maxResource = smallestRes
+               childQ2.maxResource = smallestRes
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, 
map[string]*resources.Resource{rootQ.QueuePath: nil, parentQ.QueuePath: nil, 
childQ1.QueuePath: nil, childQ2.QueuePath: nil}, tt.askQueue)
+               assertZeroRemaining(t, rootRemaining, pRemaining, cRemaining1, 
cRemaining2)
+
+               // guaranteed set only for queue at specific levels but no 
usage.
+               // so remaining for queues without guaranteed quota inherits 
from parent queue based on min perm calculation
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, 
map[string]*resources.Resource{rootQ.QueuePath: resources.Multiply(smallestRes, 
2), parentQ.QueuePath: nil, childQ1.QueuePath: childRes, childQ2.QueuePath: 
nil}, tt.askQueue)
+               assert.Assert(t, resources.Equals(rootRemaining, 
resources.Multiply(smallestRes, 2)), "guaranteed set, but no usage. so all 
guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(pRemaining, 
resources.Multiply(smallestRes, 2)), "guaranteed not set, also no usage. 
However, parent's remaining should be used")
+               assert.Assert(t, resources.Equals(cRemaining1, 
resources.Add(resources.Multiply(smallestRes, 2), childRes)), "guaranteed not 
set, also no usage. However, parent's remaining should be used")
+               assert.Assert(t, resources.Equals(cRemaining2, 
resources.Multiply(smallestRes, 2)), "guaranteed not set, also no usage. 
However, parent's remaining should be used")
+
+               // guaranteed set but no usage. so nothing to preempt
+               // clean start for the snapshot: whole hierarchy with guarantee
+               queueRes := map[string]*resources.Resource{rootQ.QueuePath: 
resources.Multiply(smallestRes, 2), parentQ.QueuePath: smallestRes, 
childQ1.QueuePath: childRes, childQ2.QueuePath: smallestRes}
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, queueRes, 
tt.askQueue)
+               assert.Assert(t, resources.Equals(rootRemaining, 
resources.Multiply(smallestRes, 2)), "guaranteed set, but no usage. so all 
guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(pRemaining, smallestRes), 
"guaranteed set, but no usage. so all guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(cRemaining1, 
resources.Add(smallestRes, childRes)), "guaranteed set, but no usage. so all 
guaranteed + parent remaining guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(cRemaining2, smallestRes), 
"guaranteed set, but no usage. so all its guaranteed (because it is lesser than 
parent's guaranteed) should be in remaining")
+
+               // clean start for the snapshot: all set guaranteed
+               // add usage to parent + root: use all guaranteed at parent 
level
+               // add usage to child2: use all guaranteed set
+               // child2 remaining behaviour changes based on the ask queue.
+               // When ask queue is child2, its own values has higher 
precedence over the parent or ancestor for common resource types.
+               // for extra resources available in parent or ancestor, it can 
simply inherit.
+               // When ask queue is child3 (diverged from very earlier branch, 
not sharing any common queue path), its remaining is min permissive of its own 
values and parent or ancestor values.
+               rootQ.allocatedResource = resources.Multiply(smallestRes, 2)
+               parentQ.allocatedResource = resources.Multiply(smallestRes, 2)
+               childQ2.allocatedResource = resources.Multiply(smallestRes, 1)
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, queueRes, 
tt.askQueue)
+               assert.Assert(t, resources.IsZero(rootRemaining), "guaranteed 
set, used completely. so all guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(pRemaining, 
resources.Multiply(smallestRes, -1)), "guaranteed set, used double than 
guaranteed. so remaining should be in -ve")
+               assert.Assert(t, resources.Equals(cRemaining1, 
resources.Add(resources.Multiply(smallestRes, -1), childRes)), "guaranteed set, 
but no usage. However remaining should include its all guaranteed + parent 
remaining guaranteed")
+               assert.Assert(t, resources.Equals(cRemaining2, 
tt.childQ2Remaining), "guaranteed set, used all guaranteed. remaining should be 
based on ask queue")
+
+               // clean start for the snapshot: all set guaranteed
+               // add usage for all: use exactly guaranteed at parent and 
child level
+               // parent guarantee used for one type child guarantee used for 
second type
+               bothRes := resources.Multiply(smallestRes, 2)
+               bothRes.AddTo(childRes)
+               rootQ.allocatedResource = bothRes
+               bothRes = resources.Add(smallestRes, childRes)
+               parentQ.allocatedResource = bothRes
+               childQ1.allocatedResource = childRes
+               childQ2.allocatedResource = smallestRes
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, queueRes, 
tt.askQueue)
+               assert.Assert(t, resources.IsZero(rootRemaining), "guaranteed 
set, used completely. usage also has extra resource types. However, no 
remaining")
+               assert.Assert(t, resources.IsZero(pRemaining), "guaranteed set, 
used completely. usage also has extra resource types. However, no remaining")
+               assert.Assert(t, resources.IsZero(cRemaining1), "guaranteed 
set, used completely. so, no remaining")
+               assert.Assert(t, resources.IsZero(cRemaining2), "guaranteed 
set, but no usage. Still, no remaining in guaranteed because of its parent 
queue")
+
+               // clean start for the snapshot: all set guaranteed
+               // add usage for root + parent: use exactly guaranteed at 
parent and child level
+               // add usage to child1: use double than guaranteed
+               // parent guarantee used for one type child guarantee used for 
second type
+               bothRes = resources.Multiply(smallestRes, 2)
+               bothRes.AddTo(resources.Multiply(childRes, 2))
+               rootQ.allocatedResource = bothRes
+               bothRes = resources.Add(smallestRes, 
resources.Multiply(childRes, 2))
+               parentQ.allocatedResource = bothRes
+               childQ1.allocatedResource = resources.Multiply(childRes, 2)
+               childQ2.allocatedResource = smallestRes
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, queueRes, 
tt.askQueue)
+               assert.Assert(t, resources.IsZero(rootRemaining), "guaranteed 
set, used completely. usage also has extra resource types. However, no 
remaining")
+               assert.Assert(t, resources.IsZero(pRemaining), "guaranteed set, 
used completely. usage also has extra resource types. However, no remaining")
+               assert.Assert(t, resources.Equals(cRemaining1, 
resources.Multiply(childRes, -1)), "guaranteed set, used double than 
guaranteed. so remaining should be in -ve")
+               assert.Assert(t, resources.IsZero(cRemaining2), "guaranteed 
set, but no usage. Still, no remaining in guaranteed because of its parent 
queue")
+
+               // clean start for the snapshot: all set guaranteed
+               // add usage for root + parent: use exactly guaranteed for one 
resource and over guaranteed for another resource at parent level
+               // add usage to child1: use double than guaranteed
+               // add usage to child2: use lesser than guaranteed.
+               // child2 remaining behaviour changes based on the ask queue.
+               // When ask queue is child2, its own values has higher 
precedence over the parent or ancestor for common resource types.
+               // for extra resources available in parent or ancestor, it can 
simply inherit.
+               // When ask queue is child3 (diverged from very earlier branch, 
not sharing any common queue path), its remaining is min permissive of its own 
values and parent or ancestor values.
+               childQ2.allocatedResource = 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 2})
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, 
map[string]*resources.Resource{rootQ.QueuePath: resources.Multiply(smallestRes, 
2), parentQ.QueuePath: resources.Add(smallestRes, resources.Multiply(childRes, 
1)), childQ1.QueuePath: childRes, childQ2.QueuePath: smallestRes}, tt.askQueue)
+               assert.Assert(t, resources.IsZero(rootRemaining), "guaranteed 
set, used completely. usage also has extra resource types. However, no 
remaining")
+               assert.Assert(t, resources.DeepEquals(pRemaining, 
resources.Add(expectedSmallestRes1, resources.Multiply(childRes, -1))), 
"guaranteed set, one resource type used completely. usage also has another 
resource types which is used bit more. remaining should have zero for one 
resource type and -ve for another")
+               assert.Assert(t, resources.DeepEquals(cRemaining1, 
resources.Add(expectedSmallestRes1, resources.Multiply(childRes, -1))), 
"guaranteed set, used double than guaranteed. so remaining should be in -ve")
+               assert.Assert(t, resources.DeepEquals(cRemaining2, 
tt.childQ2Remaining1), "guaranteed set, used bit lesser. parent's usage also 
has extra resource types. remaining should be based on ask queue")
+       }
+}
+
+func setup(t *testing.T) (*Queue, *Queue, *Queue, *Queue, *Queue) {
        rootQ, err := createRootQueue(map[string]string{})
        assert.NilError(t, err)
-       var parentQ, childQ1, childQ2 *Queue
+       var parentQ, childQ1, childQ2, parent1Q, childQ3 *Queue
        parentQ, err = createManagedQueue(rootQ, "parent", true, 
map[string]string{})
        assert.NilError(t, err)
+       parent1Q, err = createManagedQueue(rootQ, "parent1", true, 
map[string]string{})
+       assert.NilError(t, err)
        childQ1, err = createManagedQueue(parentQ, "child1", false, 
map[string]string{})
        assert.NilError(t, err)
        childQ2, err = createManagedQueue(parentQ, "child2", false, 
map[string]string{})
        assert.NilError(t, err)
-       rootRemaining, pRemaining, cRemaining1, cRemaining2 := 
getRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2)
-       assert.Assert(t, resources.IsZero(rootRemaining), "guaranteed and max 
res not set, so no remaining")
-       assert.Assert(t, resources.IsZero(pRemaining), "guaranteed and max res 
not set, so no remaining")
-       assert.Assert(t, resources.IsZero(cRemaining1), "guaranteed and max res 
not set, so no remaining")
-       assert.Assert(t, resources.IsZero(cRemaining2), "guaranteed and max res 
not set, so no remaining")
-
-       // no guaranteed and no usage, but max res set. so min of guaranteed 
and max should be remaining
-       smallestRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5})
-       rootQ.maxResource = resources.Multiply(smallestRes, 4)
-       parentQ.maxResource = resources.Multiply(smallestRes, 2)
-       childQ1.maxResource = smallestRes
-       childQ2.maxResource = smallestRes
-       rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
getRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2)
+       childQ3, err = createManagedQueue(parent1Q, "child3", false, 
map[string]string{})
+       assert.NilError(t, err)
+       return rootQ, parentQ, childQ1, childQ2, childQ3
+}
+func assertZeroRemaining(t *testing.T, rootRemaining *resources.Resource, 
pRemaining *resources.Resource, cRemaining1 *resources.Resource, cRemaining2 
*resources.Resource) {

Review Comment:
   Nit: Add a newline here.



##########
pkg/common/resources/resources_test.go:
##########
@@ -588,6 +588,46 @@ func TestComponentWiseMinOnlyExisting(t *testing.T) {
        }
 }
 
+func TestComponentWiseMinPermissiveWithPrecedence(t *testing.T) {

Review Comment:
   This test name makes no sense. You're not calling that method from the test 
at all.



##########
pkg/scheduler/objects/preemption_queue_test.go:
##########
@@ -123,113 +123,185 @@ func TestGetPreemptableResource(t *testing.T) {
 
 func TestGetRemainingGuaranteedResource(t *testing.T) {
        // no guaranteed and no usage. so no remaining
+       rootQ, parentQ, childQ1, childQ2, childQ3 := setup(t)
+       smallestRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5})
+       childRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{"second": 5})
+       expectedSmallestRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 3})
+       expectedSmallestRes1 := smallestRes.Clone()
+       expectedSmallestRes1.MultiplyTo(float64(0))
+       var tests = []struct {
+               testName          string
+               askQueue          *Queue
+               childQ2Remaining  *resources.Resource
+               childQ2Remaining1 *resources.Resource
+       }{
+               
{"UnderGuaranteedChildQueue_Under_OverGuaranteedParentQueue_Does_Not_Have_Higher_Precedence_When_AskQueue_Is_Different_From_UnderGuaranteedChildQueue",
 childQ3,
+                       resources.Multiply(smallestRes, -1), 
resources.Add(expectedSmallestRes1, resources.Multiply(childRes, -1))},
+               
{"UnderGuaranteedChildQueue_Under_OverGuaranteedParentQueue_Has_Higher_Precedence_When_AskQueue_Is_Same_As_UnderGuaranteedChildQueue",
 childQ2,
+                       resources.Multiply(smallestRes, 0), 
resources.Add(expectedSmallestRes, resources.Multiply(childRes, -1))},
+       }
+       for _, tt := range tests {
+               var rootRemaining, pRemaining, cRemaining1, cRemaining2 
*resources.Resource
+               resetQueueResources(rootQ, parentQ, childQ1, childQ2)
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, 
map[string]*resources.Resource{rootQ.QueuePath: nil, parentQ.QueuePath: nil, 
childQ1.QueuePath: nil, childQ2.QueuePath: nil}, tt.askQueue)
+               assertZeroRemaining(t, rootRemaining, pRemaining, cRemaining1, 
cRemaining2)
+
+               // no guaranteed and no usage, but max res set. so min of 
guaranteed and max should be remaining
+               smallestRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5})
+               rootQ.maxResource = resources.Multiply(smallestRes, 4)
+               parentQ.maxResource = resources.Multiply(smallestRes, 2)
+               childQ1.maxResource = smallestRes
+               childQ2.maxResource = smallestRes
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, 
map[string]*resources.Resource{rootQ.QueuePath: nil, parentQ.QueuePath: nil, 
childQ1.QueuePath: nil, childQ2.QueuePath: nil}, tt.askQueue)
+               assertZeroRemaining(t, rootRemaining, pRemaining, cRemaining1, 
cRemaining2)
+
+               // guaranteed set only for queue at specific levels but no 
usage.
+               // so remaining for queues without guaranteed quota inherits 
from parent queue based on min perm calculation
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, 
map[string]*resources.Resource{rootQ.QueuePath: resources.Multiply(smallestRes, 
2), parentQ.QueuePath: nil, childQ1.QueuePath: childRes, childQ2.QueuePath: 
nil}, tt.askQueue)
+               assert.Assert(t, resources.Equals(rootRemaining, 
resources.Multiply(smallestRes, 2)), "guaranteed set, but no usage. so all 
guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(pRemaining, 
resources.Multiply(smallestRes, 2)), "guaranteed not set, also no usage. 
However, parent's remaining should be used")
+               assert.Assert(t, resources.Equals(cRemaining1, 
resources.Add(resources.Multiply(smallestRes, 2), childRes)), "guaranteed not 
set, also no usage. However, parent's remaining should be used")
+               assert.Assert(t, resources.Equals(cRemaining2, 
resources.Multiply(smallestRes, 2)), "guaranteed not set, also no usage. 
However, parent's remaining should be used")
+
+               // guaranteed set but no usage. so nothing to preempt
+               // clean start for the snapshot: whole hierarchy with guarantee
+               queueRes := map[string]*resources.Resource{rootQ.QueuePath: 
resources.Multiply(smallestRes, 2), parentQ.QueuePath: smallestRes, 
childQ1.QueuePath: childRes, childQ2.QueuePath: smallestRes}
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, queueRes, 
tt.askQueue)
+               assert.Assert(t, resources.Equals(rootRemaining, 
resources.Multiply(smallestRes, 2)), "guaranteed set, but no usage. so all 
guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(pRemaining, smallestRes), 
"guaranteed set, but no usage. so all guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(cRemaining1, 
resources.Add(smallestRes, childRes)), "guaranteed set, but no usage. so all 
guaranteed + parent remaining guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(cRemaining2, smallestRes), 
"guaranteed set, but no usage. so all its guaranteed (because it is lesser than 
parent's guaranteed) should be in remaining")
+
+               // clean start for the snapshot: all set guaranteed
+               // add usage to parent + root: use all guaranteed at parent 
level
+               // add usage to child2: use all guaranteed set
+               // child2 remaining behaviour changes based on the ask queue.
+               // When ask queue is child2, its own values has higher 
precedence over the parent or ancestor for common resource types.
+               // for extra resources available in parent or ancestor, it can 
simply inherit.
+               // When ask queue is child3 (diverged from very earlier branch, 
not sharing any common queue path), its remaining is min permissive of its own 
values and parent or ancestor values.
+               rootQ.allocatedResource = resources.Multiply(smallestRes, 2)
+               parentQ.allocatedResource = resources.Multiply(smallestRes, 2)
+               childQ2.allocatedResource = resources.Multiply(smallestRes, 1)
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, queueRes, 
tt.askQueue)
+               assert.Assert(t, resources.IsZero(rootRemaining), "guaranteed 
set, used completely. so all guaranteed should be in remaining")
+               assert.Assert(t, resources.Equals(pRemaining, 
resources.Multiply(smallestRes, -1)), "guaranteed set, used double than 
guaranteed. so remaining should be in -ve")
+               assert.Assert(t, resources.Equals(cRemaining1, 
resources.Add(resources.Multiply(smallestRes, -1), childRes)), "guaranteed set, 
but no usage. However remaining should include its all guaranteed + parent 
remaining guaranteed")
+               assert.Assert(t, resources.Equals(cRemaining2, 
tt.childQ2Remaining), "guaranteed set, used all guaranteed. remaining should be 
based on ask queue")
+
+               // clean start for the snapshot: all set guaranteed
+               // add usage for all: use exactly guaranteed at parent and 
child level
+               // parent guarantee used for one type child guarantee used for 
second type
+               bothRes := resources.Multiply(smallestRes, 2)
+               bothRes.AddTo(childRes)
+               rootQ.allocatedResource = bothRes
+               bothRes = resources.Add(smallestRes, childRes)
+               parentQ.allocatedResource = bothRes
+               childQ1.allocatedResource = childRes
+               childQ2.allocatedResource = smallestRes
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, queueRes, 
tt.askQueue)
+               assert.Assert(t, resources.IsZero(rootRemaining), "guaranteed 
set, used completely. usage also has extra resource types. However, no 
remaining")
+               assert.Assert(t, resources.IsZero(pRemaining), "guaranteed set, 
used completely. usage also has extra resource types. However, no remaining")
+               assert.Assert(t, resources.IsZero(cRemaining1), "guaranteed 
set, used completely. so, no remaining")
+               assert.Assert(t, resources.IsZero(cRemaining2), "guaranteed 
set, but no usage. Still, no remaining in guaranteed because of its parent 
queue")
+
+               // clean start for the snapshot: all set guaranteed
+               // add usage for root + parent: use exactly guaranteed at 
parent and child level
+               // add usage to child1: use double than guaranteed
+               // parent guarantee used for one type child guarantee used for 
second type
+               bothRes = resources.Multiply(smallestRes, 2)
+               bothRes.AddTo(resources.Multiply(childRes, 2))
+               rootQ.allocatedResource = bothRes
+               bothRes = resources.Add(smallestRes, 
resources.Multiply(childRes, 2))
+               parentQ.allocatedResource = bothRes
+               childQ1.allocatedResource = resources.Multiply(childRes, 2)
+               childQ2.allocatedResource = smallestRes
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, queueRes, 
tt.askQueue)
+               assert.Assert(t, resources.IsZero(rootRemaining), "guaranteed 
set, used completely. usage also has extra resource types. However, no 
remaining")
+               assert.Assert(t, resources.IsZero(pRemaining), "guaranteed set, 
used completely. usage also has extra resource types. However, no remaining")
+               assert.Assert(t, resources.Equals(cRemaining1, 
resources.Multiply(childRes, -1)), "guaranteed set, used double than 
guaranteed. so remaining should be in -ve")
+               assert.Assert(t, resources.IsZero(cRemaining2), "guaranteed 
set, but no usage. Still, no remaining in guaranteed because of its parent 
queue")
+
+               // clean start for the snapshot: all set guaranteed
+               // add usage for root + parent: use exactly guaranteed for one 
resource and over guaranteed for another resource at parent level
+               // add usage to child1: use double than guaranteed
+               // add usage to child2: use lesser than guaranteed.
+               // child2 remaining behaviour changes based on the ask queue.
+               // When ask queue is child2, its own values has higher 
precedence over the parent or ancestor for common resource types.
+               // for extra resources available in parent or ancestor, it can 
simply inherit.
+               // When ask queue is child3 (diverged from very earlier branch, 
not sharing any common queue path), its remaining is min permissive of its own 
values and parent or ancestor values.
+               childQ2.allocatedResource = 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 2})
+               rootRemaining, pRemaining, cRemaining1, cRemaining2 = 
setAndGetRemainingGuaranteed(rootQ, parentQ, childQ1, childQ2, 
map[string]*resources.Resource{rootQ.QueuePath: resources.Multiply(smallestRes, 
2), parentQ.QueuePath: resources.Add(smallestRes, resources.Multiply(childRes, 
1)), childQ1.QueuePath: childRes, childQ2.QueuePath: smallestRes}, tt.askQueue)
+               assert.Assert(t, resources.IsZero(rootRemaining), "guaranteed 
set, used completely. usage also has extra resource types. However, no 
remaining")
+               assert.Assert(t, resources.DeepEquals(pRemaining, 
resources.Add(expectedSmallestRes1, resources.Multiply(childRes, -1))), 
"guaranteed set, one resource type used completely. usage also has another 
resource types which is used bit more. remaining should have zero for one 
resource type and -ve for another")
+               assert.Assert(t, resources.DeepEquals(cRemaining1, 
resources.Add(expectedSmallestRes1, resources.Multiply(childRes, -1))), 
"guaranteed set, used double than guaranteed. so remaining should be in -ve")
+               assert.Assert(t, resources.DeepEquals(cRemaining2, 
tt.childQ2Remaining1), "guaranteed set, used bit lesser. parent's usage also 
has extra resource types. remaining should be based on ask queue")
+       }
+}
+
+func setup(t *testing.T) (*Queue, *Queue, *Queue, *Queue, *Queue) {

Review Comment:
   Normally I'm not in favor of named return values, but when there's 5 of the 
same type... I think it's warranted.



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