HBASE-10600 HTable#batch() should perform validation on empty Put

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1571899 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2014-02-26 02:44:31 +00:00
parent 31b8b2d92b
commit d77ef9a8b5
2 changed files with 30 additions and 0 deletions

View File

@ -481,6 +481,12 @@ class AsyncProcess {
NonceGenerator ng = this.hConnection.getNonceGenerator();
for (Row r : rows) {
posInList++;
if (r instanceof Put) {
Put put = (Put) r;
if (put.isEmpty()) {
throw new IllegalArgumentException("No columns to insert for #" + (posInList+1)+ " item");
}
}
Action<Row> action = new Action<Row>(r, posInList);
setNonce(ng, r, action);
actions.add(action);

View File

@ -267,6 +267,30 @@ public class TestFromClientSide3 {
"hbase.hstore.compaction.min"));
}
@Test
public void testHTableBatchWithEmptyPut() throws Exception {
HTable table = TEST_UTIL.createTable(
Bytes.toBytes("testHTableBatchWithEmptyPut"), new byte[][] { FAMILY });
try {
List actions = (List) new ArrayList();
Object[] results = new Object[2];
// create an empty Put
Put put1 = new Put(ROW);
actions.add(put1);
Put put2 = new Put(ANOTHERROW);
put2.add(FAMILY, QUALIFIER, VALUE);
actions.add(put2);
table.batch(actions, results);
fail("Empty Put should have failed the batch call");
} catch (IllegalArgumentException iae) {
} finally {
table.close();
}
}
@Test
public void testHTableExistsMethodSingleRegionSingleGet() throws Exception {