Java Code Examples for org.apache.hadoop.hbase.util.PositionedByteRange#putShort()

The following examples show how to use org.apache.hadoop.hbase.util.PositionedByteRange#putShort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicPositionedMutableByteRangeTest.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutAndGetPrimitiveTypes() throws Exception {
    PositionedByteRange pbr = new DynamicPositionedMutableByteRange(1);
    int i1 = 18, i2 = 2;
    short s1 = 0;
    long l1 = 1234L;
    pbr.putInt(i1);
    pbr.putInt(i2);
    pbr.putShort(s1);
    pbr.putLong(l1);
    pbr.putVLong(0);
    pbr.putVLong(l1);
    pbr.putVLong(Long.MAX_VALUE);
    pbr.putVLong(Long.MIN_VALUE);
    // rewind
    pbr.setPosition(0);
    Assert.assertEquals(i1, pbr.getInt());
    Assert.assertEquals(i2, pbr.getInt());
    Assert.assertEquals(s1, pbr.getShort());
    Assert.assertEquals(l1, pbr.getLong());
    Assert.assertEquals(0, pbr.getVLong());
    Assert.assertEquals(l1, pbr.getVLong());
    Assert.assertEquals(Long.MAX_VALUE, pbr.getVLong());
    Assert.assertEquals(Long.MIN_VALUE, pbr.getVLong());
}
 
Example 2
Source File: DynamicPositionedMutableByteRangeTest.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutGetAPIsCompareWithBBAPIs() throws Exception {
    // confirm that the long/int/short writing is same as BBs
    PositionedByteRange pbr = new DynamicPositionedMutableByteRange(1);
    int i1 = -234, i2 = 2;
    short s1 = 0;
    long l1 = 1234L;
    pbr.putInt(i1);
    pbr.putShort(s1);
    pbr.putInt(i2);
    pbr.putLong(l1);
    // rewind
    pbr.setPosition(0);
    Assert.assertEquals(i1, pbr.getInt());
    Assert.assertEquals(s1, pbr.getShort());
    Assert.assertEquals(i2, pbr.getInt());
    Assert.assertEquals(l1, pbr.getLong());
    // Read back using BB APIs
    ByteBuffer bb = ByteBuffer.wrap(pbr.getBytes());
    Assert.assertEquals(i1, bb.getInt());
    Assert.assertEquals(s1, bb.getShort());
    Assert.assertEquals(i2, bb.getInt());
    Assert.assertEquals(l1, bb.getLong());
}