@Override
  public synchronized DatasetVersionRecord addDatasetVersion(String accountName, String containerName,
      String datasetName, String version, long timeToLiveInSeconds, long creationTimeInMs,
      boolean datasetVersionTtlEnabled, DatasetVersionState datasetVersionState) throws AccountServiceException {
    Account account = nameToAccountMap.get(accountName);
    short accountId = account.getId();
    short containerId = account.getContainerByName(containerName).getId();
    idToDatasetVersionMap.putIfAbsent(new Pair<>(accountId, containerId), new HashMap<>());
    Dataset dataset = getDataset(accountName, containerName, datasetName);
    long updatedExpirationTimeMs = Utils.Infinite_Time;
    if (dataset.getRetentionTimeInSeconds() != null) {
      updatedExpirationTimeMs = Utils.addSecondsToEpochTime(creationTimeInMs, dataset.getRetentionTimeInSeconds());
    }
    if (datasetVersionTtlEnabled | dataset.getRetentionTimeInSeconds() == null) {
      updatedExpirationTimeMs = Utils.addSecondsToEpochTime(creationTimeInMs, timeToLiveInSeconds);
    }
    if ("LATEST".equals(version)) {
      List<Map.Entry<Pair<String, String>, DatasetVersionRecord>> datasetToDatasetVersionList =
          new ArrayList<>(idToDatasetVersionMap.get(new Pair<>(accountId, containerId)).entrySet());
      datasetToDatasetVersionList.sort(
          (entry1, entry2) -> entry2.getValue().getVersion().compareTo(entry1.getValue().getVersion()));
      if (datasetToDatasetVersionList.size() == 0) {
        version = "1";
      } else {
        version = String.valueOf(Integer.parseInt(datasetToDatasetVersionList.get(0).getValue().getVersion()) + 1);
      }
    }
    DatasetVersionRecord datasetVersionRecord =
        new DatasetVersionRecord(accountId, containerId, datasetName, version, updatedExpirationTimeMs,
            creationTimeInMs, null);
    idToDatasetVersionMap.get(new Pair<>(accountId, containerId))
        .put(new Pair<>(datasetName, version), datasetVersionRecord);
    return datasetVersionRecord;
  }
Constructor.
@param shouldReturnOnlyUnknown {@code true} if always returns {@link InMemAccountService#UNKNOWN_ACCOUNT} when queried
                                                    by account name; {@code false} to do the actual query.
@param notifyConsumers {@code true} if consumers should be notified of account changes. {@code false} otherwise.
ambry-test-utils/src/main/java/com/github/ambry/account/InMemAccountService.java