diff --git src/main/java/org/apache/hadoop/hbase/ServerName.java src/main/java/org/apache/hadoop/hbase/ServerName.java index d5f2fd7..d6d869a 100644 --- src/main/java/org/apache/hadoop/hbase/ServerName.java +++ src/main/java/org/apache/hadoop/hbase/ServerName.java @@ -75,7 +75,8 @@ public class ServerName implements Comparable { private final long startcode; /** - * Cached bytes of this ServerName instance. + * Cached versioned bytes of this ServerName instance. + * @see #getVersionedBytes() */ private byte [] bytes; @@ -121,7 +122,7 @@ public class ServerName implements Comparable { /** * @return {@link #getServerName()} as bytes with a short-sized prefix with - * the {@link ServerName#VERSION} of this class. + * the ServerName#VERSION of this class. */ public synchronized byte [] getVersionedBytes() { if (this.bytes == null) { diff --git src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java index a216a14..db56e6b 100644 --- src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java +++ src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java @@ -29,8 +29,12 @@ import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.NavigableMap; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.CoprocessorEnvironment; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HRegionInfo; @@ -38,8 +42,6 @@ import org.apache.hadoop.hbase.HServerAddress; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; -import org.apache.hadoop.hbase.UnknownRegionException; -import org.apache.hadoop.hbase.CoprocessorEnvironment; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.master.AssignmentManager; @@ -56,6 +58,7 @@ import org.junit.Test; * interface hooks at all appropriate times during normal HMaster operations. */ public class TestMasterObserver { + private static final Log LOG = LogFactory.getLog(TestMasterObserver.class); public static class CPMasterObserver implements MasterObserver { @@ -642,27 +645,37 @@ public class TestMasterObserver { HTable table = UTIL.createTable(TEST_TABLE, TEST_FAMILY); UTIL.createMultiRegions(table, TEST_FAMILY); - - Map regions = table.getRegionsInfo(); - assertFalse(regions.isEmpty()); - Map.Entry firstRegion = - regions.entrySet().iterator().next(); - - // try to force a move + NavigableMap regions = table.getRegionLocations(); + Map.Entry firstGoodPair = null; + for (Map.Entry e: regions.entrySet()) { + if (e.getValue() != null) { + firstGoodPair = e; + break; + } + } + assertNotNull("Found a non-null entry", firstGoodPair); + LOG.info("Found " + firstGoodPair.toString()); + // Try to force a move Collection servers = master.getClusterStatus().getServers(); String destName = null; + String firstRegionHostnamePortStr = firstGoodPair.getValue().toString(); + LOG.info("firstRegionHostnamePortStr=" + firstRegionHostnamePortStr); + boolean found = false; + // Find server that is NOT carrying the first region for (ServerName info : servers) { - HServerAddress hsa = - new HServerAddress(info.getHostname(), info.getPort()); - if (!hsa.equals(firstRegion.getValue())) { + LOG.info("ServerName=" + info); + if (!firstRegionHostnamePortStr.equals(info.getHostAndPort())) { destName = info.toString(); + found = true; break; } } - master.move(firstRegion.getKey().getEncodedNameAsBytes(), - Bytes.toBytes(destName)); + assertTrue("Found server", found); + LOG.info("Found " + destName); + master.move(firstGoodPair.getKey().getEncodedNameAsBytes(), + Bytes.toBytes(destName)); assertTrue("Coprocessor should have been called on region move", - cp.wasMoveCalled()); + cp.wasMoveCalled()); // make sure balancer is on master.balanceSwitch(true);