aalhour commented on code in PR #5681:
URL: https://github.com/apache/hbase/pull/5681#discussion_r1491293713


##########
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReportForDuty.java:
##########
@@ -241,6 +243,125 @@ public void run() {
     waitForClusterOnline(master);
   }
 
+  /**
+   * Tests that the RegionServer's reportForDuty gets rejected by the master 
when the master is
+   * configured to reject decommissioned hosts and when there is a match for 
the joining
+   * RegionServer in the list of decommissioned servers. Test case for 
HBASE-28342.
+   */
+  @Test
+  public void 
testReportForDutyGetsRejectedByMasterWhenConfiguredToRejectDecommissionedHosts()
+    throws Exception {
+    // Start a master and wait for it to become the active/primary master.
+    // Use a random unique port
+    cluster.getConfiguration().setInt(HConstants.MASTER_PORT, 
HBaseTestingUtil.randomFreePort());
+    
cluster.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART,
 1);
+    
cluster.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART,
 1);
+
+    // Set the cluster to reject decommissioned hosts
+    
cluster.getConfiguration().setBoolean(HConstants.REJECT_DECOMMISSIONED_HOSTS_KEY,
 true);
+
+    master = cluster.addMaster();
+    rs = cluster.addRegionServer();
+    LOG.debug("Starting master: " + master.getMaster().getServerName());
+    master.start();
+    rs.start();
+
+    waitForClusterOnline(master);
+
+    assertEquals(0, 
master.getMaster().listDecommissionedRegionServers().size());
+    assertEquals(0, 
master.getMaster().getServerManager().getDrainingServersList().size());
+    assertEquals(1, 
master.getMaster().getServerManager().getOnlineServers().size());
+
+    // Decommission the region server and tries to re-add it
+    List<ServerName> serversToDecommission = new ArrayList<ServerName>();
+    serversToDecommission.add(rs.getRegionServer().getServerName());
+    master.getMaster().decommissionRegionServers(serversToDecommission, true);
+
+    // Assert that the server is now decommissioned
+    ServerName decommissionedServer = 
master.getMaster().listDecommissionedRegionServers().get(0);
+    assertEquals(1, 
master.getMaster().listDecommissionedRegionServers().size());
+    assertEquals(1, 
master.getMaster().getServerManager().getDrainingServersList().size());
+    assertEquals(1, 
master.getMaster().getServerManager().getOnlineServers().size());
+    assertEquals(rs.getRegionServer().getServerName().toString(),
+      decommissionedServer.getServerName());
+
+    // Create a second region server
+    cluster.getConfiguration().set(HConstants.REGION_SERVER_IMPL, 
MyRegionServer.class.getName());
+    rs2 = cluster.addRegionServer();
+    rs2.start();
+    waitForSecondRsStarted();
+
+    // Assert that the number of decommissioned and live hosts didn't change 
and that the hostname
+    // of rs2 matches that of the decommissioned server
+    String rs2HostName = rs2.getRegionServer().getServerName().getHostname();
+    assertEquals(1, 
master.getMaster().listDecommissionedRegionServers().size());
+    assertEquals(1, 
master.getMaster().getServerManager().getDrainingServersList().size());
+    assertEquals(1, master.getMaster().getLiveRegionServers().size());
+    assertEquals(1, 
master.getMaster().getServerManager().getOnlineServers().size());
+    assertEquals(rs2HostName, decommissionedServer.getHostname());
+  }
+
+  /**
+   * Tests that the RegionServer's reportForDuty gets accepted by the master 
when the master is not
+   * configured to reject decommissioned hosts, even when there is a match for 
the joining
+   * RegionServer in the list of decommissioned servers. Test case for 
HBASE-28342.
+   */
+  @Test
+  public void 
testReportForDutyGetsAcceptedByMasterWhenNotConfiguredToRejectDecommissionedHosts()
+    throws Exception {
+    // Start a master and wait for it to become the active/primary master.
+    // Use a random unique port
+    cluster.getConfiguration().setInt(HConstants.MASTER_PORT, 
HBaseTestingUtil.randomFreePort());
+    
cluster.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART,
 1);
+    
cluster.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART,
 1);
+
+    // Set the cluster to not reject decommissioned hosts (default behavior)
+    
cluster.getConfiguration().setBoolean(HConstants.REJECT_DECOMMISSIONED_HOSTS_KEY,
 false);
+
+    master = cluster.addMaster();
+    rs = cluster.addRegionServer();
+    LOG.debug("Starting master: " + master.getMaster().getServerName());
+    master.start();
+    rs.start();
+
+    waitForClusterOnline(master);
+
+    assertEquals(0, 
master.getMaster().listDecommissionedRegionServers().size());
+    assertEquals(0, 
master.getMaster().getServerManager().getDrainingServersList().size());
+    assertEquals(1, 
master.getMaster().getServerManager().getOnlineServers().size());
+
+    // Decommission the region server and tries to re-add it
+    List<ServerName> serversToDecommission = new ArrayList<ServerName>();
+    serversToDecommission.add(rs.getRegionServer().getServerName());
+    master.getMaster().decommissionRegionServers(serversToDecommission, true);

Review Comment:
   It is asynchronous but I can see its results in the following assertions, it 
gets executed in a separate thread. Do you think we need to explicitly add a 
`Thread.sleep` here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to