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 static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.fail;
22
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.fs.FileSystem;
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.hbase.HColumnDescriptor;
30 import org.apache.hadoop.hbase.HRegionInfo;
31 import org.apache.hadoop.hbase.HTableDescriptor;
32 import org.apache.hadoop.hbase.client.RetriesExhaustedException;
33 import org.apache.hadoop.hbase.client.example.RefreshHFilesClient;
34 import org.apache.hadoop.hbase.regionserver.HRegion;
35 import org.apache.hadoop.hbase.regionserver.HStore;
36 import org.apache.hadoop.hbase.regionserver.RegionServerServices;
37 import org.apache.hadoop.hbase.regionserver.Store;
38 import org.apache.hadoop.hbase.testclassification.MediumTests;
39 import org.apache.hadoop.hbase.wal.WAL;
40 import org.junit.Test;
41 import org.junit.experimental.categories.Category;
42
43 @Category(MediumTests.class)
44 public class TestRefreshHFilesEndpoint extends TestRefreshHFilesBase {
45
46 @Test
47 public void testRefreshRegionHFilesEndpoint() throws Exception {
48 setUp(HRegion.class.getName());
49 addHFilesToRegions();
50 assertEquals(2, HTU.getNumHFiles(TABLE_NAME, FAMILY));
51 callRefreshRegionHFilesEndPoint();
52 assertEquals(4, HTU.getNumHFiles(TABLE_NAME, FAMILY));
53 }
54
55 @Test(expected = IOException.class)
56 public void testRefreshRegionHFilesEndpointWithException() throws IOException {
57 setUp(HRegionForRefreshHFilesEP.class.getName());
58 callRefreshRegionHFilesEndPoint();
59 }
60
61 private void callRefreshRegionHFilesEndPoint() throws IOException {
62 try {
63 RefreshHFilesClient refreshHFilesClient = new RefreshHFilesClient(CONF);
64 refreshHFilesClient.refreshHFiles(TABLE_NAME);
65 } catch (RetriesExhaustedException rex) {
66 if (rex.getCause() instanceof IOException)
67 throw new IOException();
68 } catch (Throwable ex) {
69 LOG.error(ex.toString(), ex);
70 fail("Couldn't call the RefreshRegionHFilesEndpoint");
71 }
72 }
73
74 public static class HRegionForRefreshHFilesEP extends HRegion {
75 HStoreWithFaultyRefreshHFilesAPI store;
76
77 public HRegionForRefreshHFilesEP(final Path tableDir, final WAL wal, final FileSystem fs,
78 final Configuration confParam, final HRegionInfo regionInfo,
79 final HTableDescriptor htd, final RegionServerServices rsServices) {
80 super(tableDir, wal, fs, confParam, regionInfo, htd, rsServices);
81 }
82
83 @Override
84 public List<Store> getStores() {
85 List<Store> list = new ArrayList<Store>(stores.size());
86
87
88
89
90 try {
91 if (this.store == null)
92 store = new HStoreWithFaultyRefreshHFilesAPI(this, new HColumnDescriptor(FAMILY),
93 this.conf);
94 list.add(store);
95 } catch (IOException ioe) {
96 LOG.info("Couldn't instantiate custom store implementation", ioe);
97 }
98
99 list.addAll(stores.values());
100 return list;
101 }
102 }
103
104 public static class HStoreWithFaultyRefreshHFilesAPI extends HStore {
105 public HStoreWithFaultyRefreshHFilesAPI(final HRegion region,
106 final HColumnDescriptor family, final Configuration confParam) throws IOException {
107 super(region, family, confParam);
108 }
109
110 @Override
111 public void refreshStoreFiles() throws IOException {
112 throw new IOException();
113 }
114 }
115 }