zhuqi-lucas commented on code in PR #927:
URL: https://github.com/apache/yunikorn-core/pull/927#discussion_r1714567175


##########
pkg/scheduler/objects/application.go:
##########
@@ -2157,6 +2158,23 @@ func (sa *Application) GetMaxResource() 
*resources.Resource {
        return sa.getResourceFromTags(siCommon.AppTagNamespaceResourceQuota)
 }
 
+// GetMaxApps returns the max apps that is set in the application tags
+func (sa *Application) GetMaxApps() uint64 {
+       return sa.GetUint64Tag(siCommon.AppTagNamespaceResourceMaxApps)
+}
+
+func (sa *Application) GetUint64Tag(tag string) uint64 {

Review Comment:
   Addressed in latest PR, thanks!



##########
pkg/scheduler/objects/application_test.go:
##########
@@ -108,46 +108,121 @@ func TestNewApplication(t *testing.T) {
        assert.Assert(t, app.IsNew(), "new application must be in new state")
        assert.Equal(t, app.execTimeout, defaultPlaceholderTimeout, "no timeout 
passed in should be modified default")
        assert.Assert(t, resources.Equals(app.placeholderAsk, res), 
"placeholder ask not set as expected")
+}
 
+func TestNewApplicationWithAnnotaionUpdate(t *testing.T) {

Review Comment:
   Addressed in latest PR, thanks!



##########
pkg/scheduler/objects/application_test.go:
##########
@@ -108,46 +108,121 @@ func TestNewApplication(t *testing.T) {
        assert.Assert(t, app.IsNew(), "new application must be in new state")
        assert.Equal(t, app.execTimeout, defaultPlaceholderTimeout, "no timeout 
passed in should be modified default")
        assert.Assert(t, resources.Equals(app.placeholderAsk, res), 
"placeholder ask not set as expected")
+}
 
+func TestNewApplicationWithAnnotaionUpdate(t *testing.T) {
+       user := security.UserGroup{
+               User:   "testuser",
+               Groups: []string{},
+       }
        // valid tags
-       siApp = &si.AddApplicationRequest{}
+       siApp := &si.AddApplicationRequest{}
        siApp.Tags = map[string]string{
                siCommon.AppTagNamespaceResourceQuota:      
"{\"resources\":{\"validMaxRes\":{\"value\":11}}}",
                siCommon.AppTagNamespaceResourceGuaranteed: 
"{\"resources\":{\"validGuaranteed\":{\"value\":22}}}",
+               siCommon.AppTagNamespaceResourceMaxApps:    "33",
        }
-       app = NewApplication(siApp, user, nil, "")
+
+       app := NewApplication(siApp, user, nil, "")
+
        guaranteed := app.GetGuaranteedResource()
        maxResource := app.GetMaxResource()
+       maxApps := app.GetMaxApps()
        assert.Assert(t, guaranteed != nil, "guaranteed resource has not been 
set")
        assert.Equal(t, 1, len(guaranteed.Resources), "more than one resource 
has been set")
        assert.Equal(t, resources.Quantity(22), 
guaranteed.Resources["validGuaranteed"])
        assert.Assert(t, maxResource != nil, "maximum resource has not been 
set")
        assert.Equal(t, 1, len(maxResource.Resources), "more than one resource 
has been set")
        assert.Equal(t, resources.Quantity(11), 
maxResource.Resources["validMaxRes"], "maximum resource is incorrect")
+       assert.Assert(t, maxApps != 0, "maximum apps has not been set or 
incorrect")
+       assert.Equal(t, uint64(33), maxApps, "maximum apps is incorrect")
+
+       // valid tags without max apps
+       siApp = &si.AddApplicationRequest{}
+       siApp.Tags = map[string]string{
+               siCommon.AppTagNamespaceResourceQuota:      
"{\"resources\":{\"validMaxRes\":{\"value\":11}}}",
+               siCommon.AppTagNamespaceResourceGuaranteed: 
"{\"resources\":{\"validGuaranteed\":{\"value\":22}}}",
+       }
+       app = NewApplication(siApp, user, nil, "")
+       guaranteed = app.GetGuaranteedResource()
+       maxResource = app.GetMaxResource()
+       maxApps = app.GetMaxApps()
+       assert.Assert(t, guaranteed != nil, "guaranteed resource has not been 
set")
+       assert.Equal(t, 1, len(guaranteed.Resources), "more than one resource 
has been set")
+       assert.Equal(t, resources.Quantity(22), 
guaranteed.Resources["validGuaranteed"])
+       assert.Assert(t, maxResource != nil, "maximum resource has not been 
set")
+       assert.Equal(t, 1, len(maxResource.Resources), "more than one resource 
has been set")
+       assert.Equal(t, resources.Quantity(11), 
maxResource.Resources["validMaxRes"], "maximum resource is incorrect")
+       assert.Assert(t, maxApps == 0, "maximum apps should have not been set")
 
        // invalid tags
        siApp = &si.AddApplicationRequest{}
        siApp.Tags = map[string]string{
                siCommon.AppTagNamespaceResourceQuota:      "{xxxxxx}",
                siCommon.AppTagNamespaceResourceGuaranteed: "{yyyyy}",
+               siCommon.AppTagNamespaceResourceMaxApps:    "zzzzz",
        }
        app = NewApplication(siApp, user, nil, "")
        guaranteed = app.GetGuaranteedResource()
        maxResource = app.GetMaxResource()
+       maxApps = app.GetMaxApps()
        assert.Assert(t, guaranteed == nil, "guaranteed resource should have 
not been set")
        assert.Assert(t, maxResource == nil, "maximum resource should have not 
been set")
+       assert.Assert(t, maxApps == 0, "maximum apps should have not been set 
or incorrect")
 
        // negative values
        siApp = &si.AddApplicationRequest{}
        siApp.Tags = map[string]string{
                siCommon.AppTagNamespaceResourceQuota:      
"{\"resources\":{\"negativeMax\":{\"value\":-11}}}",
                siCommon.AppTagNamespaceResourceGuaranteed: 
"{\"resources\":{\"negativeGuaranteed\":{\"value\":-22}}}",
+               siCommon.AppTagNamespaceResourceMaxApps:    "-33",
        }
        app = NewApplication(siApp, user, nil, "")
        guaranteed = app.GetGuaranteedResource()
        maxResource = app.GetMaxResource()
+       maxApps = app.GetMaxApps()
        assert.Assert(t, guaranteed == nil, "guaranteed resource should have 
not been set")
        assert.Assert(t, maxResource == nil, "maximum resource should have not 
been set")
+       assert.Assert(t, maxApps == 0, "maximum apps should have not been set 
or incorrect")
+
+       // test seperate max app cases to increase testing coverage

Review Comment:
   Addressed in latest PR, thanks!



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