1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.mapreduce;
20
21 import java.util.Set;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.hbase.HBaseConfiguration;
28 import org.apache.hadoop.hbase.IntegrationTestBase;
29 import org.apache.hadoop.hbase.IntegrationTestingUtility;
30 import org.apache.hadoop.hbase.IntegrationTests;
31 import org.apache.hadoop.hbase.TableName;
32 import org.apache.hadoop.util.ToolRunner;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.experimental.categories.Category;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 @Category(IntegrationTests.class)
65
66 public class IntegrationTestTableSnapshotInputFormat extends IntegrationTestBase {
67
68 private static final Log LOG = LogFactory.getLog(IntegrationTestTableSnapshotInputFormat.class);
69
70 private static final String TABLE_NAME_KEY = "IntegrationTestTableSnapshotInputFormat.table";
71 private static final String DEFAULT_TABLE_NAME = "IntegrationTestTableSnapshotInputFormat";
72
73 private static final String SNAPSHOT_NAME_KEY = "IntegrationTestTableSnapshotInputFormat.snapshot";
74
75
76 private static final String NUM_REGIONS_KEY = "IntegrationTestTableSnapshotInputFormat.numRegions";
77 private static final int DEFAULT_NUM_REGIONS = 32;
78
79 private static final String TABLE_DIR_KEY = "IntegrationTestTableSnapshotInputFormat.tableDir";
80
81 private IntegrationTestingUtility util;
82
83 @Override
84 public void setConf(Configuration conf) {
85 super.setConf(conf);
86 util = getTestingUtil(conf);
87 }
88
89 @Override
90 @Before
91 public void setUp() throws Exception {
92 super.setUp();
93 util = getTestingUtil(getConf());
94 util.initializeCluster(1);
95 this.setConf(util.getConfiguration());
96 }
97
98 @Override
99 @After
100 public void cleanUp() throws Exception {
101 util.restoreCluster();
102 }
103
104 @Override
105 public void setUpCluster() throws Exception {
106 }
107
108 @Override
109 public int runTestFromCommandLine() throws Exception {
110 Configuration conf = getConf();
111 TableName tableName = TableName.valueOf(conf.get(TABLE_NAME_KEY, DEFAULT_TABLE_NAME));
112 String snapshotName = conf.get(SNAPSHOT_NAME_KEY, tableName.getQualifierAsString()
113 + "_snapshot_" + System.currentTimeMillis());
114 int numRegions = conf.getInt(NUM_REGIONS_KEY, DEFAULT_NUM_REGIONS);
115 String tableDirStr = conf.get(TABLE_DIR_KEY);
116 Path tableDir;
117 if (tableDirStr == null) {
118 tableDir = util.getDataTestDirOnTestFS(tableName.getQualifierAsString());
119 } else {
120 tableDir = new Path(tableDirStr);
121 }
122
123
124
125
126
127
128
129
130 int expectedNumSplits = numRegions > 2 ? numRegions - 2 : numRegions;
131
132 TestTableSnapshotInputFormat.doTestWithMapReduce(util, tableName, snapshotName, tableDir,
133 numRegions, expectedNumSplits, false);
134
135 return 0;
136 }
137
138 @Override
139 public String getTablename() {
140 return null;
141 }
142
143 @Override
144 protected Set<String> getColumnFamilies() {
145 return null;
146 }
147
148 public static void main(String[] args) throws Exception {
149 Configuration conf = HBaseConfiguration.create();
150 IntegrationTestingUtility.setUseDistributedCluster(conf);
151 int ret = ToolRunner.run(conf, new IntegrationTestTableSnapshotInputFormat(), args);
152 System.exit(ret);
153 }
154
155 }