@@ -90,8 +90,8 @@ private void stopHttpServer() throws Exception {
9090 }
9191
9292 public static class NotificationServlet extends HttpServlet {
93- public static int counter = 0 ;
94- public static int failureCounter = 0 ;
93+ public static volatile int counter = 0 ;
94+ public static volatile int failureCounter = 0 ;
9595 private static final long serialVersionUID = 1L ;
9696
9797 protected void doGet (HttpServletRequest req , HttpServletResponse res )
@@ -155,7 +155,11 @@ public void testMR() throws Exception {
155155
156156 System .out .println (launchWordCount (this .createJobConf (),
157157 "a b c d e f g h" , 1 , 1 ));
158- Thread .sleep (2000 );
158+ boolean keepTrying = true ;
159+ for (int tries = 0 ; tries < 30 && keepTrying ; tries ++) {
160+ Thread .sleep (50 );
161+ keepTrying = !(NotificationServlet .counter == 2 );
162+ }
159163 assertEquals (2 , NotificationServlet .counter );
160164 assertEquals (0 , NotificationServlet .failureCounter );
161165
@@ -173,14 +177,22 @@ public void testMR() throws Exception {
173177 // run a job with KILLED status
174178 System .out .println (UtilsForTests .runJobKill (this .createJobConf (), inDir ,
175179 outDir ).getID ());
176- Thread .sleep (2000 );
180+ keepTrying = true ;
181+ for (int tries = 0 ; tries < 30 && keepTrying ; tries ++) {
182+ Thread .sleep (50 );
183+ keepTrying = !(NotificationServlet .counter == 4 );
184+ }
177185 assertEquals (4 , NotificationServlet .counter );
178186 assertEquals (0 , NotificationServlet .failureCounter );
179187
180188 // run a job with FAILED status
181189 System .out .println (UtilsForTests .runJobFail (this .createJobConf (), inDir ,
182190 outDir ).getID ());
183- Thread .sleep (2000 );
191+ keepTrying = true ;
192+ for (int tries = 0 ; tries < 30 && keepTrying ; tries ++) {
193+ Thread .sleep (50 );
194+ keepTrying = !(NotificationServlet .counter == 6 );
195+ }
184196 assertEquals (6 , NotificationServlet .counter );
185197 assertEquals (0 , NotificationServlet .failureCounter );
186198 }
0 commit comments