Esempio n. 1
0
 @Test
 public void testByteBufferBackedKeyValueWithTags() throws Exception {
   KeyValue kvCell = new KeyValue(row1, fam1, qual1, 0l, Type.Put, row1, tags);
   ByteBuffer buf = ByteBuffer.allocateDirect(kvCell.getBuffer().length);
   ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getBuffer(), 0, kvCell.getBuffer().length);
   ByteBufferedCell offheapKV = new OffheapKeyValue(buf, 0, buf.capacity(), true, 0l);
   assertEquals(
       ROW1,
       ByteBufferUtils.toStringBinary(
           offheapKV.getRowByteBuffer(),
           offheapKV.getRowPositionInByteBuffer(),
           offheapKV.getRowLength()));
   assertEquals(
       FAM1,
       ByteBufferUtils.toStringBinary(
           offheapKV.getFamilyByteBuffer(),
           offheapKV.getFamilyPositionInByteBuffer(),
           offheapKV.getFamilyLength()));
   assertEquals(
       QUAL1,
       ByteBufferUtils.toStringBinary(
           offheapKV.getQualifierByteBuffer(),
           offheapKV.getQualifierPositionInByteBuffer(),
           offheapKV.getQualifierLength()));
   assertEquals(
       ROW1,
       ByteBufferUtils.toStringBinary(
           offheapKV.getValueByteBuffer(),
           offheapKV.getValuePositionInByteBuffer(),
           offheapKV.getValueLength()));
   assertEquals(0L, offheapKV.getTimestamp());
   assertEquals(Type.Put.getCode(), offheapKV.getTypeByte());
   // change tags to handle both onheap and offheap stuff
   List<Tag> resTags =
       Tag.asList(offheapKV.getTagsArray(), offheapKV.getTagsOffset(), offheapKV.getTagsLength());
   Tag tag1 = resTags.get(0);
   assertEquals(t1.getType(), tag1.getType());
   assertEquals(Bytes.toString(t1.getValue()), Bytes.toString(getTagValue(tag1)));
   Tag tag2 = resTags.get(1);
   assertEquals(tag2.getType(), tag2.getType());
   assertEquals(Bytes.toString(t2.getValue()), Bytes.toString(getTagValue(tag2)));
   Tag res = Tag.getTag(offheapKV.getTagsArray(), 0, offheapKV.getTagsLength(), (byte) 2);
   assertEquals(Bytes.toString(t2.getValue()), Bytes.toString(getTagValue(tag2)));
   res = Tag.getTag(offheapKV.getTagsArray(), 0, offheapKV.getTagsLength(), (byte) 3);
   assertNull(res);
 }