@Override
  protected void parseDirectories(File stackRoot, File commonServicesRoot, File extensionRoot) throws AmbariException {
    try {
      // Ensure correct behavior during the parallel test execution.
      lock.lock();

      ModulesPathsKey pathsKey = new ModulesPathsKey(stackRoot, commonServicesRoot, extensionRoot);
      CachedModules cachedModules = pathsToCachedModulesMap.get(pathsKey);

      if (cachedModules == null) {
        super.parseDirectories(stackRoot, commonServicesRoot, extensionRoot);
        CachedModules newEntry = new CachedModules(commonServiceModules, stackModules, extensionModules, stackMap);
        pathsToCachedModulesMap.put(pathsKey, newEntry);
      } else {
        commonServiceModules = cachedModules.getCachedCommonServiceModules();
        stackModules = cachedModules.getCachedStackModules();
        extensionModules = cachedModules.getCachedExtensionModules();
        stackMap = cachedModules.getCachedStackMap();
      }
    } finally {
      lock.unlock();
    }
  }
Directory tree rescans and stack modules parsing take much time on every module init.
This class enhances {@code}StackManager{@code} to reuse already parsed modules.
ambari-server/src/test/java/org/apache/ambari/server/stack/StackManagerMock.java