hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cur...@apache.org
Subject [50/50] [abbrv] git commit: Rebase against trunk
Date Mon, 22 Sep 2014 23:48:39 GMT
Rebase against trunk


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e82461be
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e82461be
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e82461be

Branch: refs/heads/YARN-1051
Commit: e82461be56fab0c3b5188219c8fc09946b0826ba
Parents: e53fdea f00e7af
Author: carlo curino <Carlo Curino>
Authored: Mon Sep 22 16:46:56 2014 -0700
Committer: carlo curino <Carlo Curino>
Committed: Mon Sep 22 16:46:56 2014 -0700

----------------------------------------------------------------------
 .../yarn/client/api/impl/TestYarnClient.java    | 97 ++++++++++++++++++++
 1 file changed, 97 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/e82461be/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java
----------------------------------------------------------------------
diff --cc hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java
index d7bea7a,5607b6e..c1f452c
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java
@@@ -808,66 -800,52 +808,163 @@@ public class TestYarnClient 
        public boolean isSecurityEnabled() {
          return true;
        }
 -    };
 +    });
      client.init(conf);
      client.start();
 -    ApplicationSubmissionContext context =
 -        mock(ApplicationSubmissionContext.class);
 -    ApplicationId applicationId = ApplicationId.newInstance(0, 1);
 -    when(context.getApplicationId()).thenReturn(applicationId);
 -    DataOutputBuffer dob = new DataOutputBuffer();
 -    Credentials credentials = new Credentials();
 -    credentials.writeTokenStorageToStream(dob);
 -    ByteBuffer tokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
 -    ContainerLaunchContext clc = ContainerLaunchContext.newInstance(
 -        null, null, null, null, tokens, null);
 -    when(context.getAMContainerSpec()).thenReturn(clc);
 -    client.submitApplication(context);
 -    // Check whether token is added or not
 -    credentials = new Credentials();
 -    DataInputByteBuffer dibb = new DataInputByteBuffer();
 -    tokens = clc.getTokens();
 -    if (tokens != null) {
 -      dibb.reset(tokens);
 -      credentials.readTokenStorageStream(dibb);
 -      tokens.rewind();
 +    try {
 +      // when i == 0, timeline DT already exists, no need to get one more
 +      // when i == 1, timeline DT doesn't exist, need to get one more
 +      for (int i = 0; i < 2; ++i) {
 +        ApplicationSubmissionContext context =
 +            mock(ApplicationSubmissionContext.class);
 +        ApplicationId applicationId = ApplicationId.newInstance(0, i + 1);
 +        when(context.getApplicationId()).thenReturn(applicationId);
 +        DataOutputBuffer dob = new DataOutputBuffer();
 +        Credentials credentials = new Credentials();
 +        if (i == 0) {
 +          credentials.addToken(client.timelineService, dToken);
 +        }
 +        credentials.writeTokenStorageToStream(dob);
 +        ByteBuffer tokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
 +        ContainerLaunchContext clc = ContainerLaunchContext.newInstance(
 +            null, null, null, null, tokens, null);
 +        when(context.getAMContainerSpec()).thenReturn(clc);
 +        client.submitApplication(context);
 +        if (i == 0) {
 +          // GetTimelineDelegationToken shouldn't be called
 +          verify(client, never()).getTimelineDelegationToken();
 +        }
 +        // In either way, token should be there
 +        credentials = new Credentials();
 +        DataInputByteBuffer dibb = new DataInputByteBuffer();
 +        tokens = clc.getTokens();
 +        if (tokens != null) {
 +          dibb.reset(tokens);
 +          credentials.readTokenStorageStream(dibb);
 +          tokens.rewind();
 +        }
 +        Collection<Token<? extends TokenIdentifier>> dTokens =
 +            credentials.getAllTokens();
 +        Assert.assertEquals(1, dTokens.size());
 +        Assert.assertEquals(dToken, dTokens.iterator().next());
 +      }
 +    } finally {
 +      client.stop();
      }
 -    Collection<Token<? extends TokenIdentifier>> dTokens =
 -        credentials.getAllTokens();
 -    Assert.assertEquals(1, dTokens.size());
 -    Assert.assertEquals(dToken, dTokens.iterator().next());
 -    client.stop();
 +  }
 +  
 +  @Test
 +  public void testReservationAPIs() {
 +    // initialize
 +    CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
 +    ReservationSystemTestUtil.setupQueueConfiguration(conf);
 +    conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
 +        ResourceScheduler.class);
 +    conf.setBoolean(YarnConfiguration.RM_RESERVATION_SYSTEM_ENABLE, true);
 +    MiniYARNCluster cluster =
 +        new MiniYARNCluster("testReservationAPIs", 2, 1, 1);
 +    YarnClient client = null;
 +    try {
 +      cluster.init(conf);
 +      cluster.start();
 +      final Configuration yarnConf = cluster.getConfig();
++      client = YarnClient.createYarnClient();
++      client.init(yarnConf);
++      client.start();
++
++      // create a reservation
++      Clock clock = new UTCClock();
++      long arrival = clock.getTime();
++      long duration = 60000;
++      long deadline = (long) (arrival + 1.05 * duration);
++      ReservationSubmissionRequest sRequest =
++          createSimpleReservationRequest(4, arrival, deadline, duration);
++      ReservationSubmissionResponse sResponse = null;
++      try {
++        sResponse = client.submitReservation(sRequest);
++      } catch (Exception e) {
++        Assert.fail(e.getMessage());
++      }
++      Assert.assertNotNull(sResponse);
++      ReservationId reservationID = sResponse.getReservationId();
++      Assert.assertNotNull(reservationID);
++      System.out.println("Submit reservation response: " + reservationID);
++
++      // Update the reservation
++      ReservationDefinition rDef = sRequest.getReservationDefinition();
++      ReservationRequest rr =
++          rDef.getReservationRequests().getReservationResources().get(0);
++      rr.setNumContainers(5);
++      arrival = clock.getTime();
++      duration = 30000;
++      deadline = (long) (arrival + 1.05 * duration);
++      rr.setDuration(duration);
++      rDef.setArrival(arrival);
++      rDef.setDeadline(deadline);
++      ReservationUpdateRequest uRequest =
++          ReservationUpdateRequest.newInstance(rDef, reservationID);
++      ReservationUpdateResponse uResponse = null;
++      try {
++        uResponse = client.updateReservation(uRequest);
++      } catch (Exception e) {
++        Assert.fail(e.getMessage());
++      }
++      Assert.assertNotNull(sResponse);
++      System.out.println("Update reservation response: " + uResponse);
++
++      // Delete the reservation
++      ReservationDeleteRequest dRequest =
++          ReservationDeleteRequest.newInstance(reservationID);
++      ReservationDeleteResponse dResponse = null;
++      try {
++        dResponse = client.deleteReservation(dRequest);
++      } catch (Exception e) {
++        Assert.fail(e.getMessage());
++      }
++      Assert.assertNotNull(sResponse);
++      System.out.println("Delete reservation response: " + dResponse);
++    } finally {
++      // clean-up
++      if (client != null) {
++        client.stop();
++      }
++      cluster.stop();
++    }
++  }
++
++  private ReservationSubmissionRequest createSimpleReservationRequest(
++      int numContainers, long arrival, long deadline, long duration) {
++    // create a request with a single atomic ask
++    ReservationRequest r =
++        ReservationRequest.newInstance(Resource.newInstance(1024, 1),
++            numContainers, 1, duration);
++    ReservationRequests reqs =
++        ReservationRequests.newInstance(Collections.singletonList(r),
++            ReservationRequestInterpreter.R_ALL);
++    ReservationDefinition rDef =
++        ReservationDefinition.newInstance(arrival, deadline, reqs,
++            "testYarnClient#reservation");
++    ReservationSubmissionRequest request =
++        ReservationSubmissionRequest.newInstance(rDef,
++            ReservationSystemTestUtil.reservationQ);
++    return request;
+   }
+   
+   @Test
+   public void testReservationAPIs() {
+     // initialize
+     CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
+     ReservationSystemTestUtil.setupQueueConfiguration(conf);
+     conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
+         ResourceScheduler.class);
+     conf.setBoolean(YarnConfiguration.RM_RESERVATION_SYSTEM_ENABLE, true);
+     MiniYARNCluster cluster =
+         new MiniYARNCluster("testReservationAPIs", 2, 1, 1);
+     YarnClient client = null;
+     try {
+       cluster.init(conf);
+       cluster.start();
+       final Configuration yarnConf = cluster.getConfig();
        client = YarnClient.createYarnClient();
        client.init(yarnConf);
        client.start();


Mime
View raw message