1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import static org.junit.Assert.*;
22
23 import java.io.IOException;
24
25 import org.apache.hadoop.fs.Path;
26 import org.apache.hadoop.hbase.HBaseTestingUtility;
27 import org.apache.hadoop.hbase.testclassification.SmallTests;
28 import org.apache.hadoop.hbase.io.HFileLink;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31
32
33
34
35 @Category(SmallTests.class)
36 public class TestStoreFileInfo {
37 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
38
39
40
41
42 @Test
43 public void testStoreFileNames() {
44 String[] legalHFileLink = { "MyTable_02=abc012-def345", "MyTable_02.300=abc012-def345",
45 "MyTable_02-400=abc012-def345", "MyTable_02-400.200=abc012-def345",
46 "MyTable_02=abc012-def345_SeqId_1_", "MyTable_02=abc012-def345_SeqId_20_" };
47 for (String name: legalHFileLink) {
48 assertTrue("should be a valid link: " + name, HFileLink.isHFileLink(name));
49 assertTrue("should be a valid StoreFile" + name, StoreFileInfo.validateStoreFileName(name));
50 assertFalse("should not be a valid reference: " + name, StoreFileInfo.isReference(name));
51
52 String refName = name + ".6789";
53 assertTrue("should be a valid link reference: " + refName,
54 StoreFileInfo.isReference(refName));
55 assertTrue("should be a valid StoreFile" + refName,
56 StoreFileInfo.validateStoreFileName(refName));
57 }
58
59 String[] illegalHFileLink = { ".MyTable_02=abc012-def345", "-MyTable_02.300=abc012-def345",
60 "MyTable_02-400=abc0_12-def345", "MyTable_02-400.200=abc012-def345...." };
61 for (String name: illegalHFileLink) {
62 assertFalse("should not be a valid link: " + name, HFileLink.isHFileLink(name));
63 }
64 }
65
66 @Test
67 public void testEqualsWithLink() throws IOException {
68 Path origin = new Path("/origin");
69 Path tmp = new Path("/tmp");
70 Path archive = new Path("/archive");
71 HFileLink link1 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"),
72 new Path(archive, "f1"));
73 HFileLink link2 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"),
74 new Path(archive, "f1"));
75
76
77 StoreFileInfo info1 = new StoreFileInfo(TEST_UTIL.getConfiguration(),
78 TEST_UTIL.getTestFileSystem(), null, link1);
79 StoreFileInfo info2 = new StoreFileInfo(TEST_UTIL.getConfiguration(),
80 TEST_UTIL.getTestFileSystem(), null, link2);
81
82 assertEquals(info1, info2);
83 assertEquals(info1.hashCode(), info2.hashCode());
84 }
85 }
86