@Test
  public void testNumberOfListStatusCalls() throws IOException, MetastoreException {
    LocalFileSystem mockFs = Mockito.mock(LocalFileSystem.class);
    Path tableLocation = new Path("mock:///tmp/testTable");

    Path countryUS = new Path(tableLocation, "country=US");
    Path countryIND = new Path(tableLocation, "country=IND");

    Path cityPA = new Path(countryUS, "city=PA");
    Path citySF = new Path(countryUS, "city=SF");
    Path cityBOM = new Path(countryIND, "city=BOM");
    Path cityDEL = new Path(countryIND, "city=DEL");

    Path paData = new Path(cityPA, "datafile");
    Path sfData = new Path(citySF, "datafile");
    Path bomData = new Path(cityBOM, "datafile");
    Path delData = new Path(cityDEL, "datafile");

    //level 1 listing
    FileStatus[] allCountries = getMockFileStatus(countryUS, countryIND);
    mockListStatusIterator(mockFs, tableLocation, allCountries);

    //level 2 listing
    FileStatus[] filesInUS = getMockFileStatus(cityPA, citySF);
    mockListStatusIterator(mockFs, countryUS, filesInUS);

    FileStatus[] filesInInd = getMockFileStatus(cityBOM, cityDEL);
    mockListStatusIterator(mockFs, countryIND, filesInInd);

    //level 3 listing
    FileStatus[] paFiles = getMockFileStatus(paData);
    mockListStatusIterator(mockFs, cityPA, paFiles);

    FileStatus[] sfFiles = getMockFileStatus(sfData);
    mockListStatusIterator(mockFs, citySF, sfFiles);

    FileStatus[] bomFiles = getMockFileStatus(bomData);
    mockListStatusIterator(mockFs, cityBOM, bomFiles);

    FileStatus[] delFiles = getMockFileStatus(delData);
    mockListStatusIterator(mockFs, cityDEL, delFiles);

    HiveMetaStoreChecker checker = new HiveMetaStoreChecker(Mockito.mock(IMetaStoreClient.class),
        MetastoreConf.newMetastoreConf());
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    Set<Path> result = new HashSet<>();
    checker.checkPartitionDirs(executorService, tableLocation, result, mockFs,
        Arrays.asList("country", "city"));
    // if there are n partition columns, then number of times listStatus should be called
    // must be equal
    // to (numDirsAtLevel1) + (numDirsAtLevel2) + ... + (numDirAtLeveln-1)
    // in this case it should 1 (table level) + 2 (US, IND)
    verify(mockFs, times(3)).listStatusIterator(any(Path.class));
    Assert.assertEquals("msck should have found 4 unknown partitions", 4, result.size());
  }
Test counts the number of listStatus calls in the msck core method of
listing sub-directories. This is important to check since it unnecessary
listStatus calls could cause performance degradation in remote filesystems
like S3. The test creates a mock FileSystem object and a mock directory structure
to simulate a table which has 2 partition keys and 2 partition values at each level.
In the end it counts how many times the listStatus is called on the mock filesystem
and confirm its equal to the current theoretical value.

@throws IOException
@throws MetastoreException
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestMsckCheckPartitions.java