30
30
import org .apache .hadoop .hbase .TableName ;
31
31
import org .apache .hadoop .hbase .client .Connection ;
32
32
import org .apache .hadoop .hbase .client .ConnectionFactory ;
33
+ import org .apache .hadoop .hbase .client .TableDescriptor ;
34
+ import org .apache .hadoop .hbase .client .TableDescriptorBuilder ;
33
35
import org .apache .hadoop .hbase .snapshot .SnapshotTestingUtils ;
34
36
import org .apache .hadoop .hbase .testclassification .MediumTests ;
35
37
import org .apache .hadoop .hbase .util .Bytes ;
36
38
import org .apache .hadoop .hbase .util .CommonFSUtils ;
37
39
import org .junit .After ;
38
- import org .junit .AfterClass ;
39
40
import org .junit .Assert ;
40
- import org .junit .BeforeClass ;
41
+ import org .junit .Before ;
41
42
import org .junit .ClassRule ;
42
43
import org .junit .Test ;
43
44
import org .junit .experimental .categories .Category ;
@@ -63,8 +64,8 @@ public class TestCompactSplitThread {
63
64
/**
64
65
* Setup the config for the cluster
65
66
*/
66
- @ BeforeClass
67
- public static void setupCluster () throws Exception {
67
+ @ Before
68
+ public void setupCluster () throws Exception {
68
69
setupConf (TEST_UTIL .getConfiguration ());
69
70
TEST_UTIL .startMiniCluster (NUM_RS );
70
71
fs = TEST_UTIL .getDFSCluster ().getFileSystem ();
@@ -91,12 +92,7 @@ private static void setupConf(Configuration conf) {
91
92
}
92
93
93
94
@ After
94
- public void tearDown () throws Exception {
95
- TEST_UTIL .deleteTable (tableName );
96
- }
97
-
98
- @ AfterClass
99
- public static void cleanupTest () throws Exception {
95
+ public void cleanupTest () throws Exception {
100
96
try {
101
97
TEST_UTIL .shutdownMiniCluster ();
102
98
} catch (Exception e ) {
@@ -172,4 +168,22 @@ public void testFlushWithTableCompactionDisabled() throws Exception {
172
168
Collection <String > hfiles = SnapshotTestingUtils .listHFileNames (fs , tableDir );
173
169
assert (hfiles .size () > blockingStoreFiles + 1 );
174
170
}
171
+
172
+ @ Test
173
+ public void testFlushWithRegionReplicas () throws Exception {
174
+ TableDescriptor htd =
175
+ TableDescriptorBuilder .newBuilder (tableName ).setRegionReplication (2 ).build ();
176
+ TEST_UTIL .createTable (htd , new byte [][] { family }, null );
177
+
178
+ // load the table
179
+ for (int i = 0 ; i < blockingStoreFiles + 1 ; i ++) {
180
+ TEST_UTIL .loadTable (TEST_UTIL .getConnection ().getTable (tableName ), family );
181
+ TEST_UTIL .flush (tableName );
182
+ }
183
+
184
+ // One region split should have taken place, because the primary replica gets split, and not the
185
+ // secondary replica.
186
+ assertEquals (1 , TEST_UTIL .getRSForFirstRegionInTable (tableName ).getCompactSplitThread ()
187
+ .getSubmittedSplitsCount ());
188
+ }
175
189
}
0 commit comments