1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase;
20
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.testclassification.MediumTests;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31 import java.io.IOException;
32
33
34
35
36
37 @Category( MediumTests.class ) public class TestMovedRegionsCleaner {
38
39 public static final Log LOG = LogFactory.getLog(TestRegionRebalancing.class);
40 private final HBaseTestingUtility UTIL = new HBaseTestingUtility();
41
42 public static int numCalls = 0;
43
44 private static class TestMockRegionServer extends MiniHBaseCluster.MiniHBaseClusterRegionServer {
45
46 public TestMockRegionServer(Configuration conf, CoordinatedStateManager cp)
47 throws IOException, InterruptedException {
48 super(conf, cp);
49 }
50
51 protected int movedRegionCleanerPeriod() {
52 return 500;
53 }
54
55 @Override protected void cleanMovedRegions() {
56
57
58 numCalls++;
59 super.cleanMovedRegions();
60 }
61 }
62
63 @After public void after() throws Exception {
64 UTIL.shutdownMiniCluster();
65 }
66
67 @Before public void before() throws Exception {
68 UTIL.getConfiguration()
69 .setStrings(HConstants.REGION_SERVER_IMPL, TestMockRegionServer.class.getName());
70 UTIL.startMiniCluster(1);
71 }
72
73
74
75
76
77
78
79
80 @Test public void testMovedRegionsCleaner() throws IOException, InterruptedException {
81
82
83
84
85 UTIL.waitFor(2000, new Waiter.Predicate<IOException>() {
86 @Override
87 public boolean evaluate() throws IOException {
88
89
90
91 return numCalls > 0;
92 }
93 });
94 }
95 }