private int getFileCount(FileSystem fs, Path path) throws Exception {
    try {
      int count = 0;
      if (!fs.exists(path)) {
        return count;
      }
      RemoteIterator<LocatedFileStatus> lfs = fs.listFiles(path, true);
      while (lfs.hasNext()) {
        LocatedFileStatus lf = lfs.next();
        LOG.info(lf.getPath().toString());
        if (lf.isFile()) {
          count++;
        }
      }
      return count;
    } catch (IOException e) {
      throw new Exception("Exception while list files on " + path, e);
    }
  }
Test util method to run the insert overwrite table or truncate table test on a table

@param isAutoPurge - If set, creates a table with auto.purge with the given value
@param isExternal - if set creates a external table for the test
@param isPartitioned - if set creates a partitioned table for the test
@param purgeExpected - if set the assert condition for the test is such that it expectes old
         table data to be moved to trash. If not creates a assert condition to make sure that
         data is not moved to trash
@param isTruncateTest - if set uses truncate table command for the test. Otherwise uses Insert
         overwrite table command for the test
@param testTableName - table name for the test table
@throws Exception
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestAutoPurgeTables.java