1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.util;
19
20 import org.apache.hadoop.hbase.SmallTests;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.junit.experimental.categories.Category;
24
25 @Category(SmallTests.class)
26 public class TestPositionedByteRange {
27 @Test
28 public void testPosition() {
29 PositionedByteRange r = new SimplePositionedByteRange(new byte[5], 1, 3);
30
31
32 r.put(Bytes.toBytes("f")[0])
33 .put(Bytes.toBytes("o")[0])
34 .put(Bytes.toBytes("o")[0]);
35 Assert.assertEquals(3, r.getPosition());
36 Assert.assertArrayEquals(
37 new byte[] { 0, Bytes.toBytes("f")[0], Bytes.toBytes("o")[0], Bytes.toBytes("o")[0], 0 },
38 r.getBytes());
39
40
41 r.setPosition(0);
42 r.put(Bytes.toBytes("f"))
43 .put(Bytes.toBytes("o"))
44 .put(Bytes.toBytes("o"));
45 Assert.assertEquals(3, r.getPosition());
46 Assert.assertArrayEquals(
47 new byte[] { 0, Bytes.toBytes("f")[0], Bytes.toBytes("o")[0], Bytes.toBytes("o")[0], 0 },
48 r.getBytes());
49
50
51 r.setPosition(0);
52 Assert.assertEquals(Bytes.toBytes("f")[0], r.get());
53 Assert.assertEquals(Bytes.toBytes("o")[0], r.get());
54 Assert.assertEquals(Bytes.toBytes("o")[0], r.get());
55
56 r.setPosition(1);
57 Assert.assertEquals(Bytes.toBytes("o")[0], r.get());
58
59
60 r.setPosition(0);
61 byte[] dst = new byte[3];
62 r.get(dst);
63 Assert.assertArrayEquals(Bytes.toBytes("foo"), dst);
64
65
66 r.setPosition(3);
67 }
68 }