1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.io.hfile.slab;
22
23 import static org.junit.Assert.*;
24 import java.nio.ByteBuffer;
25
26 import org.apache.hadoop.hbase.SmallTests;
27 import org.junit.*;
28 import org.junit.experimental.categories.Category;
29
30
31 @Category(SmallTests.class)
32 public class TestSlab {
33 static final int BLOCKSIZE = 1000;
34 static final int NUMBLOCKS = 100;
35 Slab testSlab;
36 ByteBuffer[] buffers = new ByteBuffer[NUMBLOCKS];
37
38 @Before
39 public void setUp() {
40 testSlab = new Slab(BLOCKSIZE, NUMBLOCKS);
41 }
42
43 @After
44 public void tearDown() {
45 testSlab.shutdown();
46 }
47
48 @Test
49 public void testBasicFunctionality() throws InterruptedException {
50 for (int i = 0; i < NUMBLOCKS; i++) {
51 buffers[i] = testSlab.alloc(BLOCKSIZE);
52 assertEquals(BLOCKSIZE, buffers[i].limit());
53 }
54
55
56 for (int i = 0; i < NUMBLOCKS; i++) {
57 buffers[i].putInt(i);
58 }
59
60
61
62 for (int i = 0; i < NUMBLOCKS; i++) {
63 buffers[i].putInt(i);
64 }
65
66 for (int i = 0; i < NUMBLOCKS; i++) {
67 testSlab.free(buffers[i]);
68 }
69
70 for (int i = 0; i < NUMBLOCKS; i++) {
71 buffers[i] = testSlab.alloc(BLOCKSIZE);
72 assertEquals(BLOCKSIZE, buffers[i].limit());
73 }
74 }
75
76
77 @org.junit.Rule
78 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
79 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
80 }
81