@Test
  public void testWithMinVersions() throws Exception {
    TableDescriptor htd = hbu.createTableDescriptor(TableName.valueOf(name.getMethodName()), 3,
      1000, 1, KeepDeletedCells.TRUE);
    HRegion region = hbu.createLocalHRegion(htd, null, null);

    long ts = EnvironmentEdgeManager.currentTime() - 2000; // 2s in the past

    Put p = new Put(T1, ts);
    p.addColumn(c0, c0, T3);
    region.put(p);
    p = new Put(T1, ts - 1);
    p.addColumn(c0, c0, T2);
    region.put(p);
    p = new Put(T1, ts - 3);
    p.addColumn(c0, c0, T1);
    region.put(p);
    p = new Put(T1, ts - 4);
    p.addColumn(c0, c0, T0);
    region.put(p);

    // all puts now are just retained because of min versions = 3

    // place a family delete marker
    Delete d = new Delete(T1, ts - 1);
    region.delete(d);
    // and a column delete marker
    d = new Delete(T1, ts - 2);
    d.addColumns(c0, c0, ts - 1);
    region.delete(d);

    Get g = new Get(T1);
    g.readAllVersions();
    g.setTimeRange(0L, ts - 2);
    Result r = region.get(g);
    checkResult(r, c0, c0, T1, T0);

    // 3 families, one column delete marker
    assertEquals(4, countDeleteMarkers(region));

    region.flush(true);
    // no delete marker removes by the flush
    assertEquals(4, countDeleteMarkers(region));

    r = region.get(g);
    checkResult(r, c0, c0, T1);
    p = new Put(T1, ts + 1);
    p.addColumn(c0, c0, T4);
    region.put(p);
    region.flush(true);

    assertEquals(4, countDeleteMarkers(region));

    r = region.get(g);
    checkResult(r, c0, c0, T1);

    // this will push out the last put before
    // family delete marker
    p = new Put(T1, ts + 2);
    p.addColumn(c0, c0, T5);
    region.put(p);

    region.flush(true);
    region.compact(true);
    // the two family markers without puts are gone
    assertEquals(2, countDeleteMarkers(region));

    // the last compactStores updated the earliestPutTs,
    // so after the next compaction the last family delete marker is also gone
    region.compact(true);
    assertEquals(0, countDeleteMarkers(region));

    HBaseTestingUtil.closeRegionAndWAL(region);
  }
Test keeping deleted rows together with min versions set
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeepDeletes.java