public static void format(Mode mode, AlluxioConfiguration alluxioConf) throws IOException {
    NoopUfsManager noopUfsManager = new NoopUfsManager();
    switch (mode) {
      case MASTER:
        URI journalLocation = JournalUtils.getJournalLocation();
        LOG.info("Formatting master journal: {}", journalLocation);
        JournalSystem journalSystem = new JournalSystem.Builder()
            .setLocation(journalLocation).build(CommonUtils.ProcessType.MASTER);
        for (String masterServiceName : ServiceUtils.getMasterServiceNames()) {
          journalSystem.createJournal(new NoopMaster(masterServiceName, noopUfsManager));
        }
        journalSystem.format();
        break;
      case WORKER:
        String workerDataFolder = Configuration.getString(PropertyKey.WORKER_DATA_FOLDER);
        LOG.info("Formatting worker data folder: {}", workerDataFolder);
        int storageLevels = Configuration.getInt(PropertyKey.WORKER_TIERED_STORE_LEVELS);
        for (int level = 0; level < storageLevels; level++) {
          PropertyKey tierLevelDirPath =
              PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_PATH.format(level);
          String[] dirPaths = Configuration.getString(tierLevelDirPath).split(",");
          String name = "Data path for tier " + level;
          for (String dirPath : dirPaths) {
            String dirWorkerDataFolder = CommonUtils.getWorkerDataDirectory(dirPath, alluxioConf);
            LOG.info("Formatting {}:{}", name, dirWorkerDataFolder);
            formatWorkerDataFolder(dirWorkerDataFolder);
          }
        }
        break;
      default:
        throw new RuntimeException(String.format("Unrecognized format mode: %s", mode));
    }
  }
@Test
  public void formatWorker() throws Exception {
    final int storageLevels = 1;
    final String perms = "rwx------";
    String workerDataFolder;
    final File[] dirs = new File[] {
        mTemporaryFolder.newFolder("level0")
    };
    for (File dir : dirs) {
      workerDataFolder = CommonUtils.getWorkerDataDirectory(dir.getPath(),
          Configuration.global());
      FileUtils.createDir(PathUtils.concatPath(workerDataFolder, "subdir"));
      FileUtils.createFile(PathUtils.concatPath(workerDataFolder, "file"));
    }
    try (Closeable r = new ConfigurationRule(new HashMap<PropertyKey, Object>() {
      {
        put(PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_PATH.format(0), dirs[0].getPath());
        put(PropertyKey.WORKER_TIERED_STORE_LEVELS, storageLevels);
        put(PropertyKey.WORKER_DATA_FOLDER_PERMISSIONS, perms);
      }
    }, Configuration.modifiableGlobal()).toResource()) {
      Format.format(Format.Mode.WORKER, Configuration.global());
    }
  }