You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ec...@apache.org on 2015/12/10 01:03:54 UTC

hbase git commit: HBASE-14851 Add test showing how to use per put TTL from thrift

Repository: hbase
Updated Branches:
  refs/heads/branch-1.2 35cfcab68 -> ddee1ba9c


HBASE-14851 Add test showing how to use per put TTL from thrift


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/ddee1ba9
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/ddee1ba9
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/ddee1ba9

Branch: refs/heads/branch-1.2
Commit: ddee1ba9cc6f588361ffdebffbd98f346d657baf
Parents: 35cfcab
Author: Elliott Clark <ec...@apache.org>
Authored: Thu Nov 19 14:19:00 2015 -0800
Committer: Elliott Clark <ec...@apache.org>
Committed: Wed Dec 9 16:03:47 2015 -0800

----------------------------------------------------------------------
 .../thrift2/TestThriftHBaseServiceHandler.java  | 50 ++++++++++++++++++++
 1 file changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/ddee1ba9/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
----------------------------------------------------------------------
diff --git a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
index 65abb0b..1575429 100644
--- a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
+++ b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
@@ -684,6 +684,56 @@ public class TestThriftHBaseServiceHandler {
     }
   }
 
+  @Test
+  public void testPutTTL() throws Exception {
+    ThriftHBaseServiceHandler handler = createHandler();
+    byte[] rowName = "testPutTTL".getBytes();
+    ByteBuffer table = wrap(tableAname);
+    List<TColumnValue> columnValues = new ArrayList<TColumnValue>();
+
+    // Add some dummy data
+    columnValues.add(
+        new TColumnValue(
+            wrap(familyAname),
+            wrap(qualifierAname),
+            wrap(Bytes.toBytes(1L))));
+
+
+    TPut put = new TPut(wrap(rowName), columnValues);
+    put.setColumnValues(columnValues);
+
+    Map<ByteBuffer, ByteBuffer> attributes = new HashMap<>();
+
+    // Time in ms for the kv's to live.
+    long ttlTimeMs = 2000L;
+
+    // the _ttl attribute is a number of ms ttl for key values in this put.
+    attributes.put(wrap(Bytes.toBytes("_ttl")), wrap(Bytes.toBytes(ttlTimeMs)));
+    // Attach the attributes
+    put.setAttributes(attributes);
+    // Send it.
+    handler.put(table, put);
+
+    // Now get the data back
+    TGet getOne = new TGet(wrap(rowName));
+    TResult resultOne = handler.get(table, getOne);
+
+    // It's there.
+    assertArrayEquals(rowName, resultOne.getRow());
+    assertEquals(1, resultOne.getColumnValuesSize());
+
+    // Sleep 30 seconds just to make 100% sure that the key value should be expired.
+    Thread.sleep(ttlTimeMs * 15);
+
+    TGet getTwo = new TGet(wrap(rowName));
+    TResult resultTwo = handler.get(table, getTwo);
+
+
+    // Nothing should be there since it's ttl'd out.
+    assertNull(resultTwo.getRow());
+    assertEquals(0, resultTwo.getColumnValuesSize());
+  }
+
   /**
    * Padding numbers to make comparison of sort order easier in a for loop
    *