2525import org .apache .hadoop .yarn .server .nodemanager .Context ;
2626import org .apache .hadoop .yarn .util .ProcfsBasedProcessTree ;
2727import org .apache .hadoop .yarn .util .ResourceCalculatorProcessTree ;
28- import org .junit .*;
28+ import org .junit .jupiter .api .AfterEach ;
29+ import org .junit .jupiter .api .BeforeEach ;
30+ import org .junit .jupiter .api .Disabled ;
31+ import org .junit .jupiter .api .Test ;
2932
3033import java .io .File ;
3134import java .io .IOException ;
3235import java .lang .reflect .Field ;
3336import java .util .Random ;
3437
3538import static org .mockito .Mockito .mock ;
39+ import static org .junit .jupiter .api .Assertions .assertTrue ;
40+ import static org .junit .jupiter .api .Assumptions .assumeTrue ;
3641
3742/**
3843 * Functional test for CGroupsResourceCalculator to compare two resource
@@ -46,9 +51,9 @@ public class TestCompareResourceCalculators {
4651 private String cgroupMemory = null ;
4752 public static final long SHMEM_KB = 100 * 1024 ;
4853
49- @ Before
54+ @ BeforeEach
5055 public void setup () throws IOException , YarnException {
51- Assume . assumeTrue (SystemUtils .IS_OS_LINUX );
56+ assumeTrue (SystemUtils .IS_OS_LINUX );
5257
5358 YarnConfiguration conf = new YarnConfiguration ();
5459 conf .set (YarnConfiguration .NM_LINUX_CONTAINER_CGROUPS_HIERARCHY ,
@@ -64,13 +69,11 @@ public void setup() throws IOException, YarnException {
6469 } catch (ResourceHandlerException e ) {
6570 throw new YarnException ("Cannot access cgroups" , e );
6671 }
67- Assume .assumeNotNull (module );
68- Assume .assumeNotNull (
69- ResourceHandlerModule .getCGroupsHandler ()
70- .getControllerPath (CGroupsHandler .CGroupController .CPU ));
71- Assume .assumeNotNull (
72- ResourceHandlerModule .getCGroupsHandler ()
73- .getControllerPath (CGroupsHandler .CGroupController .MEMORY ));
72+ assumeTrue (module != null );
73+ assumeTrue (ResourceHandlerModule .getCGroupsHandler ()
74+ .getControllerPath (CGroupsHandler .CGroupController .CPU ) != null );
75+ assumeTrue (ResourceHandlerModule .getCGroupsHandler ()
76+ .getControllerPath (CGroupsHandler .CGroupController .MEMORY ) != null );
7477
7578 Random random = new Random (System .currentTimeMillis ());
7679 cgroup = Long .toString (random .nextLong ());
@@ -80,14 +83,14 @@ public void setup() throws IOException, YarnException {
8083 .getPathForCGroup (CGroupsHandler .CGroupController .MEMORY , cgroup );
8184 }
8285
83- @ After
86+ @ AfterEach
8487 public void tearDown () throws YarnException {
8588 stopTestProcess ();
8689 }
8790
8891
8992 // Ignored in automated tests due to flakiness by design
90- @ Ignore
93+ @ Disabled
9194 @ Test
9295 public void testCompareResults ()
9396 throws YarnException , InterruptedException , IOException {
@@ -118,20 +121,20 @@ private void ensureCleanedUp(
118121 long pmem1 = metric1 .getRssMemorySize (0 );
119122 long pmem2 = metric2 .getRssMemorySize (0 );
120123 System .out .println (pmem1 + " " + pmem2 );
121- Assert . assertTrue ("pmem should be invalid " + pmem1 + " " + pmem2 ,
122- pmem1 == ResourceCalculatorProcessTree .UNAVAILABLE &&
123- pmem2 == ResourceCalculatorProcessTree . UNAVAILABLE );
124+ assertTrue (pmem1 == ResourceCalculatorProcessTree . UNAVAILABLE &&
125+ pmem2 == ResourceCalculatorProcessTree .UNAVAILABLE ,
126+ "pmem should be invalid " + pmem1 + " " + pmem2 );
124127 long vmem1 = metric1 .getRssMemorySize (0 );
125128 long vmem2 = metric2 .getRssMemorySize (0 );
126129 System .out .println (vmem1 + " " + vmem2 );
127- Assert . assertTrue ("vmem Error outside range " + vmem1 + " " + vmem2 ,
128- vmem1 == ResourceCalculatorProcessTree .UNAVAILABLE &&
129- vmem2 == ResourceCalculatorProcessTree . UNAVAILABLE );
130+ assertTrue (vmem1 == ResourceCalculatorProcessTree . UNAVAILABLE &&
131+ vmem2 == ResourceCalculatorProcessTree .UNAVAILABLE ,
132+ "vmem Error outside range " + vmem1 + " " + vmem2 );
130133 float cpu1 = metric1 .getCpuUsagePercent ();
131134 float cpu2 = metric2 .getCpuUsagePercent ();
132135 // TODO ProcfsBasedProcessTree may report negative on process exit
133- Assert . assertTrue ("CPU% Error outside range " + cpu1 + " " + cpu2 ,
134- cpu1 == 0 && cpu2 == 0 );
136+ assertTrue (cpu1 == 0 && cpu2 == 0 ,
137+ "CPU% Error outside range " + cpu1 + " " + cpu2 );
135138 }
136139
137140 private void compareMetrics (
@@ -145,22 +148,22 @@ private void compareMetrics(
145148 // can report a small amount after process stop
146149 // This is not an issue since the cgroup is deleted
147150 System .out .println (pmem1 + " " + (pmem2 - SHMEM_KB * 1024 ));
148- Assert . assertTrue ("pmem Error outside range " + pmem1 + " " + pmem2 ,
149- Math . abs ( pmem1 - ( pmem2 - SHMEM_KB * 1024 )) < 5000000 );
151+ assertTrue (Math . abs ( pmem1 - ( pmem2 - SHMEM_KB * 1024 )) < 5000000 ,
152+ "pmem Error outside range " + pmem1 + " " + pmem2 );
150153 long vmem1 = metric1 .getRssMemorySize (0 );
151154 long vmem2 = metric2 .getRssMemorySize (0 );
152155 System .out .println (vmem1 + " " + (vmem2 - SHMEM_KB * 1024 ));
153156 // TODO The calculation is different and cgroup
154157 // can report a small amount after process stop
155158 // This is not an issue since the cgroup is deleted
156- Assert . assertTrue ("vmem Error outside range " + vmem1 + " " + vmem2 ,
157- Math . abs ( vmem1 - ( vmem2 - SHMEM_KB * 1024 )) < 5000000 );
159+ assertTrue (Math . abs ( vmem1 - ( vmem2 - SHMEM_KB * 1024 )) < 5000000 ,
160+ "vmem Error outside range " + vmem1 + " " + vmem2 );
158161 float cpu1 = metric1 .getCpuUsagePercent ();
159162 float cpu2 = metric2 .getCpuUsagePercent ();
160163 if (cpu1 > 0 ) {
161164 // TODO ProcfsBasedProcessTree may report negative on process exit
162- Assert . assertTrue ("CPU% Error outside range " + cpu1 + " " + cpu2 ,
163- Math . abs ( cpu2 - cpu1 ) < 10 );
165+ assertTrue (Math . abs ( cpu2 - cpu1 ) < 10 ,
166+ "CPU% Error outside range " + cpu1 + " " + cpu2 );
164167 }
165168 }
166169
0 commit comments