diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java index dd19acb..35bcc46 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java @@ -69,8 +69,6 @@ import org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse; import org.apache.hadoop.yarn.api.protocolrecords.GetLabelsToNodesRequest; import org.apache.hadoop.yarn.api.protocolrecords.GetLabelsToNodesResponse; -import org.apache.hadoop.yarn.api.protocolrecords.GetNewReservationRequest; -import org.apache.hadoop.yarn.api.protocolrecords.GetNewReservationResponse; import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsRequest; import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse; import org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest; @@ -158,7 +156,7 @@ public void testClientStop() { @SuppressWarnings("deprecation") @Test (timeout = 30000) - public void testSubmitApplication() { + public void testSubmitApplication() throws Exception { Configuration conf = new Configuration(); conf.setLong(YarnConfiguration.YARN_CLIENT_APP_SUBMISSION_POLL_INTERVAL_MS, 100); // speed up tests @@ -184,8 +182,6 @@ public void testSubmitApplication() { Assert.assertTrue(e instanceof ApplicationIdNotProvidedException); Assert.assertTrue(e.getMessage().contains( "ApplicationId is not provided in ApplicationSubmissionContext")); - } catch (IOException e) { - Assert.fail("IOException is not expected."); } // Submit the application with applicationId provided @@ -197,13 +193,7 @@ public void testSubmitApplication() { System.currentTimeMillis(), i); when(context.getApplicationId()).thenReturn(applicationId); ((MockYarnClient) client).setYarnApplicationState(exitStates[i]); - try { - client.submitApplication(context); - } catch (YarnException e) { - Assert.fail("Exception is not expected."); - } catch (IOException e) { - Assert.fail("Exception is not expected."); - } + client.submitApplication(context); verify(((MockYarnClient) client).mockReport,times(4 * i + 4)) .getYarnApplicationState(); } @@ -583,12 +573,11 @@ public void start() { .thenReturn(mockNodeToLabelsResponse); historyClient = mock(AHSClient.class); - - } catch (YarnException e) { - Assert.fail("Exception is not expected."); - } catch (IOException e) { - Assert.fail("Exception is not expected."); + + } catch (Exception e) { + Assert.fail("Unexpected exception caught: " + e); } + when(mockResponse.getApplicationReport()).thenReturn(mockReport); } @@ -993,18 +982,6 @@ private ApplicationId createApp(YarnClient rmClient, boolean unmanaged) return appId; } - private GetNewReservationResponse getNewReservation(YarnClient rmClient) { - GetNewReservationRequest newReservationRequest = GetNewReservationRequest - .newInstance(); - GetNewReservationResponse getNewReservationResponse = null; - try { - getNewReservationResponse = rmClient.createReservation(); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - return getNewReservationResponse; - } - private void waitTillAccepted(YarnClient rmClient, ApplicationId appId, boolean unmanagedApplication) throws Exception { @@ -1071,13 +1048,10 @@ TimelineClient createTimelineClient() throws IOException, YarnException { }); client.init(conf); - try { - conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_CLIENT_BEST_EFFORT, true); - client.serviceInit(conf); - client.getTimelineDelegationToken(); - } catch (Exception e) { - Assert.fail("Should not have thrown an exception"); - } + conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_CLIENT_BEST_EFFORT, true); + client.serviceInit(conf); + client.getTimelineDelegationToken(); + try { conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_CLIENT_BEST_EFFORT, false); client.serviceInit(conf); @@ -1229,16 +1203,13 @@ private YarnClient setupYarnClient(MiniYARNCluster cluster) { } private ReservationSubmissionRequest submitReservationTestHelper( - YarnClient client, long arrival, long deadline, long duration) { - ReservationId reservationID = getNewReservation(client).getReservationId(); + YarnClient client, long arrival, long deadline, long duration) + throws IOException, YarnException { + ReservationId reservationID = client.createReservation().getReservationId(); ReservationSubmissionRequest sRequest = createSimpleReservationRequest( reservationID, 4, arrival, deadline, duration); - ReservationSubmissionResponse sResponse = null; - try { - sResponse = client.submitReservation(sRequest); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + ReservationSubmissionResponse sResponse = + client.submitReservation(sRequest); Assert.assertNotNull(sResponse); Assert.assertNotNull(reservationID); System.out.println("Submit reservation response: " + reservationID); @@ -1260,11 +1231,7 @@ public void testCreateReservation() throws Exception { // Submit the reservation again with the same request and make sure it // passes. - try { - client.submitReservation(sRequest); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + client.submitReservation(sRequest); // Submit the reservation with the same reservation id but different // reservation definition, and ensure YarnException is thrown. @@ -1314,12 +1281,7 @@ public void testUpdateReservation() throws Exception { rDef.setDeadline(deadline); ReservationUpdateRequest uRequest = ReservationUpdateRequest.newInstance(rDef, reservationID); - ReservationUpdateResponse uResponse = null; - try { - uResponse = client.updateReservation(uRequest); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + ReservationUpdateResponse uResponse = client.updateReservation(uRequest); Assert.assertNotNull(uResponse); System.out.println("Update reservation response: " + uResponse); } finally { @@ -1344,15 +1306,10 @@ public void testListReservationsByReservationId() throws Exception{ submitReservationTestHelper(client, arrival, deadline, duration); ReservationId reservationID = sRequest.getReservationId(); - ReservationListResponse response = null; ReservationListRequest request = ReservationListRequest.newInstance( ReservationSystemTestUtil.reservationQ, reservationID.toString(), -1, -1, false); - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + ReservationListResponse response = client.listReservations(request); Assert.assertNotNull(response); Assert.assertEquals(1, response.getReservationAllocationState().size()); Assert.assertEquals(response.getReservationAllocationState().get(0) @@ -1388,12 +1345,7 @@ public void testListReservationsByTimeInterval() throws Exception { ReservationSystemTestUtil.reservationQ, "", arrival + duration / 2, arrival + duration / 2, true); - ReservationListResponse response = null; - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + ReservationListResponse response = client.listReservations(request); Assert.assertNotNull(response); Assert.assertEquals(1, response.getReservationAllocationState().size()); Assert.assertEquals(response.getReservationAllocationState().get(0) @@ -1402,12 +1354,7 @@ public void testListReservationsByTimeInterval() throws Exception { request = ReservationListRequest.newInstance( ReservationSystemTestUtil.reservationQ, "", 1, Long.MAX_VALUE, true); - response = null; - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + response = client.listReservations(request); Assert.assertNotNull(response); Assert.assertEquals(1, response.getReservationAllocationState().size()); Assert.assertEquals(response.getReservationAllocationState().get(0) @@ -1449,12 +1396,7 @@ public void testListReservationsByInvalidTimeInterval() throws Exception { ReservationListRequest request = ReservationListRequest .newInstance(ReservationSystemTestUtil.reservationQ, "", 1, -1, true); - ReservationListResponse response = null; - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + ReservationListResponse response = client.listReservations(request); Assert.assertNotNull(response); Assert.assertEquals(1, response.getReservationAllocationState().size()); Assert.assertEquals(response.getReservationAllocationState().get(0) @@ -1464,12 +1406,7 @@ public void testListReservationsByInvalidTimeInterval() throws Exception { request = ReservationListRequest.newInstance( ReservationSystemTestUtil.reservationQ, "", 1, -10, true); - response = null; - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + response = client.listReservations(request); Assert.assertNotNull(response); Assert.assertEquals(1, response.getReservationAllocationState().size()); Assert.assertEquals(response.getReservationAllocationState().get(0) @@ -1501,12 +1438,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() ReservationSystemTestUtil.reservationQ, "", Long.MAX_VALUE, -1, false); - ReservationListResponse response = null; - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + ReservationListResponse response = client.listReservations(request); // Ensure all reservations are filtered out. Assert.assertNotNull(response); @@ -1521,12 +1453,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() ReservationSystemTestUtil.reservationQ, "", deadline + duration, deadline + 2 * duration, false); - response = null; - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + response = client.listReservations(request); // Ensure all reservations are filtered out. Assert.assertNotNull(response); @@ -1539,12 +1466,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() ReservationSystemTestUtil.reservationQ, "", 0, arrival - duration, false); - response = null; - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + response = client.listReservations(request); // Ensure all reservations are filtered out. Assert.assertNotNull(response); @@ -1554,12 +1476,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() request = ReservationListRequest .newInstance(ReservationSystemTestUtil.reservationQ, "", 0, 1, false); - response = null; - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + response = client.listReservations(request); // Ensure all reservations are filtered out. Assert.assertNotNull(response); @@ -1590,12 +1507,7 @@ public void testReservationDelete() throws Exception { // Delete the reservation ReservationDeleteRequest dRequest = ReservationDeleteRequest.newInstance(reservationID); - ReservationDeleteResponse dResponse = null; - try { - dResponse = client.deleteReservation(dRequest); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + ReservationDeleteResponse dResponse = client.deleteReservation(dRequest); Assert.assertNotNull(dResponse); System.out.println("Delete reservation response: " + dResponse); @@ -1604,12 +1516,7 @@ public void testReservationDelete() throws Exception { ReservationSystemTestUtil.reservationQ, reservationID.toString(), -1, -1, false); - ReservationListResponse response = null; - try { - response = client.listReservations(request); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + ReservationListResponse response = client.listReservations(request); Assert.assertNotNull(response); Assert.assertEquals(0, response.getReservationAllocationState().size()); } finally {