1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.mob;
20
21 import java.io.IOException;
22 import java.util.Random;
23
24 import org.apache.hadoop.hbase.Cell;
25 import org.apache.hadoop.hbase.CellUtil;
26 import org.apache.hadoop.hbase.KeyValue;
27 import org.apache.hadoop.hbase.regionserver.StoreFile;
28 import org.apache.hadoop.hbase.util.Bytes;
29 import org.junit.Assert;
30
31 public class MobTestUtil {
32 protected static final char FIRST_CHAR = 'a';
33 protected static final char LAST_CHAR = 'z';
34
35 protected static String generateRandomString(int demoLength) {
36 String base = "abcdefghijklmnopqrstuvwxyz";
37 Random random = new Random();
38 StringBuffer sb = new StringBuffer();
39 for (int i = 0; i < demoLength; i++) {
40 int number = random.nextInt(base.length());
41 sb.append(base.charAt(number));
42 }
43 return sb.toString();
44 }
45 protected static void writeStoreFile(final StoreFile.Writer writer, String caseName)
46 throws IOException {
47 writeStoreFile(writer, Bytes.toBytes(caseName), Bytes.toBytes(caseName));
48 }
49
50
51
52
53
54
55
56
57
58 private static void writeStoreFile(final StoreFile.Writer writer, byte[] fam,
59 byte[] qualifier) throws IOException {
60 long now = System.currentTimeMillis();
61 try {
62 for (char d = FIRST_CHAR; d <= LAST_CHAR; d++) {
63 for (char e = FIRST_CHAR; e <= LAST_CHAR; e++) {
64 byte[] b = new byte[] { (byte) d, (byte) e };
65 writer.append(new KeyValue(b, fam, qualifier, now, b));
66 }
67 }
68 } finally {
69 writer.close();
70 }
71 }
72
73
74
75
76 public static void assertCellEquals(Cell firstKeyValue,
77 Cell secondKeyValue) {
78 Assert.assertEquals(Bytes.toString(CellUtil.cloneRow(firstKeyValue)),
79 Bytes.toString(CellUtil.cloneRow(secondKeyValue)));
80 Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(firstKeyValue)),
81 Bytes.toString(CellUtil.cloneFamily(secondKeyValue)));
82 Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(firstKeyValue)),
83 Bytes.toString(CellUtil.cloneQualifier(secondKeyValue)));
84 Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(firstKeyValue)),
85 Bytes.toString(CellUtil.cloneValue(secondKeyValue)));
86 }
87 }