5151public class TestZstdDictionarySplitMerge {
5252
5353 private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil ();
54+ private static int numRows = 10_000 ;
5455 private static Configuration conf ;
5556
5657 @ BeforeAll
@@ -82,16 +83,16 @@ public void test() throws Exception {
8283 .setConfiguration (ZstdCodec .ZSTD_DICTIONARY_KEY , dictionaryPath ).build ())
8384 .build ();
8485 final Admin admin = TEST_UTIL .getAdmin ();
85- admin .createTable (td , new byte [][] { Bytes .toBytes (1 ) });
86+ admin .createTable (td , new byte [][] { Bytes .toBytes (String . valueOf ( 1 ) ) });
8687 TEST_UTIL .waitTableAvailable (tableName );
8788 // Load some data
8889 Table t = ConnectionFactory .createConnection (conf ).getTable (tableName );
89- TEST_UTIL .loadNumericRows (t , cfName , 0 , 100_000 );
90+ TEST_UTIL .loadNumericRows (t , cfName , 0 , numRows );
9091 admin .flush (tableName );
9192 assertTrue (DictionaryCache .contains (dictionaryPath ), "Dictionary was not loaded" );
92- TEST_UTIL .verifyNumericRows (t , cfName , 0 , 100_000 , 0 );
93+ TEST_UTIL .verifyNumericRows (t , cfName , 0 , numRows , 0 );
9394 // Test split procedure
94- admin .split (tableName , Bytes .toBytes (50_000 ));
95+ admin .split (tableName , Bytes .toBytes (String . valueOf ( numRows / 2 ) ));
9596 TEST_UTIL .waitFor (30000 , new ExplainingPredicate <Exception >() {
9697 @ Override
9798 public boolean evaluate () throws Exception {
@@ -104,30 +105,36 @@ public String explainFailure() throws Exception {
104105 }
105106 });
106107 TEST_UTIL .waitUntilNoRegionsInTransition ();
107- TEST_UTIL .verifyNumericRows (t , cfName , 0 , 100_000 , 0 );
108+ TEST_UTIL .verifyNumericRows (t , cfName , 0 , numRows , 0 );
108109 // Test merge procedure
109110 RegionInfo regionA = null ;
110111 RegionInfo regionB = null ;
112+
111113 for (RegionInfo region : admin .getRegions (tableName )) {
112114 if (region .getStartKey ().length == 0 ) {
113115 regionA = region ;
114- } else if (Bytes .equals (region .getStartKey (), Bytes .toBytes (1 ))) {
116+ } else if (Bytes .equals (region .getStartKey (), Bytes .toBytes (String . valueOf ( 1 ) ))) {
115117 regionB = region ;
116118 }
117119 }
118120 assertNotNull (regionA );
119121 assertNotNull (regionB );
122+
123+ // major compact before merging otherwise the regions are not mergable
124+ TEST_UTIL .compact (tableName , true );
125+ admin .reopenTableRegions (tableName );
126+
120127 admin
121128 .mergeRegionsAsync (new byte [][] { regionA .getRegionName (), regionB .getRegionName () }, false )
122- .get (30 , TimeUnit .SECONDS );
129+ .get (300 , TimeUnit .SECONDS );
123130 assertEquals (2 , admin .getRegions (tableName ).size ());
124131 ServerName expected = TEST_UTIL .getMiniHBaseCluster ().getRegionServer (0 ).getServerName ();
125132 assertEquals (expected , TEST_UTIL .getConnection ().getRegionLocator (tableName )
126- .getRegionLocation (Bytes .toBytes (1 ), true ).getServerName ());
133+ .getRegionLocation (Bytes .toBytes (String . valueOf ( 1 ) ), true ).getServerName ());
127134 try (AsyncConnection asyncConn = ConnectionFactory .createAsyncConnection (conf ).get ()) {
128135 assertEquals (expected , asyncConn .getRegionLocator (tableName )
129- .getRegionLocation (Bytes .toBytes (1 ), true ).get ().getServerName ());
136+ .getRegionLocation (Bytes .toBytes (String . valueOf ( 1 ) ), true ).get ().getServerName ());
130137 }
131- TEST_UTIL .verifyNumericRows (t , cfName , 0 , 100_000 , 0 );
138+ TEST_UTIL .verifyNumericRows (t , cfName , 0 , numRows , 0 );
132139 }
133140}
0 commit comments