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.testclassification.IntegrationTests;
31 import org.apache.hadoop.hbase.TableName;
32 import org.apache.hadoop.hbase.util.Bytes;
33 import org.apache.hadoop.util.ToolRunner;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.experimental.categories.Category;
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
65
66
67
68 @Category(IntegrationTests.class)
69
70 public class IntegrationTestTableSnapshotInputFormat extends IntegrationTestBase {
71
72 private static final Log LOG = LogFactory.getLog(IntegrationTestTableSnapshotInputFormat.class);
73
74 private static final String TABLE_NAME_KEY = "IntegrationTestTableSnapshotInputFormat.table";
75 private static final String DEFAULT_TABLE_NAME = "IntegrationTestTableSnapshotInputFormat";
76
77 private static final String SNAPSHOT_NAME_KEY =
78 "IntegrationTestTableSnapshotInputFormat.snapshot";
79 private static final String NUM_REGIONS_KEY =
80 "IntegrationTestTableSnapshotInputFormat.numRegions";
81
82 private static final String MR_IMPLEMENTATION_KEY =
83 "IntegrationTestTableSnapshotInputFormat.API";
84 private static final String MAPRED_IMPLEMENTATION = "mapred";
85 private static final String MAPREDUCE_IMPLEMENTATION = "mapreduce";
86
87 private static final int DEFAULT_NUM_REGIONS = 32;
88 private static final String TABLE_DIR_KEY = "IntegrationTestTableSnapshotInputFormat.tableDir";
89
90 private static final byte[] START_ROW = Bytes.toBytes("bbb");
91 private static final byte[] END_ROW = Bytes.toBytes("yyy");
92
93
94
95 private static final byte[] MAPRED_START_ROW = Bytes.toBytes("aaa");
96 private static final byte[] MAPRED_END_ROW = Bytes.toBytes("zz{");
97
98 private IntegrationTestingUtility util;
99
100 @Override
101 public void setConf(Configuration conf) {
102 super.setConf(conf);
103 util = getTestingUtil(conf);
104 }
105
106 @Override
107 @Before
108 public void setUp() throws Exception {
109 super.setUp();
110 util = getTestingUtil(getConf());
111 util.initializeCluster(1);
112 this.setConf(util.getConfiguration());
113 }
114
115 @Override
116 @After
117 public void cleanUp() throws Exception {
118 util.restoreCluster();
119 }
120
121 @Override
122 public void setUpCluster() throws Exception {
123 }
124
125 @Override
126 public int runTestFromCommandLine() throws Exception {
127 Configuration conf = getConf();
128 TableName tableName = TableName.valueOf(conf.get(TABLE_NAME_KEY, DEFAULT_TABLE_NAME));
129 String snapshotName = conf.get(SNAPSHOT_NAME_KEY, tableName.getQualifierAsString()
130 + "_snapshot_" + System.currentTimeMillis());
131 int numRegions = conf.getInt(NUM_REGIONS_KEY, DEFAULT_NUM_REGIONS);
132 String tableDirStr = conf.get(TABLE_DIR_KEY);
133 Path tableDir;
134 if (tableDirStr == null) {
135 tableDir = util.getDataTestDirOnTestFS(tableName.getQualifierAsString());
136 } else {
137 tableDir = new Path(tableDirStr);
138 }
139
140 final String mr = conf.get(MR_IMPLEMENTATION_KEY, MAPREDUCE_IMPLEMENTATION);
141 if (mr.equalsIgnoreCase(MAPREDUCE_IMPLEMENTATION)) {
142
143
144
145
146
147
148
149
150 LOG.debug("Running job with mapreduce API.");
151 int expectedNumSplits = numRegions > 2 ? numRegions - 2 : numRegions;
152
153 org.apache.hadoop.hbase.mapreduce.TestTableSnapshotInputFormat.doTestWithMapReduce(util,
154 tableName, snapshotName, START_ROW, END_ROW, tableDir, numRegions,
155 expectedNumSplits, false);
156 } else if (mr.equalsIgnoreCase(MAPRED_IMPLEMENTATION)) {
157
158
159
160
161
162
163
164 LOG.debug("Running job with mapred API.");
165 int expectedNumSplits = numRegions;
166
167 org.apache.hadoop.hbase.mapred.TestTableSnapshotInputFormat.doTestWithMapReduce(util,
168 tableName, snapshotName, MAPRED_START_ROW, MAPRED_END_ROW, tableDir, numRegions,
169 expectedNumSplits, false);
170 } else {
171 throw new IllegalArgumentException("Unrecognized mapreduce implementation: " + mr +".");
172 }
173
174 return 0;
175 }
176
177 @Override
178 public TableName getTablename() {
179 return null;
180 }
181
182 @Override
183 protected Set<String> getColumnFamilies() {
184 return null;
185 }
186
187 public static void main(String[] args) throws Exception {
188 Configuration conf = HBaseConfiguration.create();
189 IntegrationTestingUtility.setUseDistributedCluster(conf);
190 int ret = ToolRunner.run(conf, new IntegrationTestTableSnapshotInputFormat(), args);
191 System.exit(ret);
192 }
193
194 }