HBASE-11877 Make TableSplit more readable (Liu Shaohui)

This commit is contained in:
stack 2014-09-04 21:25:54 -07:00
parent 8de30d32d4
commit aa05ad1291
4 changed files with 53 additions and 4 deletions

View File

@ -119,8 +119,14 @@ public class TableSplit implements InputSplit, Comparable<TableSplit> {
@Override
public String toString() {
return m_regionLocation + ":" +
Bytes.toStringBinary(m_startRow) + "," + Bytes.toStringBinary(m_endRow);
StringBuilder sb = new StringBuilder();
sb.append("HBase table split(");
sb.append("table name: ").append(m_tableName);
sb.append(", start row: ").append(Bytes.toStringBinary(m_startRow));
sb.append(", end row: ").append(Bytes.toStringBinary(m_endRow));
sb.append(", region location: ").append(m_regionLocation);
sb.append(")");
return sb.toString();
}
@Override

View File

@ -314,8 +314,15 @@ implements Writable, Comparable<TableSplit> {
*/
@Override
public String toString() {
return regionLocation + ":" +
Bytes.toStringBinary(startRow) + "," + Bytes.toStringBinary(endRow);
StringBuilder sb = new StringBuilder();
sb.append("HBase table split(");
sb.append("table name: ").append(tableName);
sb.append(", scan: ").append(scan);
sb.append(", start row: ").append(Bytes.toStringBinary(startRow));
sb.append(", end row: ").append(Bytes.toStringBinary(endRow));
sb.append(", region location: ").append(regionLocation);
sb.append(")");
return sb.toString();
}
/**

View File

@ -23,7 +23,9 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.hbase.SmallTests;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@ -88,4 +90,22 @@ public class TestSplitTable {
assertEquals(tablesplit.hashCode(), same.hashCode());
assertEquals(tablesplit, same);
}
@Test
@SuppressWarnings("deprecation")
public void testToString() {
TableSplit split =
new TableSplit(TableName.valueOf("table"), "row-start".getBytes(), "row-end".getBytes(),
"location");
String str =
"HBase table split(table name: table, start row: row-start, "
+ "end row: row-end, region location: location)";
Assert.assertEquals(str, split.toString());
split = new TableSplit((TableName) null, null, null, null);
str =
"HBase table split(table name: null, start row: null, "
+ "end row: null, region location: null)";
Assert.assertEquals(str, split.toString());
}
}

View File

@ -85,5 +85,21 @@ public class TestTableSplit {
Assert.assertEquals(666, deserialized.getLength());
}
@Test
public void testToString() {
TableSplit split =
new TableSplit(TableName.valueOf("table"), "row-start".getBytes(), "row-end".getBytes(),
"location");
String str =
"HBase table split(table name: table, scan: , start row: row-start, "
+ "end row: row-end, region location: location)";
Assert.assertEquals(str, split.toString());
split = new TableSplit((TableName) null, null, null, null);
str =
"HBase table split(table name: null, scan: , start row: null, "
+ "end row: null, region location: null)";
Assert.assertEquals(str, split.toString());
}
}