pbacsko commented on a change in pull request #356:
URL: 
https://github.com/apache/incubator-yunikorn-core/pull/356#discussion_r781482493



##########
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:
       Nit: can't this be an assert as well? 

##########
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")
+       }
+       assert.Assert(t, resources.Equals(node.GetAllocatedResource(), piece), 
"allocated resource not set correctly %v got %v", piece, 
node.GetAllocatedResource())
+
+       // clean up all should be zero
+       if node.RemoveAllocation(allocID) == nil {
+               t.Error("allocation should have been removed but was not")

Review comment:
       Same here




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