wilfred-s commented on a change in pull request #356:
URL:
https://github.com/apache/incubator-yunikorn-core/pull/356#discussion_r781737383
##########
File path: pkg/scheduler/objects/node_test.go
##########
@@ -488,6 +488,40 @@ func TestRemoveAllocation(t *testing.T) {
}
}
+func TestNodeReplaceAllocation(t *testing.T) {
+ node := newNode("node-123", map[string]resources.Quantity{"first": 100,
"second": 200})
+ assert.Assert(t, resources.IsZero(node.GetAllocatedResource()), "failed
to initialize node")
+
+ // allocate half of the resources available and check the calculation
+ phID := "ph-1"
+ half :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50,
"second": 100})
+ ph := newPlaceholderAlloc(appID1, phID, nodeID1, "queue-1", half)
+ node.AddAllocation(ph)
+ if node.GetAllocation(phID) == nil {
+ t.Fatal("failed to add placeholder allocation")
+ }
+ assert.Assert(t, resources.Equals(node.GetAllocatedResource(), half),
"allocated resource not set correctly %v got %v", half,
node.GetAllocatedResource())
+
+ allocID := "real-1"
+ piece :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 25,
"second": 50})
+ alloc := newAllocation(appID1, allocID, nodeID1, "queue-1", piece)
+ // calculate the delta: new allocation resource - placeholder (should
be negative!)
+ delta := resources.Sub(piece, half)
+ assert.Assert(t, delta.HasNegativeValue(), "expected negative values in
delta")
+ // swap and check the calculation
+ node.ReplaceAllocation(phID, alloc, delta)
+ if node.GetAllocation(allocID) == nil {
+ t.Fatal("failed to replace allocation: allocation not returned")
Review comment:
We should file a follow up for that, the node testing code has a large
number of places where it should be using asserts.
Nil object checks do look a bit weird in the assert, might not improve
readability:
```
assert.Assert(t, node.GetAllocation(allocID) != nil, "failed to replace
allocation: allocation not returned")
```
--
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]