Skip to content

Commit 1012ee5

Browse files
committed
Test maxRecentVersions
1 parent 7ad8aab commit 1012ee5

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/test/java/com/google/cloud/anviltop/hbase/TestGet.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,54 @@ public void testSingleTimestamp() throws IOException {
204204
table.close();
205205
}
206206

207+
/**
208+
* Requirement 3.6 - Client can request a maximum # of most recent versions returned.
209+
*/
210+
@Test
211+
public void testMaxVersions() throws IOException {
212+
HTableInterface table = connection.getTable(TABLE_NAME);
213+
byte[] rowKey = Bytes.toBytes("testrow-" + RandomStringUtils.random(8));
214+
byte[] qual = Bytes.toBytes("qual-" + RandomStringUtils.random(8));
215+
long timestamp1 = System.currentTimeMillis();
216+
long timestamp2 = timestamp1 + 1;
217+
long timestamp3 = timestamp2 + 1;
218+
long timestamp4 = timestamp3 + 1;
219+
long timestamp5 = timestamp4 + 1;
220+
byte[] value1 = Bytes.toBytes("value-" + RandomStringUtils.random(8));
221+
byte[] value2 = Bytes.toBytes("value-" + RandomStringUtils.random(8));
222+
byte[] value3 = Bytes.toBytes("value-" + RandomStringUtils.random(8));
223+
byte[] value4 = Bytes.toBytes("value-" + RandomStringUtils.random(8));
224+
byte[] value5 = Bytes.toBytes("value-" + RandomStringUtils.random(8));
225+
226+
Put put = new Put(rowKey);
227+
put.add(COLUMN_FAMILY, qual, timestamp1, value1);
228+
put.add(COLUMN_FAMILY, qual, timestamp2, value2);
229+
put.add(COLUMN_FAMILY, qual, timestamp3, value3);
230+
put.add(COLUMN_FAMILY, qual, timestamp4, value4);
231+
put.add(COLUMN_FAMILY, qual, timestamp5, value5);
232+
table.put(put);
233+
234+
Get get = new Get(rowKey);
235+
get.addColumn(COLUMN_FAMILY, qual);
236+
get.setMaxVersions(3);
237+
Result result = table.get(get);
238+
239+
Assert.assertEquals(3, result.size());
240+
Assert.assertTrue(result.containsColumn(COLUMN_FAMILY, qual));
241+
List<Cell> cells = result.getColumnCells(COLUMN_FAMILY, qual);
242+
Assert.assertEquals(3, cells.size());
243+
244+
// Cells return in descending order
245+
Assert.assertEquals(timestamp5, cells.get(0).getTimestamp());
246+
Assert.assertArrayEquals(value5, CellUtil.cloneValue(cells.get(0)));
247+
Assert.assertEquals(timestamp4, cells.get(1).getTimestamp());
248+
Assert.assertArrayEquals(value4, CellUtil.cloneValue(cells.get(1)));
249+
Assert.assertEquals(timestamp3, cells.get(2).getTimestamp());
250+
Assert.assertArrayEquals(value3, CellUtil.cloneValue(cells.get(2)));
251+
252+
Delete delete = new Delete(rowKey);
253+
table.delete(delete);
254+
255+
table.close();
256+
}
207257
}

0 commit comments

Comments
 (0)