}
/** The test! */
@SuppressWarnings("unchecked")
public void testScanner() throws IOException {
MiniDFSCluster cluster = null;
FileSystem fs = null;
try {
// Initialization
if(System.getProperty("test.build.data") == null) {
String dir = new File(new File("").getAbsolutePath(), "build/contrib/hbase/test").getAbsolutePath();
System.out.println(dir);
System.setProperty("test.build.data", dir);
}
Configuration conf = new HBaseConfiguration();
Environment.getenv();
if(Environment.debugging) {
Logger rootLogger = Logger.getRootLogger();
rootLogger.setLevel(Level.WARN);
ConsoleAppender consoleAppender = null;
for(Enumeration<Appender> e = (Enumeration<Appender>)rootLogger.getAllAppenders();
e.hasMoreElements();) {
Appender a = e.nextElement();
if(a instanceof ConsoleAppender) {
consoleAppender = (ConsoleAppender)a;
break;
}
}
if(consoleAppender != null) {
Layout layout = consoleAppender.getLayout();
if(layout instanceof PatternLayout) {
PatternLayout consoleLayout = (PatternLayout)layout;
consoleLayout.setConversionPattern("%d %-5p [%t] %l: %m%n");
}
}
Logger.getLogger("org.apache.hadoop.hbase").setLevel(Environment.logLevel);
}
cluster = new MiniDFSCluster(conf, 2, true, (String[])null);
fs = cluster.getFileSystem();
Path dir = new Path("/hbase");
fs.mkdirs(dir);
Path regionDir = HStoreFile.getHRegionDir(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, 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,
new BytesWritable(byteStream.toByteArray()));
region.commit(lockid);
// 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, 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,
new BytesWritable(address.toString().getBytes(HConstants.UTF8_ENCODING)));
region.put(lockid, HConstants.COL_STARTCODE,
new BytesWritable(
String.valueOf(START_CODE).getBytes(HConstants.UTF8_ENCODING)));
region.commit(lockid);
// 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, 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,
new BytesWritable(address.toString().getBytes(HConstants.UTF8_ENCODING)));
region.commit(lockid);
// 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, null);
// Validate again
scan(true, address.toString());
getRegionInfo();
} catch(IOException e) {
e.printStackTrace();
throw e;
} finally {
if(fs != null) {
fs.close();
}
if(cluster != null) {
cluster.shutdown();
}
}
}