public RouterQuotaUsage getQuotaUsage(String path) {
    readLock.lock();
    try {
      RouterQuotaUsage quotaUsage = this.cache.get(path);
      if (quotaUsage != null && isQuotaSet(quotaUsage)) {
        return quotaUsage;
      }

      // If not found, look for its parent path usage value.
      int pos = path.lastIndexOf(Path.SEPARATOR);
      if (pos != -1) {
        String parentPath = path.substring(0, pos);
        return getQuotaUsage(parentPath);
      }
    } finally {
      readLock.unlock();
    }

    return null;
  }
@Test
  public void testGetQuotaUsage() {
    RouterQuotaUsage quotaGet;

    // test case1: get quota with a non-exist path
    quotaGet = manager.getQuotaUsage("/non-exist-path");
    assertNull(quotaGet);

    // test case2: get quota from a no-quota set path
    RouterQuotaUsage.Builder quota = new RouterQuotaUsage.Builder()
        .quota(HdfsConstants.QUOTA_RESET)
        .spaceQuota(HdfsConstants.QUOTA_RESET);
    manager.put("/noQuotaSet", quota.build());
    quotaGet = manager.getQuotaUsage("/noQuotaSet");
    // it should return null
    assertNull(quotaGet);

    // test case3: get quota from a quota-set path
    quota.quota(1);
    quota.spaceQuota(HdfsConstants.QUOTA_RESET);
    manager.put("/hasQuotaSet", quota.build());
    quotaGet = manager.getQuotaUsage("/hasQuotaSet");
    assertEquals(1, quotaGet.getQuota());
    assertEquals(HdfsConstants.QUOTA_RESET, quotaGet.getSpaceQuota());

    // test case4: get quota with a non-exist child path
    quotaGet = manager.getQuotaUsage("/hasQuotaSet/file");
    // it will return the nearest ancestor which quota was set
    assertEquals(1, quotaGet.getQuota());
    assertEquals(HdfsConstants.QUOTA_RESET, quotaGet.getSpaceQuota());

    // test case5: get quota with a child path which its parent
    // wasn't quota set
    quota.quota(HdfsConstants.QUOTA_RESET);
    quota.spaceQuota(HdfsConstants.QUOTA_RESET);
    manager.put("/hasQuotaSet/noQuotaSet", quota.build());
    // here should return the quota of path /hasQuotaSet
    // (the nearest ancestor which quota was set)
    quotaGet = manager.getQuotaUsage("/hasQuotaSet/noQuotaSet/file");
    assertEquals(1, quotaGet.getQuota());
    assertEquals(HdfsConstants.QUOTA_RESET, quotaGet.getSpaceQuota());

    // test case6: get quota with a child path which its parent was quota set
    quota.quota(2);
    quota.spaceQuota(HdfsConstants.QUOTA_RESET);
    manager.put("/hasQuotaSet/hasQuotaSet", quota.build());
    // here should return the quota of path /hasQuotaSet/hasQuotaSet
    quotaGet = manager.getQuotaUsage("/hasQuotaSet/hasQuotaSet/file");
    assertEquals(2, quotaGet.getQuota());
    assertEquals(HdfsConstants.QUOTA_RESET, quotaGet.getSpaceQuota());
  }