Class BalancerTestBase

java.lang.Object
org.apache.hadoop.hbase.master.balancer.BalancerTestBase
Direct Known Subclasses:
RSGroupableBalancerTestBase, StochasticBalancerTestBase, TestBalancerStatusTagInJMXMetrics, TestBaseLoadBalancer, TestCacheAwareLoadBalancer, TestFavoredStochasticBalancerPickers, TestFavoredStochasticLoadBalancer, TestSimpleLoadBalancer, TestStochasticBalancerJmxMetrics

public class BalancerTestBase extends Object
Class used to be the base of unit tests on load balancers. It gives helper methods to create maps of ServerName to lists of RegionInfo and to check list of region plans.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int[][]
     
    protected int[][]
     
    protected int[][]
     
    protected static org.apache.hadoop.conf.Configuration
     
    protected int[]
     
    private static final org.slf4j.Logger
     
    (package private) static int
     
    private Queue<org.apache.hadoop.hbase.client.RegionInfo>
     
    private Queue<org.apache.hadoop.hbase.ServerName>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    assertClusterAsBalanced(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> servers)
    Invariant is that all servers have between floor(avg) and ceiling(avg) number of regions.
    boolean
    assertClusterOverallAsBalanced(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> servers, int tablenum)
    Invariant is that all servers have between acceptable range number of regions.
    void
    assertRegionReplicaPlacement(Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> serverMap, org.apache.hadoop.hbase.master.RackManager rackManager)
    Checks whether region replicas are not hosted on the same host.
    protected List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad>
    convertToList(Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> servers)
     
    protected List<org.apache.hadoop.hbase.client.RegionInfo>
    createRegions(int numRegions, org.apache.hadoop.hbase.TableName tableName)
     
    protected Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>>
    createServerMap(int numNodes, int numRegions, int numRegionsPerServer, int replication, int numTables)
     
    protected org.apache.hadoop.hbase.master.balancer.BalancerClusterState
    mockCluster(int[] mockCluster)
     
    protected TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>>
    mockClusterServers(int[] mockCluster)
     
    protected TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>>
    mockClusterServers(int[][] mockCluster)
     
    protected TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>>
    mockClusterServers(int[] mockCluster, int numTables)
     
    protected Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>>
    mockClusterServersUnsorted(int[] mockCluster, int numTables)
     
    protected HashMap<org.apache.hadoop.hbase.TableName,TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>>>
    mockClusterServersWithTables(Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> clusterServers)
     
    protected TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>>
    mockUniformClusterServers(int[] mockCluster)
     
    protected String
    printMock(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> balancedCluster)
     
    protected String
    printStats(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> servers)
     
    protected List<org.apache.hadoop.hbase.client.RegionInfo>
    randomRegions(int numRegions)
     
    protected List<org.apache.hadoop.hbase.client.RegionInfo>
    randomRegions(int numRegions, int numTables)
     
    protected org.apache.hadoop.hbase.master.balancer.ServerAndLoad
    randomServer(int numRegionsPerServer)
     
    protected List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad>
    randomServers(int numServers, int numRegionsPerServer)
     
    protected List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad>
    reconcile(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> list, List<org.apache.hadoop.hbase.master.RegionPlan> plans, Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> servers)
    This assumes the RegionPlan HSI instances are the same ones in the map, so actually no need to even pass in the map, but I think it's clearer.
    protected void
    returnRegions(List<org.apache.hadoop.hbase.client.RegionInfo> regions)
     
    protected void
    returnServer(org.apache.hadoop.hbase.ServerName server)
     
    protected void
    returnServers(List<org.apache.hadoop.hbase.ServerName> servers)
     
    protected List<org.apache.hadoop.hbase.client.RegionInfo>
    uniformRegions(int numRegions)
     
    protected void
    updateLoad(Map<org.apache.hadoop.hbase.ServerName,org.apache.hadoop.hbase.master.balancer.ServerAndLoad> map, org.apache.hadoop.hbase.ServerName sn, int diff)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • assertClusterAsBalanced

      public void assertClusterAsBalanced(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> servers)
      Invariant is that all servers have between floor(avg) and ceiling(avg) number of regions.
    • assertClusterOverallAsBalanced

      public boolean assertClusterOverallAsBalanced(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> servers, int tablenum)
      Invariant is that all servers have between acceptable range number of regions.
    • assertRegionReplicaPlacement

      public void assertRegionReplicaPlacement(Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> serverMap, org.apache.hadoop.hbase.master.RackManager rackManager)
      Checks whether region replicas are not hosted on the same host.
    • printStats

      protected String printStats(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> servers)
    • convertToList

      protected List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> convertToList(Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> servers)
    • printMock

      protected String printMock(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> balancedCluster)
    • reconcile

      protected List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> reconcile(List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> list, List<org.apache.hadoop.hbase.master.RegionPlan> plans, Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> servers)
      This assumes the RegionPlan HSI instances are the same ones in the map, so actually no need to even pass in the map, but I think it's clearer.
      Returns:
      a list of all added ServerAndLoad values.
    • updateLoad

      protected void updateLoad(Map<org.apache.hadoop.hbase.ServerName,org.apache.hadoop.hbase.master.balancer.ServerAndLoad> map, org.apache.hadoop.hbase.ServerName sn, int diff)
    • mockClusterServers

      protected TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> mockClusterServers(int[][] mockCluster)
    • mockClusterServers

      protected TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> mockClusterServers(int[] mockCluster)
    • mockCluster

      protected org.apache.hadoop.hbase.master.balancer.BalancerClusterState mockCluster(int[] mockCluster)
    • mockClusterServers

      protected TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> mockClusterServers(int[] mockCluster, int numTables)
    • mockClusterServersUnsorted

      protected Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> mockClusterServersUnsorted(int[] mockCluster, int numTables)
    • mockUniformClusterServers

      protected TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> mockUniformClusterServers(int[] mockCluster)
    • mockClusterServersWithTables

      protected HashMap<org.apache.hadoop.hbase.TableName,TreeMap<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>>> mockClusterServersWithTables(Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> clusterServers)
    • randomRegions

      protected List<org.apache.hadoop.hbase.client.RegionInfo> randomRegions(int numRegions)
    • createRegions

      protected List<org.apache.hadoop.hbase.client.RegionInfo> createRegions(int numRegions, org.apache.hadoop.hbase.TableName tableName)
    • randomRegions

      protected List<org.apache.hadoop.hbase.client.RegionInfo> randomRegions(int numRegions, int numTables)
    • uniformRegions

      protected List<org.apache.hadoop.hbase.client.RegionInfo> uniformRegions(int numRegions)
    • returnRegions

      protected void returnRegions(List<org.apache.hadoop.hbase.client.RegionInfo> regions)
    • randomServer

      protected org.apache.hadoop.hbase.master.balancer.ServerAndLoad randomServer(int numRegionsPerServer)
    • randomServers

      protected List<org.apache.hadoop.hbase.master.balancer.ServerAndLoad> randomServers(int numServers, int numRegionsPerServer)
    • returnServer

      protected void returnServer(org.apache.hadoop.hbase.ServerName server)
    • returnServers

      protected void returnServers(List<org.apache.hadoop.hbase.ServerName> servers)
    • createServerMap

      protected Map<org.apache.hadoop.hbase.ServerName,List<org.apache.hadoop.hbase.client.RegionInfo>> createServerMap(int numNodes, int numRegions, int numRegionsPerServer, int replication, int numTables)