2222import static org .junit .Assert .assertTrue ;
2323
2424import java .io .IOException ;
25+ import java .io .UncheckedIOException ;
2526import java .util .List ;
2627import java .util .Map ;
27-
28+ import org . apache . hadoop . conf . Configuration ;
2829import org .apache .hadoop .hbase .HBaseClassTestRule ;
2930import org .apache .hadoop .hbase .HConstants ;
3031import org .apache .hadoop .hbase .MiniHBaseCluster ;
3132import org .apache .hadoop .hbase .ServerName ;
33+ import org .apache .hadoop .hbase .StartMiniClusterOption ;
3234import org .apache .hadoop .hbase .TableName ;
3335import org .apache .hadoop .hbase .client .RegionInfo ;
3436import org .apache .hadoop .hbase .master .procedure .ServerCrashProcedure ;
@@ -52,6 +54,33 @@ public class TestRetainAssignmentOnRestart extends AbstractTestRestartCluster {
5254
5355 private static int NUM_OF_RS = 3 ;
5456
57+ public static final class HMasterForTest extends HMaster {
58+
59+ public HMasterForTest (Configuration conf ) throws IOException {
60+ super (conf );
61+ }
62+
63+ @ Override
64+ protected void startProcedureExecutor () throws IOException {
65+ // only start procedure executor when we have all the regionservers ready to take regions
66+ new Thread (() -> {
67+ for (;;) {
68+ if (getServerManager ().createDestinationServersList ().size () == NUM_OF_RS ) {
69+ try {
70+ HMasterForTest .super .startProcedureExecutor ();
71+ } catch (IOException e ) {
72+ throw new UncheckedIOException (e );
73+ }
74+ }
75+ try {
76+ Thread .sleep (1000 );
77+ } catch (InterruptedException e ) {
78+ }
79+ }
80+ }).start ();
81+ }
82+ }
83+
5584 @ Override
5685 protected boolean splitWALCoordinatedByZk () {
5786 return true ;
@@ -205,7 +234,8 @@ private void setupCluster() throws Exception, IOException, InterruptedException
205234 HConstants .ZK_CONNECTION_REGISTRY_CLASS );
206235 // Enable retain assignment during ServerCrashProcedure
207236 UTIL .getConfiguration ().setBoolean (ServerCrashProcedure .MASTER_SCP_RETAIN_ASSIGNMENT , true );
208- UTIL .startMiniCluster (NUM_OF_RS );
237+ UTIL .startMiniCluster (StartMiniClusterOption .builder ().masterClass (HMasterForTest .class )
238+ .numRegionServers (NUM_OF_RS ).build ());
209239
210240 // Turn off balancer
211241 UTIL .getMiniHBaseCluster ().getMaster ().getMasterRpcServices ().synchronousBalanceSwitch (false );
0 commit comments