TABLE_NAME,
INPUT_FILE
};
MiniHBaseCluster cluster = null;
MiniZooKeeperCluster zkCluster = null;
FileSystem fs = null;
try {
// using the restart method allows us to avoid having the hbase
// root directory overwritten by /home/$username
zkCluster = testUtil.startMiniZKCluster();
testUtil.restartHBaseCluster(2);
cluster = testUtil.getMiniHBaseCluster();
GenericOptionsParser opts =
new GenericOptionsParser(cluster.getConfiguration(), args);
Configuration conf = opts.getConfiguration();
args = opts.getRemainingArgs();
fs = FileSystem.get(conf);
FSDataOutputStream op = fs.create(new Path(INPUT_FILE), true);
String line1 = "0001,0002\n";
String line2 = "0002,0004\n";
String line3 = "0003,0005\n";
String line4 = "0004,-1\n";
String line5 = "0005,-1\n";
op.write(line1.getBytes());
op.write(line2.getBytes());
op.write(line3.getBytes());
op.write(line4.getBytes());
op.write(line5.getBytes());
op.close();
final byte[] FAM = Bytes.toBytes(FAMILY);
final byte[] TAB = Bytes.toBytes(TABLE_NAME);
HTableDescriptor desc = new HTableDescriptor(TAB);
desc.addFamily(new HColumnDescriptor(FAM));
HBaseAdmin hbaseAdmin=new HBaseAdmin(conf);
if (hbaseAdmin.isTableAvailable(TABLE_NAME)) {
hbaseAdmin.disableTable(TABLE_NAME);
hbaseAdmin.deleteTable(TABLE_NAME);
}
hbaseAdmin.createTable(desc);
Job job = ImportTsv.createSubmittableJob(conf, args);
job.waitForCompletion(false);
assertTrue(job.isSuccessful());
if(log.isInfoEnabled())
log.info("ImportTsv successful. Running HBase Giraph job.");
//now operate over HBase using Vertex I/O formats
conf.set(TableInputFormat.INPUT_TABLE, TABLE_NAME);
conf.set(TableOutputFormat.OUTPUT_TABLE, TABLE_NAME);
GiraphJob giraphJob = new GiraphJob(conf, BspCase.getCallingMethodName());
GiraphConfiguration giraphConf = giraphJob.getConfiguration();
giraphConf.setZooKeeperConfiguration(
cluster.getMaster().getZooKeeper().getQuorum());
setupConfiguration(giraphJob);
giraphConf.setVertexClass(EdgeNotification.class);
giraphConf.setVertexInputFormatClass(TableEdgeInputFormat.class);
giraphConf.setVertexOutputFormatClass(TableEdgeOutputFormat.class);
assertTrue(giraphJob.run(true));
if(log.isInfoEnabled())
log.info("Giraph job successful. Checking output qualifier.");
//Do a get on row 0002, it should have a parent of 0001
//if the outputFormat worked.
HTable table = new HTable(conf, TABLE_NAME);
Result result = table.get(new Get("0002".getBytes()));
byte[] parentBytes = result.getValue(FAMILY.getBytes(),
OUTPUT_FIELD.getBytes());
assertNotNull(parentBytes);
assertTrue(parentBytes.length > 0);
Assert.assertEquals("0001", Bytes.toString(parentBytes));
} finally {
if (cluster != null) {
cluster.shutdown();
}
if (zkCluster != null) {
zkCluster.shutdown();
}
// clean test files
if (fs != null) {
fs.delete(hbaseRootdir);
}