@@ -628,15 +628,17 @@ protected PrivilegedOperationExecutor getPrivilegedOperationExecutor() {
628
628
when (context .getEnvironment ()).thenReturn (env );
629
629
Path workDir = new Path ("/tmp" );
630
630
631
+ LocalizerStartContext lsc = new LocalizerStartContext .Builder ()
632
+ .setNmPrivateContainerTokens (nmPrivateCTokensPath )
633
+ .setNmAddr (address )
634
+ .setUser (appSubmitter )
635
+ .setAppId (appId .toString ())
636
+ .setLocId ("12345" )
637
+ .setDirsHandler (dirService )
638
+ .build ();
639
+
631
640
try {
632
- lce .startLocalizer (new LocalizerStartContext .Builder ()
633
- .setNmPrivateContainerTokens (nmPrivateCTokensPath )
634
- .setNmAddr (address )
635
- .setUser (appSubmitter )
636
- .setAppId (appId .toString ())
637
- .setLocId ("12345" )
638
- .setDirsHandler (dirService )
639
- .build ());
641
+ lce .startLocalizer (lsc );
640
642
Assert .fail ("startLocalizer should have thrown an exception" );
641
643
} catch (IOException e ) {
642
644
assertTrue ("Unexpected exception " + e ,
@@ -648,50 +650,54 @@ protected PrivilegedOperationExecutor getPrivilegedOperationExecutor() {
648
650
LinuxContainerExecutor .ExitCode .INVALID_CONFIG_FILE .getExitCode (),
649
651
};
650
652
651
- for (int i = 0 ; i < exitCodesToThrow .length ; i ++) {
652
- int exitCode = exitCodesToThrow [i ];
653
+ for (int exitCode : exitCodesToThrow ) {
653
654
doThrow (new PrivilegedOperationException ("invalid config" , exitCode , null , null ))
654
655
.when (spyPrivilegedExecutor ).executePrivilegedOperation (
655
656
any (), any (PrivilegedOperation .class ),
656
657
any (), any (), anyBoolean (), anyBoolean ());
657
658
658
659
try {
659
- lce .startLocalizer (new LocalizerStartContext .Builder ()
660
- .setNmPrivateContainerTokens (nmPrivateCTokensPath )
661
- .setNmAddr (address )
662
- .setUser (appSubmitter )
663
- .setAppId (appId .toString ())
664
- .setLocId ("12345" )
665
- .setDirsHandler (dirService )
666
- .build ());
660
+ lce .startLocalizer (lsc );
667
661
Assert .fail ("startLocalizer should have thrown a ConfigurationException" );
668
662
} catch (ConfigurationException e ) {
669
663
assertTrue ("Unexpected exception " + e ,
670
664
e .getMessage ().contains ("exitCode=" + exitCode ));
671
665
}
672
666
}
673
667
668
+ // Assert that we do catch an IOException thrown by the ProcessBuilder.start
669
+ // method as a misconfiguration
670
+ String containerExecutorPath = lce .getContainerExecutorExecutablePath (conf );
674
671
doThrow (new PrivilegedOperationException ("IO error" ,
675
- new IOException ("No such file or directory " )))
672
+ new IOException ("Cannot run program \" " + containerExecutorPath + " \" " )))
676
673
.when (spyPrivilegedExecutor ).executePrivilegedOperation (
677
674
any (), any (PrivilegedOperation .class ),
678
675
any (), any (), anyBoolean (), anyBoolean ());
679
676
680
677
try {
681
- lce .startLocalizer (new LocalizerStartContext .Builder ()
682
- .setNmPrivateContainerTokens (nmPrivateCTokensPath )
683
- .setNmAddr (address )
684
- .setUser (appSubmitter )
685
- .setAppId (appId .toString ())
686
- .setLocId ("12345" )
687
- .setDirsHandler (dirService )
688
- .build ());
689
- Assert .fail ("startLocalizer should have thrown a ConfigurationException" );
678
+ lce .startLocalizer (lsc );
679
+ Assert .fail ("startLocalizer should have thrown an ConfigurationException" );
690
680
} catch (ConfigurationException e ) {
691
681
assertTrue ("Unexpected exception " + e ,
692
682
e .getMessage ().contains ("Container executor not found" ));
693
683
}
694
684
685
+ // Assert that we do not catch every IOException as a misconfiguration
686
+ doThrow (new PrivilegedOperationException ("IO error" ,
687
+ new IOException ("No such file or directory" )))
688
+ .when (spyPrivilegedExecutor ).executePrivilegedOperation (
689
+ any (), any (PrivilegedOperation .class ),
690
+ any (), any (), anyBoolean (), anyBoolean ());
691
+
692
+ try {
693
+ lce .startLocalizer (lsc );
694
+ Assert .fail ("startLocalizer should have thrown an IOException" );
695
+ } catch (ConfigurationException e ) {
696
+ Assert .fail ("startLocalizer should not have thrown a ConfigurationException" );
697
+ } catch (IOException e ) {
698
+ assertTrue ("Unexpected exception " + e ,
699
+ e .getMessage ().contains ("exitCode" ));
700
+ }
695
701
696
702
doThrow (new PrivilegedOperationException ("interrupted" ))
697
703
.when (spyPrivilegedExecutor ).executePrivilegedOperation (
0 commit comments