@Test
public void testTsvParseAttributesKey() throws BadTsvLineException {
TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a,HBASE_TS_KEY,HBASE_ATTRIBUTES_KEY", "\t");
assertEquals(0, parser.getRowKeyColumnIndex());
byte[] line = Bytes.toBytes("rowkey\tval_a\t1234\tkey=>value");
ParsedLine parse = parser.parse(line, line.length);
assertEquals(18, parse.getAttributeKeyOffset());
assertEquals(3, parser.getAttributesKeyColumnIndex());
String attributes[] = parse.getIndividualAttributes();
assertEquals(attributes[0], "key=>value");
try {
line = Bytes.toBytes("rowkey\tval_a\t1234");
parser.parse(line, line.length);
fail("Should get BadTsvLineException on empty rowkey.");
} catch (BadTsvLineException b) {
}
parser = new TsvParser("HBASE_ATTRIBUTES_KEY,col_a,HBASE_ROW_KEY,HBASE_TS_KEY", "\t");
assertEquals(2, parser.getRowKeyColumnIndex());
line = Bytes.toBytes("key=>value\tval_a\trowkey\t1234");
parse = parser.parse(line, line.length);
assertEquals(0, parse.getAttributeKeyOffset());
assertEquals(0, parser.getAttributesKeyColumnIndex());
attributes = parse.getIndividualAttributes();
assertEquals(attributes[0], "key=>value");
try {
line = Bytes.toBytes("val_a");
ParsedLine parse2 = parser.parse(line, line.length);
fail("Should get BadTsvLineException when number of columns less than rowkey position.");
} catch (BadTsvLineException b) {
}
parser = new TsvParser("col_a,HBASE_ATTRIBUTES_KEY,HBASE_TS_KEY,HBASE_ROW_KEY", "\t");