1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.io.hfile.bucket;
20
21 import static org.junit.Assert.assertTrue;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.nio.ByteBuffer;
26
27 import org.apache.hadoop.hbase.testclassification.SmallTests;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31
32
33
34 @Category(SmallTests.class)
35 public class TestFileIOEngine {
36 @Test
37 public void testFileIOEngine() throws IOException {
38 int size = 2 * 1024 * 1024;
39 String filePath = "testFileIOEngine";
40 try {
41 FileIOEngine fileIOEngine = new FileIOEngine(filePath, size);
42 for (int i = 0; i < 50; i++) {
43 int len = (int) Math.floor(Math.random() * 100);
44 long offset = (long) Math.floor(Math.random() * size % (size - len));
45 byte[] data1 = new byte[len];
46 for (int j = 0; j < data1.length; ++j) {
47 data1[j] = (byte) (Math.random() * 255);
48 }
49 byte[] data2 = new byte[len];
50 fileIOEngine.write(ByteBuffer.wrap(data1), offset);
51 fileIOEngine.read(ByteBuffer.wrap(data2), offset);
52 for (int j = 0; j < data1.length; ++j) {
53 assertTrue(data1[j] == data2[j]);
54 }
55 }
56 } finally {
57 File file = new File(filePath);
58 if (file.exists()) {
59 file.delete();
60 }
61 }
62
63 }
64 }