1818
1919package org .apache .hadoop .yarn .server .resourcemanager .scheduler .policy ;
2020
21- import java .util .*;
21+ import static org .junit .Assert .assertEquals ;
22+ import static org .junit .Assert .assertTrue ;
2223
23- import org .junit .Assert ;
24- import org .junit .Test ;
24+ import java .util .Arrays ;
25+ import java .util .Iterator ;
26+ import java .util .List ;
2527
2628import org .apache .hadoop .yarn .api .records .Priority ;
29+ import org .junit .Assert ;
30+ import org .junit .Test ;
2731
28- import static org .assertj .core .api .Assertions .assertThat ;
29-
30- public class TestFifoOrderingPolicy {
32+ public
33+ class TestFifoOrderingPolicy {
3134
3235 @ Test
3336 public void testFifoOrderingPolicy () {
@@ -36,13 +39,17 @@ public void testFifoOrderingPolicy() {
3639 MockSchedulableEntity r1 = new MockSchedulableEntity ();
3740 MockSchedulableEntity r2 = new MockSchedulableEntity ();
3841
39- assertThat (policy .getComparator ().compare (r1 , r2 )).isEqualTo (0 );
42+ assertEquals ("The comparator should return 0 because the entities are created with " +
43+ "the same values." , 0 ,
44+ policy .getComparator ().compare (r1 , r2 ));
4045
4146 r1 .setSerial (1 );
42- assertThat (policy .getComparator ().compare (r1 , r2 )).isEqualTo (1 );
47+ assertEquals ("The lhs entity has a larger serial, the comparator return " +
48+ "value should be 1." , 1 , policy .getComparator ().compare (r1 , r2 ));
4349
4450 r2 .setSerial (2 );
45- assertThat (policy .getComparator ().compare (r1 , r2 )).isEqualTo (-1 );
51+ Assert .assertEquals ("The rhs entity has a larger serial, the comparator return " +
52+ "value should be -1." , -1 , policy .getComparator ().compare (r1 , r2 ));
4653 }
4754
4855 @ Test
@@ -63,46 +70,80 @@ public void testIterators() {
6370 schedOrder .addSchedulableEntity (msp3 );
6471
6572 //Assignment, oldest to youngest
66- checkSerials (schedOrder .getAssignmentIterator (IteratorSelector .EMPTY_ITERATOR_SELECTOR ), new long []{1 , 2 , 3 });
73+ checkSerials (Arrays .asList (1L , 2L , 3L ), schedOrder .getAssignmentIterator (
74+ IteratorSelector .EMPTY_ITERATOR_SELECTOR ));
6775
6876 //Preemption, youngest to oldest
69- checkSerials (schedOrder . getPreemptionIterator (), new long []{ 3 , 2 , 1 } );
77+ checkSerials (Arrays . asList ( 3L , 2L , 1L ), schedOrder . getPreemptionIterator () );
7078 }
7179
72- public void checkSerials (Iterator <MockSchedulableEntity > si ,
73- long [] serials ) {
74- for (int i = 0 ;i < serials .length ;i ++) {
75- Assert .assertEquals (si .next ().getSerial (),
76- serials [i ]);
80+ public void checkSerials (List <Long > expectedSerials , Iterator <MockSchedulableEntity >
81+ actualSerialIterator ) {
82+ for (long expectedSerial : expectedSerials ) {
83+ assertEquals (expectedSerial , actualSerialIterator .next ().getSerial ());
7784 }
7885 }
7986
8087 @ Test
81- public void testFifoOrderingPolicyAlongWithPriorty () {
88+ public void testFifoOrderingPolicyAlongWithPriority () {
8289 FifoOrderingPolicy <MockSchedulableEntity > policy =
8390 new FifoOrderingPolicy <MockSchedulableEntity >();
8491 MockSchedulableEntity r1 = new MockSchedulableEntity ();
8592 MockSchedulableEntity r2 = new MockSchedulableEntity ();
8693
87- Priority p1 = Priority . newInstance ( 1 );
88- Priority p2 = Priority . newInstance ( 0 );
94+ assertEquals ( "Both r1 and r2 priority is null, the comparator should return 0." , 0 ,
95+ policy . getComparator (). compare ( r1 , r2 ) );
8996
90- // Both r1 and r1 priority is null
91- Assert .assertEquals (0 , policy .getComparator ().compare (r1 , r2 ));
97+ Priority p2 = Priority .newInstance (0 );
9298
9399 // r1 is null and r2 is not null
94100 r2 .setApplicationPriority (p2 );
95- Assert .assertEquals (-1 , policy .getComparator ().compare (r1 , r2 ));
101+ Assert .assertTrue ("The priority of r1 is null, the priority of r2 is not null, " +
102+ "the comparator should return a negative value." ,
103+ policy .getComparator ().compare (r1 , r2 ) < 0 );
104+
105+ Priority p1 = Priority .newInstance (1 );
96106
97107 // r1 is not null and r2 is null
98- r2 .setApplicationPriority (null );
99108 r1 .setApplicationPriority (p1 );
100- Assert .assertEquals (1 , policy .getComparator ().compare (r1 , r2 ));
109+ r2 .setApplicationPriority (null );
110+ assertTrue ("The priority of r1 is not null, the priority of r2 is null," +
111+ "the comparator should return a positive value." ,
112+ policy .getComparator ().compare (r1 , r2 ) > 0 );
101113
102114 // r1 is not null and r2 is not null
103115 r1 .setApplicationPriority (p1 );
104116 r2 .setApplicationPriority (p2 );
105- Assert .assertEquals (-1 , policy .getComparator ().compare (r1 , r2 ));
117+ Assert .assertTrue ("Both priorities are not null, the r1 has higher priority, " +
118+ "the result should be a negative value." ,
119+ policy .getComparator ().compare (r1 , r2 ) < 0 );
106120 }
107121
122+ @ Test
123+ public void testOrderingUsingAppSubmitTime () {
124+ FifoOrderingPolicy <MockSchedulableEntity > policy =
125+ new FifoOrderingPolicy <MockSchedulableEntity >();
126+ MockSchedulableEntity r1 = new MockSchedulableEntity ();
127+ MockSchedulableEntity r2 = new MockSchedulableEntity ();
128+
129+ // R1, R2 has been started at same time
130+ assertEquals (r1 .getStartTime (), r2 .getStartTime ());
131+
132+ // No changes, equal
133+ assertEquals ("The submit times are the same, the comparator should return 0." , 0 ,
134+ policy .getComparator ().compare (r1 , r2 ));
135+
136+ // R2 has been started after R1
137+ r1 .setStartTime (5 );
138+ r2 .setStartTime (10 );
139+ Assert .assertTrue ("r2 was started after r1, " +
140+ "the comparator should return a negative value." ,
141+ policy .getComparator ().compare (r1 , r2 ) < 0 );
142+
143+ // R1 has been started after R2
144+ r1 .setStartTime (10 );
145+ r2 .setStartTime (5 );
146+ Assert .assertTrue ("r2 was started before r1, the comparator should return a positive value." ,
147+ policy .getComparator ().compare (r1 , r2 ) > 0 );
148+ }
108149}
0 commit comments