Index: src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java (revision 1508966) +++ src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java (working copy) @@ -19,14 +19,18 @@ */ package org.apache.hadoop.hbase.client; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.io.IOException; import java.util.ArrayList; import java.util.Random; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HRegionLocation; @@ -90,6 +94,72 @@ // Nothing to do. } + @Test + public void testAppend() throws IOException { + byte [] rowKey = Bytes.toBytes("mytestRowKey"); + byte [] column1 = Bytes.toBytes("ulbytes"); + byte [] column2 = Bytes.toBytes("dlbytes"); + byte [] column3 = Bytes.toBytes("tbytes"); + String part11 = "one two"; + String part12 = " three"; + String cFamily = "TestA"; + String TABLE = "mytesttable"; + Configuration conf = TEST_UTIL.getConfiguration(); + + HTablePool pool = new HTablePool(conf, 10); + HBaseAdmin admin = new HBaseAdmin(conf); + + if(admin.tableExists(TABLE)){ + admin.disableTable(TABLE); + admin.deleteTable(TABLE); + } + + HTableDescriptor tableDescriptor = new HTableDescriptor(TABLE); + HColumnDescriptor hcd = new HColumnDescriptor(cFamily); + hcd.setMaxVersions(1); + tableDescriptor.addFamily(hcd); + admin.createTable(tableDescriptor); + + HTableInterface table = pool.getTable(TABLE); + + Append a = new Append(rowKey); + a.setReturnResults(false); + a.add(Bytes.toBytes(cFamily), column1, Bytes.toBytes(part11)); + a.add(Bytes.toBytes(cFamily), column2, Bytes.toBytes(part11)); + a.add(Bytes.toBytes(cFamily), column3, Bytes.toBytes(part11)); + table.append(a); + a = new Append(rowKey); + a.add(Bytes.toBytes(cFamily), column1, Bytes.toBytes(part12)); + a.add(Bytes.toBytes(cFamily), column2, Bytes.toBytes(part12)); + a.add(Bytes.toBytes(cFamily), column3, Bytes.toBytes(part12)); + Result result = table.append(a); + + byte [] resultForColumn1 = result.getValue(Bytes.toBytes(cFamily), column1); + byte [] resultForColumn2 = result.getValue(Bytes.toBytes(cFamily), column2); + byte [] resultForColumn3 = result.getValue(Bytes.toBytes(cFamily), column3); + if (resultForColumn1 == null || resultForColumn2 == null || resultForColumn3 == null) + System.out.println("The DB table contains these values but they are never given back, ..."); + else { + assertEquals(0, Bytes.compareTo(Bytes.toBytes(part11 + part12), + resultForColumn1)); + assertEquals(0, Bytes.compareTo(Bytes.toBytes(part11 + part12), + resultForColumn2)); + assertEquals(0, Bytes.compareTo(Bytes.toBytes(part11 + part12), + resultForColumn3)); + } + HTable t = new HTable(conf, TABLE); + Get getOperation = new Get(rowKey); + getOperation.addColumn(Bytes.toBytes(cFamily), column1); + Result res = t.get(getOperation); + byte[] b1 = Bytes.toBytes(part11 + part12); + byte[] b2 = res.getValue(Bytes.toBytes(cFamily), column1); + assertEquals(0, Bytes.compareTo(b1, b2)); + + pool.close(); + admin.close(); + t.close(); + } + private void randomCFPuts(HTable table, byte[] row, byte[] family, int nPuts) throws Exception { Put put = new Put(row); Index: src/main/java/org/apache/hadoop/hbase/client/Append.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/Append.java (revision 1508966) +++ src/main/java/org/apache/hadoop/hbase/client/Append.java (working copy) @@ -88,7 +88,13 @@ if(list == null) { list = new ArrayList(); } - list.add(new KeyValue( + // find where the new entry should be placed in the List + int idx = 0; + for (KeyValue kv : list) { + if (Bytes.compareTo(qualifier, kv.getQualifier()) < 0) break; + idx ++; + } + list.add(idx, new KeyValue( this.row, family, qualifier, this.ts, KeyValue.Type.Put, value)); familyMap.put(family, list); return this;