@Test
public void testUpdateReservation() {

  Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L,
      resCalc, minAlloc, maxAlloc, planName, replanner, true, context);
  ReservationId reservationID =
      ReservationSystemTestUtil.getNewReservationId();
  // First add a reservation
  int[] alloc = { 10, 10, 10, 10, 10, 10 };
  int start = 100;
  ReservationAllocation rAllocation =
      createReservationAllocation(reservationID, start, alloc);
  Assert.assertNull(plan.getReservationById(reservationID));
  try {
    plan.addReservation(rAllocation, false);
  } catch (PlanningException e) {
    Assert.fail(e.getMessage());
  }
  doAssertions(plan, rAllocation);
  RLESparseResourceAllocation userCons =
      plan.getConsumptionForUserOverTime(user, start, start + alloc.length);
  for (int i = 0; i < alloc.length; i++) {
    assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])),
        plan.getTotalCommittedResources(start + i));
    assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])),
        userCons.getCapacityAtTime(start + i));
  }
  // Now update it
  start = 110;
  int[] updatedAlloc = { 0, 5, 10, 10, 5, 0 };
  rAllocation =
      createReservationAllocation(reservationID, start, updatedAlloc, true);
  try {
    plan.updateReservation(rAllocation);
  } catch (PlanningException e) {
    Assert.fail(e.getMessage());
  }
  doAssertions(plan, rAllocation);
  userCons = plan.getConsumptionForUserOverTime(user, start,
      start + updatedAlloc.length);
  for (int i = 0; i < updatedAlloc.length; i++) {
    assertEquals(Resource.newInstance(1024 * (updatedAlloc[i] + i),
        updatedAlloc[i] + i), plan.getTotalCommittedResources(start + i));
    assertEquals(Resource.newInstance(1024 * (updatedAlloc[i] + i),
        updatedAlloc[i] + i), userCons.getCapacityAtTime(start + i));
  }
}