1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.util;
19
20 import static org.junit.Assert.*;
21
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.fs.Path;
24 import org.apache.hadoop.hbase.HConstants;
25 import org.apache.hadoop.hbase.HRegionInfo;
26 import org.apache.hadoop.hbase.SmallTests;
27 import org.apache.hadoop.hbase.regionserver.HRegion;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30 import org.mockito.Mockito;
31
32
33
34
35 @Category(SmallTests.class)
36 public class TestHFileArchiveUtil {
37
38 @Test
39 public void testGetTableArchivePath() {
40 assertNotNull(HFileArchiveUtil.getTableArchivePath(new Path("table")));
41 assertNotNull(HFileArchiveUtil.getTableArchivePath(new Path("root", new Path("table"))));
42 }
43
44 @Test
45 public void testGetArchivePath() throws Exception {
46 Configuration conf = new Configuration();
47 FSUtils.setRootDir(conf, new Path("root"));
48 assertNotNull(HFileArchiveUtil.getArchivePath(conf));
49 }
50
51 @Test
52 public void testRegionArchiveDir() {
53 Configuration conf = null;
54 Path tableDir = new Path("table");
55 Path regionDir = new Path("region");
56 assertNotNull(HFileArchiveUtil.getRegionArchiveDir(conf, tableDir, regionDir));
57 }
58
59 @Test
60 public void testGetStoreArchivePath(){
61 byte[] family = Bytes.toBytes("Family");
62 Path tabledir = new Path("table");
63 HRegionInfo region = new HRegionInfo(Bytes.toBytes("table"));
64 Configuration conf = null;
65 assertNotNull(HFileArchiveUtil.getStoreArchivePath(conf, region, tabledir, family));
66 conf = new Configuration();
67 assertNotNull(HFileArchiveUtil.getStoreArchivePath(conf, region, tabledir, family));
68
69
70 HRegion mockRegion = Mockito.mock(HRegion.class);
71 Mockito.when(mockRegion.getRegionInfo()).thenReturn(region);
72 Mockito.when(mockRegion.getTableDir()).thenReturn(tabledir);
73
74 assertNotNull(HFileArchiveUtil.getStoreArchivePath(null, mockRegion, family));
75 conf = new Configuration();
76 assertNotNull(HFileArchiveUtil.getStoreArchivePath(conf, mockRegion, family));
77 }
78 }