richscott commented on code in PR #897:
URL: https://github.com/apache/yunikorn-core/pull/897#discussion_r1697412476


##########
pkg/common/resources/tracked_resources.go:
##########
@@ -103,3 +103,46 @@ func (tr *TrackedResource) 
AggregateTrackedResource(instType string,
        }
        tr.TrackedResourceMap[instType] = aggregatedResourceTime
 }
+
+func EqualsTracked(left, right *TrackedResource) bool {
+       if left == right {
+               return true
+       }
+
+       if left == nil || right == nil {
+               return false
+       }
+
+       equals := true
+       for k, v := range left.TrackedResourceMap {
+               inner, ok := right.TrackedResourceMap[k]
+               if !ok {
+                       return false
+               }
+
+               equals = equals && equalsMapContents(v, inner)
+       }
+
+       return equals

Review Comment:
   Nice improvement! Fixed in commit 9b3c237 



##########
pkg/common/resources/tracked_resources_test.go:
##########
@@ -210,3 +210,55 @@ func TestTrackedResourceAggregateTrackedResource(t 
*testing.T) {
                })
        }
 }
+
+func TestEqualsTracked(t *testing.T) {
+       type inputs struct {
+               base    map[string]map[string]int64
+               compare map[string]map[string]int64
+       }
+       var tests = []struct {
+               caseName string
+               input    inputs
+               expected bool
+       }{
+               {"simple cases (nil checks)", inputs{nil, nil}, true},
+               {"simple cases (nil checks)", 
inputs{map[string]map[string]int64{}, nil}, false},
+               {"same first and second level keys and different resource 
value",
+                       inputs{map[string]map[string]int64{"first": {"val": 
10}}, map[string]map[string]int64{"first": {"val": 0}}},
+                       false,
+               },
+               {"different first-level key, same second-level key, same 
resource value",
+                       inputs{map[string]map[string]int64{"first": {"val": 
10}}, map[string]map[string]int64{"second": {"val": 10}}},
+                       false},
+               {"same first-level key, different second-level key, same 
resource value",
+                       inputs{map[string]map[string]int64{"first": {"val": 
10}}, map[string]map[string]int64{"first": {"value": 10}}},
+                       false},
+               {"same first-level key, second has larger sub-level map",
+                       inputs{map[string]map[string]int64{"first": {"val": 
10}}, map[string]map[string]int64{"first": {"val": 10, "sum": 7}}},
+                       false},
+               {"same first-level key, first has larger sub-level map",
+                       inputs{map[string]map[string]int64{"first": {"val": 10, 
"sum": 7}}, map[string]map[string]int64{"first": {"val": 10}}},
+                       false},
+               {"same keys and values",
+                       inputs{map[string]map[string]int64{"x": {"val": 10, 
"sum": 7}}, map[string]map[string]int64{"x": {"val": 10, "sum": 7}}},
+                       true},
+       }
+       for _, tt := range tests {
+               t.Run(tt.caseName, func(t *testing.T) {
+                       var base, compare *TrackedResource
+                       if tt.input.base != nil {
+                               base = NewTrackedResourceFromMap(tt.input.base)
+                       }
+                       if tt.input.compare != nil {
+                               compare = 
NewTrackedResourceFromMap(tt.input.compare)
+                       }
+
+                       if result := EqualsTracked(base, compare); result != 
tt.expected {
+                               t.Errorf("Equal result should be %v instead of 
%v, left %v, right %v", tt.expected, result, base, compare)

Review Comment:
   Fixed in commit 9b3c237



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