/**
* the test
* @throws IOException
*/
public void testGet() throws IOException {
MiniDFSCluster cluster = null;
try {
// Initialization
cluster = new MiniDFSCluster(conf, 2, true, (String[])null);
FileSystem fs = cluster.getFileSystem();
Path dir = new Path("/hbase");
fs.mkdirs(dir);
HTableDescriptor desc = new HTableDescriptor("test");
desc.addFamily(new HColumnDescriptor(CONTENTS.toString()));
desc.addFamily(new HColumnDescriptor(HConstants.COLUMN_FAMILY.toString()));
HRegionInfo info = new HRegionInfo(0L, desc, null, null);
Path regionDir = HRegion.getRegionDir(dir, info.regionName);
fs.mkdirs(regionDir);
HLog log = new HLog(fs, new Path(regionDir, "log"), conf);
HRegion r = new HRegion(dir, log, fs, conf, info, null);
// Write information to the table
long lockid = r.startUpdate(ROW_KEY);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream s = new DataOutputStream(bytes);
CONTENTS.write(s);
r.put(lockid, CONTENTS, bytes.toByteArray());
bytes.reset();
HGlobals.rootRegionInfo.write(s);
r.put(lockid, HConstants.COL_REGIONINFO,
Writables.getBytes(HGlobals.rootRegionInfo));
r.commit(lockid, System.currentTimeMillis());
lockid = r.startUpdate(ROW_KEY);
r.put(lockid, HConstants.COL_SERVER,
Writables.stringToBytes(new HServerAddress(SERVER_ADDRESS).toString()));
r.put(lockid, HConstants.COL_STARTCODE, Writables.longToBytes(lockid));
r.put(lockid, new Text(HConstants.COLUMN_FAMILY + "region"),
"region".getBytes(HConstants.UTF8_ENCODING));
r.commit(lockid, System.currentTimeMillis());
// Verify that get works the same from memcache as when reading from disk
// NOTE dumpRegion won't work here because it only reads from disk.
verifyGet(r, SERVER_ADDRESS);
// Close and re-open region, forcing updates to disk
r.close();
log.rollWriter();
r = new HRegion(dir, log, fs, conf, info, null);
// Read it back
verifyGet(r, SERVER_ADDRESS);
// Update one family member and add a new one
lockid = r.startUpdate(ROW_KEY);
r.put(lockid, new Text(HConstants.COLUMN_FAMILY + "region"),
"region2".getBytes(HConstants.UTF8_ENCODING));
String otherServerName = "bar.foo.com:4321";
r.put(lockid, HConstants.COL_SERVER,
Writables.stringToBytes(new HServerAddress(otherServerName).toString()));
r.put(lockid, new Text(HConstants.COLUMN_FAMILY + "junk"),
"junk".getBytes(HConstants.UTF8_ENCODING));
r.commit(lockid, System.currentTimeMillis());
verifyGet(r, otherServerName);
// Close region and re-open it
r.close();
log.rollWriter();
r = new HRegion(dir, log, fs, conf, info, null);
// Read it back
verifyGet(r, otherServerName);
// Close region once and for all
r.close();
log.closeAndDelete();
} finally {
if(cluster != null) {
cluster.shutdown();
}
}
}