本文整理汇总了Java中org.apache.hadoop.hbase.thrift2.generated.TPut.setAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java TPut.setAttributes方法的具体用法?Java TPut.setAttributes怎么用?Java TPut.setAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.thrift2.generated.TPut
的用法示例。
在下文中一共展示了TPut.setAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPutTTL
import org.apache.hadoop.hbase.thrift2.generated.TPut; //导入方法依赖的package包/类
@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());
}
示例2: testPutTTL
import org.apache.hadoop.hbase.thrift2.generated.TPut; //导入方法依赖的package包/类
@Test
public void testPutTTL() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = Bytes.toBytes("testPutTTL");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(1);
// 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());
}