@Test public void testVersions() throws Exception {
  byte[] TABLE=Bytes.toBytes("testVersions");
  long[] STAMPS=makeStamps(20);
  byte[][] VALUES=makeNAscii(VALUE,20);
  HTable ht=TEST_UTIL.createTable(TABLE,FAMILY,10);
  Put put=new Put(ROW);
  put.add(FAMILY,QUALIFIER,STAMPS[1],VALUES[1]);
  put.add(FAMILY,QUALIFIER,STAMPS[2],VALUES[2]);
  put.add(FAMILY,QUALIFIER,STAMPS[4],VALUES[4]);
  put.add(FAMILY,QUALIFIER,STAMPS[5],VALUES[5]);
  ht.put(put);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[1],VALUES[1]);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[2],VALUES[2]);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[4],VALUES[4]);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[5],VALUES[5]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[1],VALUES[1]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[2],VALUES[2]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[4],VALUES[4]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[5],VALUES[5]);
  getVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[0]);
  getVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[3]);
  getVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[6]);
  scanVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[0]);
  scanVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[3]);
  scanVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[6]);
  Get get=new Get(ROW);
  get.addColumn(FAMILY,QUALIFIER);
  get.setMaxVersions(2);
  Result result=ht.get(get);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[4],STAMPS[5]},new byte[][]{VALUES[4],VALUES[5]},0,1);
  Scan scan=new Scan(ROW);
  scan.addColumn(FAMILY,QUALIFIER);
  scan.setMaxVersions(2);
  result=getSingleScanResult(ht,scan);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[4],STAMPS[5]},new byte[][]{VALUES[4],VALUES[5]},0,1);
  TEST_UTIL.flush();
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[1],VALUES[1]);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[2],VALUES[2]);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[4],VALUES[4]);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[5],VALUES[5]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[1],VALUES[1]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[2],VALUES[2]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[4],VALUES[4]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[5],VALUES[5]);
  getVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[0]);
  getVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[3]);
  getVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[6]);
  scanVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[0]);
  scanVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[3]);
  scanVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[6]);
  get=new Get(ROW);
  get.addColumn(FAMILY,QUALIFIER);
  get.setMaxVersions(2);
  result=ht.get(get);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[4],STAMPS[5]},new byte[][]{VALUES[4],VALUES[5]},0,1);
  scan=new Scan(ROW);
  scan.addColumn(FAMILY,QUALIFIER);
  scan.setMaxVersions(2);
  result=getSingleScanResult(ht,scan);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[4],STAMPS[5]},new byte[][]{VALUES[4],VALUES[5]},0,1);
  put=new Put(ROW);
  put.add(FAMILY,QUALIFIER,STAMPS[3],VALUES[3]);
  put.add(FAMILY,QUALIFIER,STAMPS[6],VALUES[6]);
  put.add(FAMILY,QUALIFIER,STAMPS[7],VALUES[7]);
  put.add(FAMILY,QUALIFIER,STAMPS[8],VALUES[8]);
  ht.put(put);
  get=new Get(ROW);
  get.addColumn(FAMILY,QUALIFIER);
  get.setMaxVersions();
  result=ht.get(get);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[1],STAMPS[2],STAMPS[3],STAMPS[4],STAMPS[5],STAMPS[6],STAMPS[7],STAMPS[8]},new byte[][]{VALUES[1],VALUES[2],VALUES[3],VALUES[4],VALUES[5],VALUES[6],VALUES[7],VALUES[8]},0,7);
  scan=new Scan(ROW);
  scan.addColumn(FAMILY,QUALIFIER);
  scan.setMaxVersions();
  result=getSingleScanResult(ht,scan);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[1],STAMPS[2],STAMPS[3],STAMPS[4],STAMPS[5],STAMPS[6],STAMPS[7],STAMPS[8]},new byte[][]{VALUES[1],VALUES[2],VALUES[3],VALUES[4],VALUES[5],VALUES[6],VALUES[7],VALUES[8]},0,7);
  get=new Get(ROW);
  get.setMaxVersions();
  result=ht.get(get);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[1],STAMPS[2],STAMPS[3],STAMPS[4],STAMPS[5],STAMPS[6],STAMPS[7],STAMPS[8]},new byte[][]{VALUES[1],VALUES[2],VALUES[3],VALUES[4],VALUES[5],VALUES[6],VALUES[7],VALUES[8]},0,7);
  scan=new Scan(ROW);
  scan.setMaxVersions();
  result=getSingleScanResult(ht,scan);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[1],STAMPS[2],STAMPS[3],STAMPS[4],STAMPS[5],STAMPS[6],STAMPS[7],STAMPS[8]},new byte[][]{VALUES[1],VALUES[2],VALUES[3],VALUES[4],VALUES[5],VALUES[6],VALUES[7],VALUES[8]},0,7);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[1],VALUES[1]);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[2],VALUES[2]);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[4],VALUES[4]);
  getVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[7],VALUES[7]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[1],VALUES[1]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[2],VALUES[2]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[4],VALUES[4]);
  scanVersionAndVerify(ht,ROW,FAMILY,QUALIFIER,STAMPS[7],VALUES[7]);
  getVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[0]);
  getVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[9]);
  scanVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[0]);
  scanVersionAndVerifyMissing(ht,ROW,FAMILY,QUALIFIER,STAMPS[9]);
  TEST_UTIL.flush();
  put=new Put(ROW);
  put.add(FAMILY,QUALIFIER,STAMPS[9],VALUES[9]);
  put.add(FAMILY,QUALIFIER,STAMPS[11],VALUES[11]);
  put.add(FAMILY,QUALIFIER,STAMPS[13],VALUES[13]);
  put.add(FAMILY,QUALIFIER,STAMPS[15],VALUES[15]);
  ht.put(put);
  get=new Get(ROW);
  get.addColumn(FAMILY,QUALIFIER);
  get.setMaxVersions(Integer.MAX_VALUE);
  result=ht.get(get);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[3],STAMPS[4],STAMPS[5],STAMPS[6],STAMPS[7],STAMPS[8],STAMPS[9],STAMPS[11],STAMPS[13],STAMPS[15]},new byte[][]{VALUES[3],VALUES[4],VALUES[5],VALUES[6],VALUES[7],VALUES[8],VALUES[9],VALUES[11],VALUES[13],VALUES[15]},0,9);
  scan=new Scan(ROW);
  scan.addColumn(FAMILY,QUALIFIER);
  scan.setMaxVersions(Integer.MAX_VALUE);
  result=getSingleScanResult(ht,scan);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[3],STAMPS[4],STAMPS[5],STAMPS[6],STAMPS[7],STAMPS[8],STAMPS[9],STAMPS[11],STAMPS[13],STAMPS[15]},new byte[][]{VALUES[3],VALUES[4],VALUES[5],VALUES[6],VALUES[7],VALUES[8],VALUES[9],VALUES[11],VALUES[13],VALUES[15]},0,9);
  Delete delete=new Delete(ROW);
  delete.deleteColumn(FAMILY,QUALIFIER,STAMPS[11]);
  delete.deleteColumn(FAMILY,QUALIFIER,STAMPS[7]);
  ht.delete(delete);
  get=new Get(ROW);
  get.addColumn(FAMILY,QUALIFIER);
  get.setMaxVersions(Integer.MAX_VALUE);
  result=ht.get(get);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[1],STAMPS[2],STAMPS[3],STAMPS[4],STAMPS[5],STAMPS[6],STAMPS[8],STAMPS[9],STAMPS[13],STAMPS[15]},new byte[][]{VALUES[1],VALUES[2],VALUES[3],VALUES[4],VALUES[5],VALUES[6],VALUES[8],VALUES[9],VALUES[13],VALUES[15]},0,9);
  scan=new Scan(ROW);
  scan.addColumn(FAMILY,QUALIFIER);
  scan.setMaxVersions(Integer.MAX_VALUE);
  result=getSingleScanResult(ht,scan);
  assertNResult(result,ROW,FAMILY,QUALIFIER,new long[]{STAMPS[1],STAMPS[2],STAMPS[3],STAMPS[4],STAMPS[5],STAMPS[6],STAMPS[8],STAMPS[9],STAMPS[13],STAMPS[15]},new byte[][]{VALUES[1],VALUES[2],VALUES[3],VALUES[4],VALUES[5],VALUES[6],VALUES[8],VALUES[9],VALUES[13],VALUES[15]},0,9);
}
