You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by GitBox <gi...@apache.org> on 2021/12/03 05:12:56 UTC

[GitHub] [incubator-yunikorn-core] wilfred-s commented on a change in pull request #344: [YUNIKORN-963] Fix calculateNodesResourceUsage when node's resource is overallocated

wilfred-s commented on a change in pull request #344:
URL: https://github.com/apache/incubator-yunikorn-core/pull/344#discussion_r761650730



##########
File path: pkg/scheduler/partition_test.go
##########
@@ -361,6 +361,35 @@ func TestRemoveNodeWithPlaceholders(t *testing.T) {
 	assert.Equal(t, 0, len(ph.Releases), "placeholder should have no releases linked anymore")
 }
 
+func TestCalculateNodesResourceUsage(t *testing.T) {
+	partition, err := newBasePartition()
+	assert.NilError(t, err, "partition create failed")
+	oldCapacity := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 100})
+	node := newNodeMaxResource(nodeID1, oldCapacity)
+	err = partition.AddNode(node, nil)
+	assert.NilError(t, err)
+
+	occupiedResources := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50})
+	alloc := objects.NewAllocation(allocID, nodeID1, newAllocationAsk("key", "appID", occupiedResources))
+	node.AddAllocation(alloc)
+	usageMap := partition.calculateNodesResourceUsage()
+	assert.Assert(t, node.GetAvailableResource().Resources["first"] == 50)
+	assert.Equal(t, usageMap["first"][4], 1)
+
+	occupiedResources = resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50})
+	alloc = objects.NewAllocation(allocID, nodeID1, newAllocationAsk("key", "appID", occupiedResources))
+	node.AddAllocation(alloc)
+	usageMap = partition.calculateNodesResourceUsage()
+	assert.Assert(t, node.GetAvailableResource().Resources["first"] == 0)
+	assert.Equal(t, usageMap["first"][9], 1)
+
+	newCapacity := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 80})
+	node.SetCapacity(newCapacity)
+	usageMap = partition.calculateNodesResourceUsage()
+	assert.Assert(t, node.GetAvailableResource().HasNegativeValue() == true)

Review comment:
       This can be simplified by removing the `== true`. The assert checks for boolean to be true

##########
File path: pkg/scheduler/partition_test.go
##########
@@ -361,6 +361,35 @@ func TestRemoveNodeWithPlaceholders(t *testing.T) {
 	assert.Equal(t, 0, len(ph.Releases), "placeholder should have no releases linked anymore")
 }
 
+func TestCalculateNodesResourceUsage(t *testing.T) {
+	partition, err := newBasePartition()
+	assert.NilError(t, err, "partition create failed")
+	oldCapacity := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 100})
+	node := newNodeMaxResource(nodeID1, oldCapacity)
+	err = partition.AddNode(node, nil)
+	assert.NilError(t, err)
+
+	occupiedResources := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50})
+	alloc := objects.NewAllocation(allocID, nodeID1, newAllocationAsk("key", "appID", occupiedResources))
+	node.AddAllocation(alloc)
+	usageMap := partition.calculateNodesResourceUsage()
+	assert.Assert(t, node.GetAvailableResource().Resources["first"] == 50)

Review comment:
       can we change this to an `assert.Equal`?
   It will require replacing the 50 with `resources.Quantity(50)` i.e.:
   ```
   assert.Equal(t, node.GetAvailableResource().Resources["first"], resources.Quantity(50))
   ```

##########
File path: pkg/scheduler/partition_test.go
##########
@@ -361,6 +361,35 @@ func TestRemoveNodeWithPlaceholders(t *testing.T) {
 	assert.Equal(t, 0, len(ph.Releases), "placeholder should have no releases linked anymore")
 }
 
+func TestCalculateNodesResourceUsage(t *testing.T) {
+	partition, err := newBasePartition()
+	assert.NilError(t, err, "partition create failed")
+	oldCapacity := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 100})
+	node := newNodeMaxResource(nodeID1, oldCapacity)
+	err = partition.AddNode(node, nil)
+	assert.NilError(t, err)
+
+	occupiedResources := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50})
+	alloc := objects.NewAllocation(allocID, nodeID1, newAllocationAsk("key", "appID", occupiedResources))
+	node.AddAllocation(alloc)
+	usageMap := partition.calculateNodesResourceUsage()
+	assert.Assert(t, node.GetAvailableResource().Resources["first"] == 50)
+	assert.Equal(t, usageMap["first"][4], 1)
+
+	occupiedResources = resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50})
+	alloc = objects.NewAllocation(allocID, nodeID1, newAllocationAsk("key", "appID", occupiedResources))
+	node.AddAllocation(alloc)
+	usageMap = partition.calculateNodesResourceUsage()
+	assert.Assert(t, node.GetAvailableResource().Resources["first"] == 0)

Review comment:
       same as above assert




-- 
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: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org