[ 
https://issues.apache.org/jira/browse/YARN-11426?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17684321#comment-17684321
 ] 

ASF GitHub Bot commented on YARN-11426:
---------------------------------------

slfan1989 commented on code in PR #5335:
URL: https://github.com/apache/hadoop/pull/5335#discussion_r1095999019


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/records/TestResource.java:
##########
@@ -42,4 +42,70 @@ void testCastToIntSafely() {
         "Cast to Integer.MAX_VALUE if the long is greater than "
             + "Integer.MAX_VALUE");
   }
+
+  @Test
+  public void testResourceFormatted() {
+    // We set 10MB
+    String expectedResult1 = "<memory:10 MB, vCores:1>";
+    MockResource capability1 = new MockResource();
+    capability1.setMemory(10);
+    capability1.setVirtualCores(1);
+    assertEquals(capability1.toFormattedString(), expectedResult1);
+
+    // We set 1024 MB = 1GB
+    String expectedResult2 = "<memory:1 GB, vCores:1>";
+    MockResource capability2 = new MockResource();
+    capability2.setMemory(1024);
+    capability2.setVirtualCores(1);
+    assertEquals(capability2.toFormattedString(), expectedResult2);
+
+    // We set 1024 * 1024 MB = 1024 GB = 1TB
+    String expectedResult3 = "<memory:1 TB, vCores:1>";
+    MockResource capability3 = new MockResource();
+    capability3.setMemory(1024 * 1024);
+    capability3.setVirtualCores(1);
+    assertEquals(capability3.toFormattedString(), expectedResult3);
+
+    // We set 1024 * 1024 * 1024 MB = 1024 * 1024 GB = 1 * 1024 TB = 1 PB
+    String expectedResult4 = "<memory:1 PB, vCores:1>";
+    MockResource capability4 = new MockResource();
+    capability4.setMemory(1024 * 1024 * 1024);
+    capability4.setVirtualCores(1);
+    assertEquals(capability4.toFormattedString(), expectedResult4);
+  }
+
+  class MockResource extends Resource {

Review Comment:
   Thanks for reviewing the code. In this unit test, we want to test whether 
the return result of `toFormattedString()` is as expected. 
   
   
![image](https://user-images.githubusercontent.com/55643692/216651973-eae6bbf2-5170-4339-9ce6-248d929cfaf5.png)
   
   The implementation class and definition of Resource are not in the same 
package. If we try to call it, classNotFound will be reported.
   
   Use Class `LightWeightResource`,  The initialization of this class requires 
org.apache.hadoop.yarn.LocalConfigurationProvider, which is under the 
`hadoop-yarn-common` package and cannot be referenced.
   
   ```
    Resource resource = Resource.newInstance(10,1);
    String expectedResult1 = "<memory:10 MB, vCores:1>";
    assertEquals(resource.toFormattedString(), expectedResult1);
   
   Error Msg:
   Caused by: java.lang.ClassNotFoundException: 
org.apache.hadoop.yarn.LocalConfigurationProvider
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
   ...
   ```
   
   Use Class `ResourcePBImpl`,   which is under the `hadoop-yarn-common` 
package and cannot be referenced.
   
   ```
   Resource resource = spy(Resource.class);
   String expectedResult1 = "<memory:10 MB, vCores:1>";
   when(resource.getResources()).thenReturn(new ResourceInformation[0]);
   when(resource.getMemorySize()).thenReturn(10L);
   when(resource.getVirtualCores()).thenReturn(1);
   assertEquals(resource.toFormattedString(), expectedResult1);
   
   Error Msg:
   org.apache.commons.lang3.NotImplementedException: This method is implemented 
by ResourcePBImpl
   ...
   ```
   
   I modified the code, please help to review again.
   
   





> Improve YARN NodeLabel Memory Display
> -------------------------------------
>
>                 Key: YARN-11426
>                 URL: https://issues.apache.org/jira/browse/YARN-11426
>             Project: Hadoop YARN
>          Issue Type: Improvement
>          Components: resourcemanager
>    Affects Versions: 3.4.0
>            Reporter: Shilun Fan
>            Assignee: Shilun Fan
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: before improvement.png, image-2023-02-01-17-55-59-037.png
>
>
> NodeLabel displays the memory information of the cluster, directly displays 
> the numbers, does not display the unit information, and is not easy to 
> understand.
> - before improvement
>   !before improvement.png!
>  * after improvement
> !image-2023-02-01-17-55-59-037.png!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to