/** The test!
* @throws IOException
*/
public void testScanner() throws IOException {
MiniDFSCluster cluster = null;
FileSystem fs = null;
try {
// Initialization
Configuration conf = new HBaseConfiguration();
cluster = new MiniDFSCluster(conf, 2, true, (String[])null);
fs = cluster.getFileSystem();
Path dir = new Path("/hbase");
fs.mkdirs(dir);
Path regionDir = HRegion.getRegionDir(dir, REGION_INFO.regionName);
fs.mkdirs(regionDir);
HLog log = new HLog(fs, new Path(regionDir, "log"), conf);
region = new HRegion(dir, log, fs, conf, REGION_INFO, null);
// Write information to the meta table
long lockid = region.startUpdate(ROW_KEY);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
DataOutputStream s = new DataOutputStream(byteStream);
HGlobals.rootRegionInfo.write(s);
region.put(lockid, HConstants.COL_REGIONINFO, byteStream.toByteArray());
region.commit(lockid, System.currentTimeMillis());
// What we just committed is in the memcache. Verify that we can get
// it back both with scanning and get
scan(false, null);
getRegionInfo();
// Close and re-open
region.close();
log.rollWriter();
region = new HRegion(dir, log, fs, conf, REGION_INFO, null);
// Verify we can get the data back now that it is on disk.
scan(false, null);
getRegionInfo();
// Store some new information
HServerAddress address = new HServerAddress("foo.bar.com:1234");
lockid = region.startUpdate(ROW_KEY);
region.put(lockid, HConstants.COL_SERVER,
Writables.stringToBytes(address.toString()));
region.put(lockid, HConstants.COL_STARTCODE,
Writables.longToBytes(START_CODE));
region.commit(lockid, System.currentTimeMillis());
// Validate that we can still get the HRegionInfo, even though it is in
// an older row on disk and there is a newer row in the memcache
scan(true, address.toString());
getRegionInfo();
// flush cache
region.flushcache(false);
// Validate again
scan(true, address.toString());
getRegionInfo();
// Close and reopen
region.close();
log.rollWriter();
region = new HRegion(dir, log, fs, conf, REGION_INFO, null);
// Validate again
scan(true, address.toString());
getRegionInfo();
// Now update the information again
address = new HServerAddress("bar.foo.com:4321");
lockid = region.startUpdate(ROW_KEY);
region.put(lockid, HConstants.COL_SERVER,
Writables.stringToBytes(address.toString()));
region.commit(lockid, System.currentTimeMillis());
// Validate again
scan(true, address.toString());
getRegionInfo();
// flush cache
region.flushcache(false);
// Validate again
scan(true, address.toString());
getRegionInfo();
// Close and reopen
region.close();
log.rollWriter();
region = new HRegion(dir, log, fs, conf, REGION_INFO, null);
// Validate again
scan(true, address.toString());
getRegionInfo();
// clean up
region.close();
log.closeAndDelete();
} finally {
if(cluster != null) {
cluster.shutdown();
}
}
}