hcd.setMaxVersions(3);
desc.addFamily(hcd);
this.admin.createTable(desc);
Put put = new Put(row, timestamp1);
put.add(contents, contents, value1);
Table table = new HTable(UTIL.getConfiguration(), tableName);
table.put(put);
// Shut down and restart the HBase cluster
table.close();
UTIL.shutdownMiniHBaseCluster();
LOG.debug("HBase cluster shut down -- restarting");
UTIL.startMiniHBaseCluster(1, NUM_SLAVES);
// Make a new connection. Use new Configuration instance because old one
// is tied to an HConnection that has since gone stale.
table = new HTable(new Configuration(UTIL.getConfiguration()), tableName);
// Overwrite previous value
put = new Put(row, timestamp2);
put.add(contents, contents, value2);
table.put(put);
// Now verify that getRow(row, column, latest) works
Get get = new Get(row);
// Should get one version by default
Result r = table.get(get);
assertNotNull(r);
assertFalse(r.isEmpty());
assertTrue(r.size() == 1);
byte [] value = r.getValue(contents, contents);
assertTrue(value.length != 0);
assertTrue(Bytes.equals(value, value2));
// Now check getRow with multiple versions
get = new Get(row);
get.setMaxVersions();
r = table.get(get);
assertTrue(r.size() == 2);
value = r.getValue(contents, contents);
assertTrue(value.length != 0);
assertTrue(Bytes.equals(value, value2));
NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> map =
r.getMap();
NavigableMap<byte[], NavigableMap<Long, byte[]>> familyMap =
map.get(contents);
NavigableMap<Long, byte[]> versionMap = familyMap.get(contents);
assertTrue(versionMap.size() == 2);
assertTrue(Bytes.equals(value1, versionMap.get(timestamp1)));
assertTrue(Bytes.equals(value2, versionMap.get(timestamp2)));
table.close();
}