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