1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.coprocessor.example;
19
20 import java.io.IOException;
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.fs.Path;
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.HColumnDescriptor;
25 import org.apache.hadoop.hbase.HConstants;
26 import org.apache.hadoop.hbase.HTableDescriptor;
27 import org.apache.hadoop.hbase.MiniHBaseCluster;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.client.Admin;
30 import org.apache.hadoop.hbase.client.HTable;
31 import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
32 import org.apache.hadoop.hbase.regionserver.Region;
33 import org.apache.hadoop.hbase.util.Bytes;
34 import org.apache.hadoop.hbase.util.HFileTestUtil;
35 import org.junit.After;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 public class TestRefreshHFilesBase {
40 protected static final Logger LOG = LoggerFactory.getLogger(TestRefreshHFilesBase.class);
41 protected static final HBaseTestingUtility HTU = new HBaseTestingUtility();
42 protected static final TableName TABLE_NAME = TableName.valueOf("testRefreshRegionHFilesEP");
43 protected static final byte[] FAMILY = Bytes.toBytes("family");
44 protected static final byte[] QUALIFIER = Bytes.toBytes("qualifier");
45 private static final int NUM_ROWS = 5;
46 private static final int NUM_MASTER = 1;
47 private static final int NUM_RS = 2;
48 private static final byte[][] SPLIT_KEY = new byte[][] { Bytes.toBytes("30") };
49 private static final String HFILE_NAME = "123abcdef";
50
51 protected static Configuration CONF = HTU.getConfiguration();
52 private static MiniHBaseCluster cluster;
53 private static HTable table;
54 private static HTableDescriptor desc;
55 private static Admin hbaseAdmin;
56
57
58 public static void setUp(String regionImpl) {
59 try {
60 CONF.set(HConstants.REGION_IMPL, regionImpl);
61 CONF.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
62
63 CONF.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, RefreshHFilesEndpoint.class.getName());
64 cluster = HTU.startMiniCluster(NUM_MASTER, NUM_RS);
65
66
67 desc = new HTableDescriptor(TABLE_NAME);
68 desc.addFamily(new HColumnDescriptor(FAMILY));
69 hbaseAdmin = cluster.getMaster().getConnection().getAdmin();
70 hbaseAdmin.createTable(desc, SPLIT_KEY);
71 table = new HTable(HTU.getConfiguration(), TABLE_NAME);
72
73
74 HTU.loadNumericRows(table, FAMILY, 1, 20);
75 HTU.flush(TABLE_NAME);
76 } catch (Exception ex) {
77 LOG.error("Couldn't finish setup", ex);
78 }
79 }
80
81 @After
82 public void tearDown() throws Exception {
83 HTU.shutdownMiniCluster();
84 }
85
86 protected void addHFilesToRegions() throws IOException {
87 Path tableDir = desc.getTableDir(HTU.getDefaultRootDirPath(), TABLE_NAME.toBytes());
88 for (Region region : cluster.getRegions(TABLE_NAME)) {
89 Path regionDir = new Path(tableDir, region.getRegionInfo().getEncodedName());
90 Path familyDir = new Path(regionDir, Bytes.toString(FAMILY));
91 HFileTestUtil.createHFile(HTU.getConfiguration(), HTU.getTestFileSystem(),
92 new Path(familyDir, HFILE_NAME), FAMILY, QUALIFIER, Bytes.toBytes("50"),
93 Bytes.toBytes("60"), NUM_ROWS);
94 }
95 }
96 }