2525import java .util .Arrays ;
2626import java .util .List ;
2727
28+ import org .apache .hadoop .test .LambdaTestUtils ;
2829import org .apache .hadoop .yarn .MockApps ;
2930import org .apache .hadoop .yarn .api .protocolrecords .GetNewApplicationRequest ;
3031import org .apache .hadoop .yarn .api .protocolrecords .GetNewApplicationResponse ;
3132import org .apache .hadoop .yarn .api .protocolrecords .SubmitApplicationRequest ;
33+ import org .apache .hadoop .yarn .api .protocolrecords .SubmitApplicationResponse ;
3234import org .apache .hadoop .yarn .api .records .ApplicationId ;
3335import org .apache .hadoop .yarn .api .records .ApplicationSubmissionContext ;
3436import org .apache .hadoop .yarn .api .records .ContainerLaunchContext ;
3840import org .apache .hadoop .yarn .server .federation .policies .FederationPolicyUtils ;
3941import org .apache .hadoop .yarn .server .federation .policies .manager .UniformBroadcastPolicyManager ;
4042import org .apache .hadoop .yarn .server .federation .store .impl .MemoryFederationStateStore ;
43+ import org .apache .hadoop .yarn .server .federation .store .records .ApplicationHomeSubCluster ;
4144import org .apache .hadoop .yarn .server .federation .store .records .GetApplicationHomeSubClusterRequest ;
45+ import org .apache .hadoop .yarn .server .federation .store .records .GetApplicationHomeSubClusterResponse ;
4246import org .apache .hadoop .yarn .server .federation .store .records .SubClusterId ;
4347import org .apache .hadoop .yarn .server .federation .utils .FederationStateStoreFacade ;
4448import org .apache .hadoop .yarn .server .federation .utils .FederationStateStoreTestUtil ;
@@ -160,19 +164,13 @@ protected YarnConfiguration createConfiguration() {
160164 */
161165 @ Test
162166 public void testGetNewApplicationOneBadSC ()
163- throws YarnException , IOException , InterruptedException {
164-
165- System .out .println ("Test getNewApplication with one bad SubCluster" );
167+ throws Exception {
168+ LOG .info ("Test getNewApplication with one bad SubCluster" );
166169 setupCluster (Arrays .asList (bad2 ));
167170
168- try {
169- interceptor .getNewApplication (GetNewApplicationRequest .newInstance ());
170- Assert .fail ();
171- } catch (Exception e ) {
172- System .out .println (e .toString ());
173- Assert .assertTrue (e .getMessage ()
174- .equals (FederationPolicyUtils .NO_ACTIVE_SUBCLUSTER_AVAILABLE ));
175- }
171+ GetNewApplicationRequest request = GetNewApplicationRequest .newInstance ();
172+ LambdaTestUtils .intercept (YarnException .class , FederationPolicyUtils .NO_ACTIVE_SUBCLUSTER_AVAILABLE ,
173+ () -> interceptor .getNewApplication (request ));
176174 }
177175
178176 /**
@@ -181,18 +179,13 @@ public void testGetNewApplicationOneBadSC()
181179 */
182180 @ Test
183181 public void testGetNewApplicationTwoBadSCs ()
184- throws YarnException , IOException , InterruptedException {
185- System . out . println ("Test getNewApplication with two bad SubClusters" );
182+ throws Exception {
183+ LOG . info ("Test getNewApplication with two bad SubClusters" );
186184 setupCluster (Arrays .asList (bad1 , bad2 ));
187185
188- try {
189- interceptor .getNewApplication (GetNewApplicationRequest .newInstance ());
190- Assert .fail ();
191- } catch (Exception e ) {
192- System .out .println (e .toString ());
193- Assert .assertTrue (e .getMessage ()
194- .equals (FederationPolicyUtils .NO_ACTIVE_SUBCLUSTER_AVAILABLE ));
195- }
186+ GetNewApplicationRequest request = GetNewApplicationRequest .newInstance ();
187+ LambdaTestUtils .intercept (YarnException .class , FederationPolicyUtils .NO_ACTIVE_SUBCLUSTER_AVAILABLE ,
188+ () -> interceptor .getNewApplication (request ));
196189 }
197190
198191 /**
@@ -201,16 +194,14 @@ public void testGetNewApplicationTwoBadSCs()
201194 */
202195 @ Test
203196 public void testGetNewApplicationOneBadOneGood ()
204- throws YarnException , IOException , InterruptedException {
205- System .out .println ("Test getNewApplication with one bad, one good SC" );
197+ throws YarnException , IOException {
198+
199+ LOG .info ("Test getNewApplication with one bad, one good SC" );
206200 setupCluster (Arrays .asList (good , bad2 ));
207- GetNewApplicationResponse response = null ;
208- try {
209- response =
210- interceptor .getNewApplication (GetNewApplicationRequest .newInstance ());
211- } catch (Exception e ) {
212- Assert .fail ();
213- }
201+ GetNewApplicationRequest request = GetNewApplicationRequest .newInstance ();
202+ GetNewApplicationResponse response = interceptor .getNewApplication (request );
203+
204+ Assert .assertNotNull (response );
214205 Assert .assertEquals (ResourceManager .getClusterTimeStamp (),
215206 response .getApplicationId ().getClusterTimestamp ());
216207 }
@@ -221,24 +212,17 @@ public void testGetNewApplicationOneBadOneGood()
221212 */
222213 @ Test
223214 public void testSubmitApplicationOneBadSC ()
224- throws YarnException , IOException , InterruptedException {
215+ throws Exception {
225216
226- System . out . println ("Test submitApplication with one bad SubCluster" );
217+ LOG . info ("Test submitApplication with one bad SubCluster" );
227218 setupCluster (Arrays .asList (bad2 ));
228219
229220 final ApplicationId appId =
230221 ApplicationId .newInstance (System .currentTimeMillis (), 1 );
231222
232- final SubmitApplicationRequest request = mockSubmitApplicationRequest (
233- appId );
234- try {
235- interceptor .submitApplication (request );
236- Assert .fail ();
237- } catch (Exception e ) {
238- System .out .println (e );
239- Assert .assertTrue (e .getMessage ()
240- .equals (FederationPolicyUtils .NO_ACTIVE_SUBCLUSTER_AVAILABLE ));
241- }
223+ final SubmitApplicationRequest request = mockSubmitApplicationRequest (appId );
224+ LambdaTestUtils .intercept (YarnException .class , FederationPolicyUtils .NO_ACTIVE_SUBCLUSTER_AVAILABLE ,
225+ () -> interceptor .submitApplication (request ));
242226 }
243227
244228 private SubmitApplicationRequest mockSubmitApplicationRequest (
@@ -261,23 +245,16 @@ private SubmitApplicationRequest mockSubmitApplicationRequest(
261245 */
262246 @ Test
263247 public void testSubmitApplicationTwoBadSCs ()
264- throws YarnException , IOException , InterruptedException {
248+ throws Exception {
265249 System .out .println ("Test submitApplication with two bad SubClusters" );
266250 setupCluster (Arrays .asList (bad1 , bad2 ));
267251
268252 final ApplicationId appId =
269253 ApplicationId .newInstance (System .currentTimeMillis (), 1 );
270254
271- final SubmitApplicationRequest request = mockSubmitApplicationRequest (
272- appId );
273- try {
274- interceptor .submitApplication (request );
275- Assert .fail ();
276- } catch (Exception e ) {
277- System .out .println (e .toString ());
278- Assert .assertTrue (e .getMessage ()
279- .equals (FederationPolicyUtils .NO_ACTIVE_SUBCLUSTER_AVAILABLE ));
280- }
255+ final SubmitApplicationRequest request = mockSubmitApplicationRequest (appId );
256+ LambdaTestUtils .intercept (YarnException .class , FederationPolicyUtils .NO_ACTIVE_SUBCLUSTER_AVAILABLE ,
257+ () -> interceptor .submitApplication (request ));
281258 }
282259
283260 /**
@@ -293,18 +270,18 @@ public void testSubmitApplicationOneBadOneGood()
293270 final ApplicationId appId =
294271 ApplicationId .newInstance (System .currentTimeMillis (), 1 );
295272
296- final SubmitApplicationRequest request = mockSubmitApplicationRequest (
297- appId );
298- try {
299- interceptor .submitApplication (request );
300- } catch (Exception e ) {
301- Assert .fail ();
302- }
303- Assert .assertEquals (good ,
304- stateStore
305- .getApplicationHomeSubCluster (
306- GetApplicationHomeSubClusterRequest .newInstance (appId ))
307- .getApplicationHomeSubCluster ().getHomeSubCluster ());
308- }
273+ final SubmitApplicationRequest request = mockSubmitApplicationRequest (appId );
274+ SubmitApplicationResponse response = interceptor .submitApplication (request );
275+ Assert .assertNotNull (response );
276+
277+ GetApplicationHomeSubClusterRequest getAppRequest =
278+ GetApplicationHomeSubClusterRequest .newInstance (appId );
279+ GetApplicationHomeSubClusterResponse getAppResponse =
280+ stateStore .getApplicationHomeSubCluster (getAppRequest );
281+ Assert .assertNotNull (getAppResponse );
309282
283+ ApplicationHomeSubCluster responseHomeSubCluster =
284+ getAppResponse .getApplicationHomeSubCluster ();
285+ Assert .assertEquals (good ,responseHomeSubCluster );
286+ }
310287}
0 commit comments