@Test
  public void testBatchingWhenException() throws Exception {
    // create 13 dummy partitions
    Set<PartitionResult> partsNotInMs = PartitionUtil.createPartsNotInMs(23);
    IMetaStoreClient spyDb = spy(db);
    // first call to createPartitions should throw exception
    doThrow(MetaException.class).doCallRealMethod().doCallRealMethod().when(spyDb)
      .add_partitions(any(), anyBoolean(), anyBoolean());

    // test with a batch size of 30 and decaying factor of 2
    msck.createPartitionsInBatches(spyDb, repairOutput, partsNotInMs, table, 30, 2, 0);
    // confirm the batch sizes were 23, 15, 8 in the three calls to create partitions
    ArgumentCaptor<Boolean> ifNotExistsArg = ArgumentCaptor.forClass(Boolean.class);
    ArgumentCaptor<Boolean> needResultsArg = ArgumentCaptor.forClass(Boolean.class);
    ArgumentCaptor<List<Partition>> argParts = ArgumentCaptor.forClass(List.class);
    // there should be 3 calls to create partitions with batch sizes of 23, 15, 8
    verify(spyDb, times(3)).add_partitions(argParts.capture(), ifNotExistsArg.capture(),
      needResultsArg.capture());
    List<List<Partition>> apds = argParts.getAllValues();
    int retryAttempt = 1;
    Assert.assertEquals(
        String.format("Unexpected batch size in retry attempt %d ", retryAttempt++), 23,
        apds.get(0).size());
    Assert.assertEquals(
        String.format("Unexpected batch size in retry attempt %d ", retryAttempt++), 15,
        apds.get(1).size());
    Assert.assertEquals(
        String.format("Unexpected batch size in retry attempt %d ", retryAttempt++), 8,
        apds.get(2).size());
    assertTrue(ifNotExistsArg.getValue());
    assertFalse(needResultsArg.getValue());
  }
Tests the number of calls to createPartitions and the respective batch sizes when first call to
createPartitions throws HiveException. The batch size should be reduced by the decayingFactor

@throws Exception
ql/src/test/org/apache/hadoop/hive/ql/exec/TestMsckCreatePartitionsInBatches.java