@Test
    public void testBatchingWhenException() throws Exception {
        HiveMetaStoreClient spyMSC = spy(msc);
        hive.setMSC(spyMSC);
        // This will throw exception only the first time.
        doThrow(new MetaException()).doCallRealMethod()
                .when(spyMSC).getPartitionsByNames(any());

        hive.getAllPartitionsInBatches(hive.getTable(dbName, tableName), 30, 2, 5, PARTIAL_PARTITION_SPEC, IS_AUTH_REQUIRED);
        ArgumentCaptor<GetPartitionsByNamesRequest> req = ArgumentCaptor.forClass(GetPartitionsByNamesRequest.class);
        // The first call with batch size of 30 will fail, the rest two call will be of size 15 each. Total 3 calls
        verify(spyMSC, times(3)).getPartitionsByNames(req.capture());
        List<GetPartitionsByNamesRequest> apds = req.getAllValues();
        Assert.assertEquals(3, apds.size());

        Assert.assertEquals(30, apds.get(0).getNames().size());
        Assert.assertEquals(15, apds.get(1).getNames().size());
        Assert.assertEquals(15, apds.get(2).getNames().size());

        Set<String> partNames = new HashSet<>(apds.get(1).getNames());
        partNames.addAll(apds.get(2).getNames());
        assert(partNames.size() == 30);

        List<String> partitionNames = hive.getPartitionNames(table.getDbName(),table.getTableName(), (short) -1);
        assert(partitionNames.size() == 30);
        partitionNames.forEach(partNames::remove);
        assert(partitionNames.size() == 30);
        // In case any duplicate/incomplete list is given by hive.getAllPartitionsInBatches, the below assertion will fail
        assert(partNames.size() == 0);
    }
Tests the number of calls to getPartitions and the respective batch sizes when first call to
getPartitions throws HiveException. The batch size should be reduced by the decayingFactor
and the second call should fetch all the results

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