private void setRecordMetadatas(
      Record record, MetadataSchema schema, Octets octets, int counter) {
    Metadata description = schema.getMetadata("description");

    RandomWordsIterator wordsIterator = setup.getRandomWordsIterator(counter);

    record.set(Schemas.TITLE, wordsIterator.nextWords(8));
    record.set(description, wordsIterator.nextWordsOfLength(octets));
  }
  @Override
  public void init(ServletConfig config) throws ServletException {
    super.init(config);

    setup = newTestSetup();

    if ("true".equals(System.getProperty("benchmarkServiceEnabled"))) {
      int numberOfRootCategories = getRequiredIntegerConfig(config, NUMBER_OF_ROOT_CATEGORIES);
      int numberOfLevel1Categories = getRequiredIntegerConfig(config, NUMBER_OF_LEVEL1_CATEGORIES);
      int numberOfLevel2Categories = getRequiredIntegerConfig(config, NUMBER_OF_LEVEL2_CATEGORIES);
      int numberOfLevel1AdministrativeUnits =
          getRequiredIntegerConfig(config, NUMBER_OF_LEVEL1_ADMINISTRATIVE_UNITS);
      int numberOfLevel2AdministrativeUnits =
          getRequiredIntegerConfig(config, NUMBER_OF_LEVEL2_ADMINISTRATIVE_UNITS);
      int numberOfFolders = getRequiredIntegerConfig(config, NUMBER_OF_FOLDERS);
      String contentSamplesFilepath = getRequiredConfig(config, CONTENT_SAMPLES);

      setup.initializeCollectionIfRequired(
          numberOfRootCategories,
          numberOfLevel1Categories,
          numberOfLevel2Categories,
          numberOfLevel1AdministrativeUnits,
          numberOfLevel2AdministrativeUnits,
          numberOfFolders,
          COLLECTION);

      setCategoriesAndClassificationIdsList();

      IOFileFilter fileFilter =
          new IOFileFilter() {

            @Override
            public boolean accept(File file) {
              return true;
            }

            @Override
            public boolean accept(File dir, String name) {
              return true;
            }
          };

      File contentSamplesFile = new File(contentSamplesFilepath);
      if (!contentSamplesFile.exists()) {
        throw new RuntimeException("Folder '" + contentSamplesFilepath + "' does not exist");
      }
      Collection<File> files = FileUtils.listFiles(contentSamplesFile, fileFilter, fileFilter);
      if (files == null || files.isEmpty()) {
        throw new RuntimeException("Folder '" + contentSamplesFilepath + "' is empty");
      }
      allPdfFiles = new ArrayList<>(files);
    }
  }
  void doAddContent(HttpServletRequest request, HttpServletResponse response, int serviceCall)
      throws ServletException, IOException {

    IOServices ioServices = getIOServices();
    RecordsFlushing recordsFlushing = getRecordsFlushing(request);
    User user = getUserServices().getUserInCollection("admin", COLLECTION);

    List<Record> records = getRandomFolders(1, serviceCall);
    if (!records.isEmpty()) {

      ContentManager contentManager = getContentServices();
      MetadataSchemaTypes types = getSchemaTypes(COLLECTION);
      MetadataSchema documentSchema = types.getSchema(Document.DEFAULT_SCHEMA);
      Document document =
          new Document(getRecordServices().newRecordWithSchema(documentSchema), types);

      int qtyOfFiles = allPdfFiles.size();
      int index = setup.getRandom().nextInt(qtyOfFiles);
      File file = allPdfFiles.get(index);
      BufferedInputStream inputStream =
          new BufferedInputStream(ioServices.newFileInputStream(file, CONTENT_TO_ADD_STREAM));
      ContentVersionDataSummary dataSummary = getContentServices().upload(inputStream);
      document.setTitle(file.getName());
      document.setContent(contentManager.createMajor(user, file.getName(), dataSummary));
      document.setFolder(records.get(0).getId());

      Transaction transaction = new Transaction(asList(document.getWrappedRecord()));
      transaction.setRecordFlushing(recordsFlushing);
      transaction.setOptimisticLockingResolution(OptimisticLockingResolution.EXCEPTION);
      try {
        getRecordServices().execute(transaction);
      } catch (RecordServicesException e) {
        throw new RuntimeException(e);
      }

      IOUtils.closeQuietly(inputStream);
    }
  }