3838import static org .junit .Assert .assertNotNull ;
3939import static org .junit .Assert .assertNull ;
4040import static org .junit .Assert .assertTrue ;
41- import static org .mockito .Matchers .any ;
42- import static org .mockito .Matchers .isNull ;
4341import static org .mockito .Mockito .RETURNS_DEEP_STUBS ;
44- import static org .mockito .Mockito .times ;
42+ import static org .mockito .Mockito .any ;
4543import static org .mockito .Mockito .atLeast ;
4644import static org .mockito .Mockito .doCallRealMethod ;
45+ import static org .mockito .Mockito .isNull ;
4746import static org .mockito .Mockito .mock ;
4847import static org .mockito .Mockito .spy ;
48+ import static org .mockito .Mockito .times ;
4949import static org .mockito .Mockito .verify ;
5050import static org .mockito .Mockito .when ;
5151
8989import org .apache .tez .dag .api .client .rpc .DAGClientAMProtocolBlockingPB ;
9090import org .apache .tez .dag .api .client .rpc .DAGClientAMProtocolRPC .GetAMStatusRequestProto ;
9191import org .apache .tez .dag .api .client .rpc .DAGClientAMProtocolRPC .GetAMStatusResponseProto ;
92- import org .apache .tez .dag .api .client .rpc .DAGClientAMProtocolRPC .GetDAGStatusRequestProto ;
9392import org .apache .tez .dag .api .client .rpc .DAGClientAMProtocolRPC .GetDAGStatusResponseProto ;
94- import org .apache .tez .dag .api .client .rpc .DAGClientAMProtocolRPC .ShutdownSessionRequestProto ;
9593import org .apache .tez .dag .api .client .rpc .DAGClientAMProtocolRPC .SubmitDAGRequestProto ;
9694import org .apache .tez .dag .api .client .rpc .DAGClientAMProtocolRPC .TezAppMasterStatusProto ;
9795import org .apache .tez .dag .api .records .DAGProtos .DAGStatusProto ;
@@ -188,10 +186,11 @@ TezClientForTest configureAndCreateTezClient(Map<String, LocalResource> lrs, boo
188186 YarnClient yarnClient = mock (YarnClient .class , RETURNS_DEEP_STUBS );
189187 when (yarnClient .createApplication ().getNewApplicationResponse ().getApplicationId ()).thenReturn (appId1 );
190188 when (yarnClient .getApplicationReport (appId1 ).getYarnApplicationState ()).thenReturn (YarnApplicationState .NEW );
191- when (yarnClient .submitApplication (any (ApplicationSubmissionContext . class ))).thenReturn (appId1 );
189+ when (yarnClient .submitApplication (any ())).thenReturn (appId1 );
192190
193191 DAGClientAMProtocolBlockingPB sessionAmProxy = mock (DAGClientAMProtocolBlockingPB .class , RETURNS_DEEP_STUBS );
194- when (sessionAmProxy .getAMStatus (any (RpcController .class ), any (GetAMStatusRequestProto .class )))
192+ when (sessionAmProxy .getAMStatus (any (), any ()))
193+ .thenReturn (GetAMStatusResponseProto .newBuilder ().setStatus (TezAppMasterStatusProto .RUNNING ).build ())
195194 .thenReturn (GetAMStatusResponseProto .newBuilder ().setStatus (TezAppMasterStatusProto .RUNNING ).build ());
196195
197196 client .sessionAmProxy = sessionAmProxy ;
@@ -255,7 +254,7 @@ private void _testTezClientSessionLargeDAGPlan(int maxIPCMsgSize, int payloadSiz
255254 client .stop ();
256255
257256 ArgumentCaptor <SubmitDAGRequestProto > captor = ArgumentCaptor .forClass (SubmitDAGRequestProto .class );
258- verify (client .sessionAmProxy ).submitDAG (( RpcController ) any (), captor .capture ());
257+ verify (client .sessionAmProxy ).submitDAG (any (), captor .capture ());
259258 SubmitDAGRequestProto request = captor .getValue ();
260259
261260 if (shouldSerialize ) {
@@ -308,12 +307,12 @@ public void testGetClient() throws Exception {
308307 verify (client2 .mockYarnClient , times (0 )).submitApplication (captor .capture ());
309308
310309 // Validate dag submission from second TezClient as normal */
311- verify (client2 .sessionAmProxy , times (1 )).submitDAG (( RpcController ) any (), ( SubmitDAGRequestProto ) any ());
310+ verify (client2 .sessionAmProxy , times (1 )).submitDAG (any (), any ());
312311
313312 // Validate stop from new TezClient as normal */
314313 client2 .stop ();
315- verify (client2 .sessionAmProxy , times (1 )).shutdownSession (( RpcController ) any (),
316- ( ShutdownSessionRequestProto ) any ());
314+ verify (client2 .sessionAmProxy , times (1 )).shutdownSession (any (),
315+ any ());
317316 verify (client2 .mockYarnClient , times (1 )).stop ();
318317 /* END reuse of AM from new TezClient */
319318 }
@@ -330,7 +329,7 @@ public TezClientForTest testTezClient(boolean isSession, boolean shouldStop) thr
330329 when (client .mockYarnClient .getApplicationReport (client .mockAppId ).getYarnApplicationState ())
331330 .thenReturn (YarnApplicationState .RUNNING );
332331 client .start ();
333- verify (client .mockYarnClient , times (1 )).init (( Configuration ) any ());
332+ verify (client .mockYarnClient , times (1 )).init (any ());
334333 verify (client .mockYarnClient , times (1 )).start ();
335334 if (isSession ) {
336335 verify (client .mockYarnClient , times (1 )).submitApplication (captor .capture ());
@@ -353,14 +352,18 @@ public TezClientForTest testTezClient(boolean isSession, boolean shouldStop) thr
353352 Vertex vertex = Vertex .create ("Vertex" , ProcessorDescriptor .create ("P" ), 1 ,
354353 Resource .newInstance (1 , 1 ));
355354 DAG dag = DAG .create ("DAG" ).addVertex (vertex ).addTaskLocalFiles (lrDAG );
355+ if (!isSession ) {
356+ when (client .sessionAmProxy .getAMStatus (any (), any ()))
357+ .thenReturn (GetAMStatusResponseProto .newBuilder ().setStatus (TezAppMasterStatusProto .SHUTDOWN ).build ());
358+ }
356359 DAGClient dagClient = client .submitDAG (dag );
357360
358361 assertTrue (dagClient .getExecutionContext ().contains (client .mockAppId .toString ()));
359362 assertEquals (dagClient .getSessionIdentifierString (), client .mockAppId .toString ());
360363
361364 if (isSession ) {
362365 verify (client .mockYarnClient , times (1 )).submitApplication (captor .capture ());
363- verify (client .sessionAmProxy , times (1 )).submitDAG (( RpcController ) any (), ( SubmitDAGRequestProto ) any ());
366+ verify (client .sessionAmProxy , times (1 )).submitDAG (any (), any ());
364367 } else {
365368 verify (client .mockYarnClient , times (1 )).submitApplication (captor .capture ());
366369 ApplicationSubmissionContext context = captor .getValue ();
@@ -399,7 +402,7 @@ public TezClientForTest testTezClient(boolean isSession, boolean shouldStop) thr
399402 assertEquals (dagClient .getSessionIdentifierString (), client .mockAppId .toString ());
400403 // additional resource is sent
401404 ArgumentCaptor <SubmitDAGRequestProto > captor1 = ArgumentCaptor .forClass (SubmitDAGRequestProto .class );
402- verify (client .sessionAmProxy , times (2 )).submitDAG (( RpcController ) any (), captor1 .capture ());
405+ verify (client .sessionAmProxy , times (2 )).submitDAG (any (), captor1 .capture ());
403406 SubmitDAGRequestProto proto = captor1 .getValue ();
404407 Assert .assertEquals (1 , proto .getAdditionalAmResources ().getLocalResourcesCount ());
405408 Assert .assertEquals (lrName2 , proto .getAdditionalAmResources ().getLocalResources (0 ).getName ());
@@ -426,8 +429,8 @@ public TezClientForTest testTezClient(boolean isSession, boolean shouldStop) thr
426429 if (shouldStop ) {
427430 client .stop ();
428431 if (isSession ) {
429- verify (client .sessionAmProxy , times (1 )).shutdownSession (( RpcController ) any (),
430- ( ShutdownSessionRequestProto ) any ());
432+ verify (client .sessionAmProxy , times (1 )).shutdownSession (any (),
433+ any ());
431434 }
432435 verify (client .mockYarnClient , times (1 )).stop ();
433436 }
@@ -443,14 +446,14 @@ public void testPreWarm() throws Exception {
443446 .thenReturn (YarnApplicationState .RUNNING );
444447
445448 when (
446- client .sessionAmProxy .getAMStatus (( RpcController ) any (), ( GetAMStatusRequestProto ) any ()))
449+ client .sessionAmProxy .getAMStatus (any (), any ()))
447450 .thenReturn (GetAMStatusResponseProto .newBuilder ().setStatus (TezAppMasterStatusProto .READY ).build ());
448451
449452 PreWarmVertex vertex = PreWarmVertex .create ("PreWarm" , 1 , Resource .newInstance (1 , 1 ));
450453 client .preWarm (vertex );
451454
452455 ArgumentCaptor <SubmitDAGRequestProto > captor1 = ArgumentCaptor .forClass (SubmitDAGRequestProto .class );
453- verify (client .sessionAmProxy , times (1 )).submitDAG (( RpcController ) any (), captor1 .capture ());
456+ verify (client .sessionAmProxy , times (1 )).submitDAG (any (), captor1 .capture ());
454457 SubmitDAGRequestProto proto = captor1 .getValue ();
455458 assertTrue (proto .getDAGPlan ().getName ().startsWith (TezConstants .TEZ_PREWARM_DAG_NAME_PREFIX ));
456459
@@ -467,7 +470,7 @@ public void testPreWarmCloseStuck() throws Exception {
467470
468471 when (client .mockYarnClient .getApplicationReport (client .mockAppId ).getYarnApplicationState ())
469472 .thenReturn (YarnApplicationState .RUNNING );
470- when (client .sessionAmProxy .getAMStatus (( RpcController ) any (), ( GetAMStatusRequestProto ) any ()))
473+ when (client .sessionAmProxy .getAMStatus (any (), any ()))
471474 .thenReturn (GetAMStatusResponseProto .newBuilder ().setStatus (TezAppMasterStatusProto .READY ).build ());
472475
473476 PreWarmVertex vertex = PreWarmVertex .create ("PreWarm" , 1 , Resource .newInstance (1 , 1 ));
@@ -480,7 +483,7 @@ public void testPreWarmCloseStuck() throws Exception {
480483 private void setClientToReportStoppedDags (TezClientForTest client ) throws Exception {
481484 when (client .mockYarnClient .getApplicationReport (client .mockAppId ).getYarnApplicationState ())
482485 .thenReturn (YarnApplicationState .FINISHED );
483- when (client .sessionAmProxy .getDAGStatus (isNull (RpcController . class ), any (GetDAGStatusRequestProto . class )))
486+ when (client .sessionAmProxy .getDAGStatus (isNull (), any ()))
484487 .thenReturn (GetDAGStatusResponseProto .newBuilder ().setDagStatus (DAGStatusProto .newBuilder ()
485488 .addDiagnostics ("Diagnostics_0" ).setState (DAGStatusStateProto .DAG_SUCCEEDED )
486489 .setDAGProgress (ProgressProto .newBuilder ()
@@ -502,8 +505,8 @@ public void testPreWarmWithTimeout() throws Exception {
502505 spyClient .mockAppId ).getYarnApplicationState ())
503506 .thenReturn (YarnApplicationState .RUNNING );
504507 when (
505- spyClient .sessionAmProxy .getAMStatus (( RpcController ) any (),
506- ( GetAMStatusRequestProto ) any ()))
508+ spyClient .sessionAmProxy .getAMStatus (any (),
509+ any ()))
507510 .thenReturn (
508511 GetAMStatusResponseProto .newBuilder ().setStatus (
509512 TezAppMasterStatusProto .INITIALIZING ).build ());
@@ -518,15 +521,15 @@ public void testPreWarmWithTimeout() throws Exception {
518521 endTime = Time .monotonicNow ();
519522 assertTrue ("Time taken is not as expected" ,
520523 (endTime - startTime ) > timeout );
521- verify (spyClient , times (0 )).submitDAG (any (DAG . class ));
524+ verify (spyClient , times (0 )).submitDAG (any ());
522525 Assert .assertTrue ("Unexpected Exception message" ,
523526 te .getMessage ().contains ("Tez AM not ready" ));
524527
525528 }
526529
527530 when (
528- spyClient .sessionAmProxy .getAMStatus (( RpcController ) any (),
529- ( GetAMStatusRequestProto ) any ()))
531+ spyClient .sessionAmProxy .getAMStatus (any (),
532+ any ()))
530533 .thenReturn (
531534 GetAMStatusResponseProto .newBuilder ().setStatus (
532535 TezAppMasterStatusProto .READY ).build ());
@@ -536,7 +539,7 @@ public void testPreWarmWithTimeout() throws Exception {
536539 endTime = Time .monotonicNow ();
537540 assertTrue ("Time taken is not as expected" ,
538541 (endTime - startTime ) <= timeout );
539- verify (spyClient , times (1 )).submitDAG (any (DAG . class ));
542+ verify (spyClient , times (1 )).submitDAG (any ());
540543 } catch (TezException te ) {
541544 fail ("PreWarm should have succeeded!" );
542545 }
@@ -571,7 +574,7 @@ public void run() {
571574 endTime = Time .monotonicNow ();
572575 assertTrue ("Time taken is not as expected" ,
573576 (endTime - startTime ) <= timeout );
574- verify (spyClient , times (2 )).submitDAG (any (DAG . class ));
577+ verify (spyClient , times (2 )).submitDAG (any ());
575578 setClientToReportStoppedDags (client );
576579 spyClient .stop ();
577580 client .stop ();
@@ -926,8 +929,7 @@ public void testAMClientHeartbeat() throws Exception {
926929 Thread .sleep (1000 );
927930 }
928931 client .stop ();
929- verify (client .sessionAmProxy , atLeast (3 )).getAMStatus (any (RpcController .class ),
930- any (GetAMStatusRequestProto .class ));
932+ verify (client .sessionAmProxy , atLeast (3 )).getAMStatus (any (), any ());
931933
932934 conf .setInt (TezConfiguration .TEZ_AM_CLIENT_HEARTBEAT_TIMEOUT_SECS , -1 );
933935 final TezClientForTest client2 = configureAndCreateTezClient (conf );
@@ -940,10 +942,7 @@ public void testAMClientHeartbeat() throws Exception {
940942 Thread .sleep (1000 );
941943 }
942944 client2 .stop ();
943- verify (client2 .sessionAmProxy , times (0 )).getAMStatus (any (RpcController .class ),
944- any (GetAMStatusRequestProto .class ));
945-
946-
945+ verify (client2 .sessionAmProxy , times (0 )).getAMStatus (any (), any ());
947946 }
948947
949948 @ Test (timeout = 20000 )
@@ -987,8 +986,7 @@ public void testAMHeartbeatFailOnGetAMStatus() throws Exception {
987986 final TezClientForTest client = configureAndCreateTezClient (conf );
988987 client .start ();
989988
990- when (client .sessionAmProxy .getAMStatus (any (RpcController .class ),
991- any (GetAMStatusRequestProto .class ))).thenThrow (new ServiceException ("error" ));
989+ when (client .sessionAmProxy .getAMStatus (any (), any ())).thenThrow (new ServiceException ("error" ));
992990 client .callRealGetSessionAMProxy = true ;
993991 when (client .mockYarnClient .getApplicationReport (client .mockAppId ).getYarnApplicationState ())
994992 .thenReturn (YarnApplicationState .FAILED );
0 commit comments