@Test
  public void deleteLifeVersionTest() throws StoreException {
    short lifeVersion = 2;
    MockId addedId = put(1, PUT_RECORD_SIZE, Utils.Infinite_Time, Utils.getRandomShort(TestUtils.RANDOM),
        Utils.getRandomShort(TestUtils.RANDOM), lifeVersion).get(0);

    MessageInfo info = new MessageInfo(addedId, DELETE_RECORD_SIZE, true, false, false, Utils.Infinite_Time, null,
        addedId.getAccountId(), addedId.getContainerId(), time.milliseconds(), (short) (lifeVersion - 1));
    try {
      store.delete(Collections.singletonList(info));
      fail("Should not delete");
    } catch (StoreException e) {
      assertEquals(e.getErrorCode(), StoreErrorCodes.LifeVersionConflict);
    }

    info = new MessageInfo(addedId, DELETE_RECORD_SIZE, true, false, false, Utils.Infinite_Time, null,
        addedId.getAccountId(), addedId.getContainerId(), time.milliseconds(), lifeVersion);
    store.delete(Collections.singletonList(info));
    deletedKeys.add(addedId);
    undeletedKeys.remove(addedId);
    liveKeys.remove(addedId);
    StoreInfo storeInfo = store.get(Arrays.asList(addedId), EnumSet.of(StoreGetOptions.Store_Include_Deleted));
    assertEquals(1, storeInfo.getMessageReadSetInfo().size());
    assertEquals(lifeVersion, storeInfo.getMessageReadSetInfo().get(0).getLifeVersion());
    assertTrue(storeInfo.getMessageReadSetInfo().get(0).isDeleted());
    assertFalse(storeInfo.getMessageReadSetInfo().get(0).isUndeleted());

    // delete with the same lifeVersion, should fail with life_version_conflict
    info = new MessageInfo(addedId, DELETE_RECORD_SIZE, true, false, false, Utils.Infinite_Time, null,
        addedId.getAccountId(), addedId.getContainerId(), time.milliseconds(), lifeVersion);
    try {
      store.delete(Collections.singletonList(info));
      fail("Should not delete");
    } catch (StoreException e) {
      assertEquals(e.getErrorCode(), StoreErrorCodes.IDDeleted);
    }

    // delete with the smaller lifeVersion, should fail with life_version_conflict
    info = new MessageInfo(addedId, DELETE_RECORD_SIZE, true, false, false, Utils.Infinite_Time, null,
        addedId.getAccountId(), addedId.getContainerId(), time.milliseconds(), (short) 0);
    try {
      store.delete(Collections.singletonList(info));
      fail("Should not delete");
    } catch (StoreException e) {
      assertEquals(e.getErrorCode(), StoreErrorCodes.LifeVersionConflict);
    }

    // delete with larger lifeVersion, should succeed.
    info = new MessageInfo(addedId, DELETE_RECORD_SIZE, true, false, false, Utils.Infinite_Time, null,
        addedId.getAccountId(), addedId.getContainerId(), time.milliseconds(), (short) (lifeVersion + 1));
    store.delete(Collections.singletonList(info));
    storeInfo = store.get(Arrays.asList(addedId), EnumSet.of(StoreGetOptions.Store_Include_Deleted));
    assertEquals(1, storeInfo.getMessageReadSetInfo().size());
    assertEquals((short) (lifeVersion + 1), storeInfo.getMessageReadSetInfo().get(0).getLifeVersion());
    assertTrue(storeInfo.getMessageReadSetInfo().get(0).isDeleted());
    assertFalse(storeInfo.getMessageReadSetInfo().get(0).isUndeleted());

    // Add a new put
    addedId = put(1, PUT_RECORD_SIZE, Utils.Infinite_Time, Utils.getRandomShort(TestUtils.RANDOM),
        Utils.getRandomShort(TestUtils.RANDOM), lifeVersion).get(0);
    info = new MessageInfo(addedId, DELETE_RECORD_SIZE, true, false, false, Utils.Infinite_Time, null,
        addedId.getAccountId(), addedId.getContainerId(), time.milliseconds(), MessageInfo.LIFE_VERSION_FROM_FRONTEND);
    store.delete(Collections.singletonList(info));
    deletedKeys.add(addedId);
    undeletedKeys.remove(addedId);
    liveKeys.remove(addedId);
    storeInfo = store.get(Arrays.asList(addedId), EnumSet.of(StoreGetOptions.Store_Include_Deleted));
    assertEquals(1, storeInfo.getMessageReadSetInfo().size());
    assertEquals(lifeVersion, storeInfo.getMessageReadSetInfo().get(0).getLifeVersion());
    assertTrue(storeInfo.getMessageReadSetInfo().get(0).isDeleted());
    assertFalse(storeInfo.getMessageReadSetInfo().get(0).isUndeleted());
  }
Tests when lifeVersion for delete is not -1.
@throws StoreException
ambry-store/src/test/java/com/github/ambry/store/BlobStoreTest.java