@Test
  public void testAddAndGetDatasetSemanticLongVersion() throws Exception {
    Account testAccount = makeTestAccountWithContainer();
    Container testContainer = new ArrayList<>(testAccount.getAllContainers()).get(0);
    Map<String, String> userTags = new HashMap<>();
    userTags.put("userTag", "tagValue");
    long datasetTtl = 3600L;

    //Test semantic long version.
    Dataset dataset =
        new DatasetBuilder(testAccount.getName(), testContainer.getName(), DATASET_NAME_WITH_SEMANTIC_LONG).setVersionSchema(
            Dataset.VersionSchema.SEMANTIC_LONG).setRetentionTimeInSeconds((long) -1).setUserTags(userTags).build();
    // Add a dataset to db
    mySqlAccountStore.addDataset(testAccount.getId(), testContainer.getId(), dataset);
    String version = "1.2.3.4";
    mySqlAccountStore.addDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
        testContainer.getName(), DATASET_NAME_WITH_SEMANTIC_LONG, version, -1, System.currentTimeMillis(), false,
        DatasetVersionState.READY);
    DatasetVersionRecord datasetVersionRecordWithSemanticVersion =
        mySqlAccountStore.getDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
            testContainer.getName(), DATASET_NAME_WITH_SEMANTIC_LONG, version);
    assertEquals("Mismatch in dataset version", version, datasetVersionRecordWithSemanticVersion.getVersion());

    // Add dataset version for non-existing dataset.
    try {
      mySqlAccountStore.addDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
          testContainer.getName(), "NonExistingDataset", version, -1, System.currentTimeMillis(), false,
          DatasetVersionState.READY);
      fail("Add dataset version should fail without dataset");
    } catch (AccountServiceException e) {
      assertEquals("Unexpected ErrorCode", AccountServiceErrorCode.NotFound, e.getErrorCode());
    }

    //add same dataset version, should fail
    try {
      mySqlAccountStore.addDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
          testContainer.getName(), DATASET_NAME_WITH_SEMANTIC_LONG, version, -1, 0, false, DatasetVersionState.READY);
      fail("Should fail due to dataset version already exist");
    } catch (AccountServiceException e) {
      assertEquals("Unexpected error code", AccountServiceErrorCode.ResourceConflict, e.getErrorCode());
    }

    //Delete dataset version
    mySqlAccountStore.deleteDatasetVersion(testAccount.getId(), testContainer.getId(), DATASET_NAME_WITH_SEMANTIC_LONG,
        version);

    //add dataset version again, should succeed.
    mySqlAccountStore.addDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
        testContainer.getName(), DATASET_NAME_WITH_SEMANTIC_LONG, version, -1, System.currentTimeMillis(), false,
        DatasetVersionState.READY);

    //get the new added dataset version, should not fail.
    mySqlAccountStore.getDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
        testContainer.getName(), DATASET_NAME_WITH_SEMANTIC_LONG, version);

    // Add dataset version which didn't follow the semantic long format.
    version = "1.2.3";
    try {
      mySqlAccountStore.addDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
          testContainer.getName(), DATASET_NAME_WITH_SEMANTIC_LONG, version, -1, System.currentTimeMillis(), false,
          DatasetVersionState.READY);
      fail("Add dataset version should fail with wrong format of semantic version");
    } catch (IllegalArgumentException e) {
      // do nothing
    }

    //delete the dataset, and can't add or get any dataset version.
    mySqlAccountStore.deleteDataset(testAccount.getId(), testContainer.getId(), DATASET_NAME_WITH_SEMANTIC_LONG);
    version = "1.2.3.5";
    try {
      mySqlAccountStore.addDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
          testContainer.getName(), DATASET_NAME_WITH_SEMANTIC_LONG, version, -1, System.currentTimeMillis(), false,
          DatasetVersionState.READY);
      fail("Should fail due to the dataset already gone");
    } catch (AccountServiceException e) {
      assertEquals("Unexpected error code", AccountServiceErrorCode.Deleted, e.getErrorCode());
    }

    try {
      mySqlAccountStore.getDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
          testContainer.getName(), DATASET_NAME_WITH_SEMANTIC_LONG, version);
      fail("Should fail due to the dataset already gone");
    } catch (AccountServiceException e) {
      assertEquals("Unexpected error code", AccountServiceErrorCode.Deleted, e.getErrorCode());
    }

    List<DatasetVersionRecord> datasetVersionRecords =
        mySqlAccountStore.getAllValidVersionForDatasetDeletion(testAccount.getId(), testContainer.getId(),
            DATASET_NAME_WITH_SEMANTIC_LONG);
    assertEquals("Mismatch on number of valid dataset versions", 1, datasetVersionRecords.size());
    assertEquals("Mismatch on valid dataset versions", "1.2.3.4", datasetVersionRecords.get(0).getVersion());
  }
Test add and get dataset semantic long version with different input.
ambry-account/src/integration-test/java/com/github/ambry/account/MySqlAccountServiceIntegrationTest.java