Search in sources :

Example 1 with MasterAddressTracker

use of org.apache.hadoop.hbase.zookeeper.MasterAddressTracker in project hbase by apache.

the class TestRSStatusServlet method setupBasicMocks.

@Before
public void setupBasicMocks() throws IOException, ServiceException {
    rs = Mockito.mock(HRegionServer.class);
    rpcServices = Mockito.mock(RSRpcServices.class);
    rpcServer = Mockito.mock(RpcServerInterface.class);
    Mockito.doReturn(HBaseConfiguration.create()).when(rs).getConfiguration();
    Mockito.doReturn(rpcServices).when(rs).getRSRpcServices();
    Mockito.doReturn(rpcServer).when(rs).getRpcServer();
    Mockito.doReturn(fakeResponse).when(rpcServices).getServerInfo((RpcController) Mockito.any(), (GetServerInfoRequest) Mockito.any());
    // Fake ZKW
    ZooKeeperWatcher zkw = Mockito.mock(ZooKeeperWatcher.class);
    Mockito.doReturn("fakequorum").when(zkw).getQuorum();
    Mockito.doReturn(zkw).when(rs).getZooKeeper();
    // Fake CacheConfig
    LOG.warn("The " + HConstants.HFILE_BLOCK_CACHE_SIZE_KEY + " is set to 0");
    CacheConfig cacheConf = Mockito.mock(CacheConfig.class);
    Mockito.doReturn(null).when(cacheConf).getBlockCache();
    Mockito.doReturn(cacheConf).when(rs).getCacheConfig();
    // Fake MasterAddressTracker
    MasterAddressTracker mat = Mockito.mock(MasterAddressTracker.class);
    Mockito.doReturn(fakeMasterAddress).when(mat).getMasterAddress();
    Mockito.doReturn(mat).when(rs).getMasterAddressTracker();
    MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class);
    Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper();
    Mockito.doReturn(rms).when(rs).getRegionServerMetrics();
    MetricsHBaseServer ms = Mockito.mock(MetricsHBaseServer.class);
    Mockito.doReturn(new MetricsHBaseServerWrapperStub()).when(ms).getHBaseServerWrapper();
    Mockito.doReturn(ms).when(rpcServer).getMetrics();
}
Also used : MasterAddressTracker(org.apache.hadoop.hbase.zookeeper.MasterAddressTracker) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) RpcServerInterface(org.apache.hadoop.hbase.ipc.RpcServerInterface) CacheConfig(org.apache.hadoop.hbase.io.hfile.CacheConfig) MetricsHBaseServer(org.apache.hadoop.hbase.ipc.MetricsHBaseServer) MetricsHBaseServerWrapperStub(org.apache.hadoop.hbase.ipc.MetricsHBaseServerWrapperStub) Before(org.junit.Before)

Example 2 with MasterAddressTracker

use of org.apache.hadoop.hbase.zookeeper.MasterAddressTracker in project hbase by apache.

the class TestMasterAddressTracker method testMasterAddressTrackerFromZK.

/**
   * Unit tests that uses ZooKeeper but does not use the master-side methods
   * but rather acts directly on ZK.
   * @throws Exception
   */
@Test
public void testMasterAddressTrackerFromZK() throws Exception {
    // Create the master node with a dummy address
    final int infoPort = 1235;
    final ServerName sn = ServerName.valueOf("localhost", 1234, System.currentTimeMillis());
    final MasterAddressTracker addressTracker = setupMasterTracker(sn, infoPort);
    try {
        assertTrue(addressTracker.hasMaster());
        ServerName pulledAddress = addressTracker.getMasterAddress();
        assertTrue(pulledAddress.equals(sn));
        assertEquals(infoPort, addressTracker.getMasterInfoPort());
    } finally {
        assertTrue("Couldn't clean up master", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), sn.toString()));
    }
}
Also used : MasterAddressTracker(org.apache.hadoop.hbase.zookeeper.MasterAddressTracker) Test(org.junit.Test)

Example 3 with MasterAddressTracker

use of org.apache.hadoop.hbase.zookeeper.MasterAddressTracker in project hbase by apache.

the class TestMasterAddressTracker method testNoMaster.

@Test
public void testNoMaster() throws Exception {
    final MasterAddressTracker addressTracker = setupMasterTracker(null, 1772);
    assertFalse(addressTracker.hasMaster());
    assertNull("should get null master when none active.", addressTracker.getMasterAddress());
    assertEquals("Should receive 0 for backup not found.", 0, addressTracker.getMasterInfoPort());
}
Also used : MasterAddressTracker(org.apache.hadoop.hbase.zookeeper.MasterAddressTracker) Test(org.junit.Test)

Example 4 with MasterAddressTracker

use of org.apache.hadoop.hbase.zookeeper.MasterAddressTracker in project hbase by apache.

the class TestMasterAddressTracker method testNoBackups.

@Test
public void testNoBackups() throws Exception {
    final ServerName sn = ServerName.valueOf("localhost", 1234, System.currentTimeMillis());
    final MasterAddressTracker addressTracker = setupMasterTracker(sn, 1772);
    try {
        assertEquals("Should receive 0 for backup not found.", 0, addressTracker.getBackupMasterInfoPort(ServerName.valueOf("doesnotexist.example.com", 1234, System.currentTimeMillis())));
    } finally {
        assertTrue("Couldn't clean up master", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), sn.toString()));
    }
}
Also used : MasterAddressTracker(org.apache.hadoop.hbase.zookeeper.MasterAddressTracker) Test(org.junit.Test)

Example 5 with MasterAddressTracker

use of org.apache.hadoop.hbase.zookeeper.MasterAddressTracker in project hbase by apache.

the class TestMasterStatusServlet method setupBasicMocks.

@Before
public void setupBasicMocks() {
    conf = HBaseConfiguration.create();
    master = Mockito.mock(HMaster.class);
    Mockito.doReturn(FAKE_HOST).when(master).getServerName();
    Mockito.doReturn(conf).when(master).getConfiguration();
    //Fake DeadServer
    DeadServer deadServer = Mockito.mock(DeadServer.class);
    // Fake serverManager
    ServerManager serverManager = Mockito.mock(ServerManager.class);
    Mockito.doReturn(1.0).when(serverManager).getAverageLoad();
    Mockito.doReturn(serverManager).when(master).getServerManager();
    Mockito.doReturn(deadServer).when(serverManager).getDeadServers();
    // Fake AssignmentManager and RIT
    AssignmentManager am = Mockito.mock(AssignmentManager.class);
    RegionStates rs = Mockito.mock(RegionStates.class);
    Set<RegionState> regionsInTransition = new HashSet<>();
    regionsInTransition.add(new RegionState(FAKE_HRI, RegionState.State.CLOSING, 12345L, FAKE_HOST));
    Mockito.doReturn(rs).when(am).getRegionStates();
    Mockito.doReturn(regionsInTransition).when(rs).getRegionsInTransition();
    Mockito.doReturn(am).when(master).getAssignmentManager();
    Mockito.doReturn(serverManager).when(master).getServerManager();
    // Fake ZKW
    ZooKeeperWatcher zkw = Mockito.mock(ZooKeeperWatcher.class);
    Mockito.doReturn(new ZNodePaths(conf)).when(zkw).getZNodePaths();
    Mockito.doReturn("fakequorum").when(zkw).getQuorum();
    Mockito.doReturn(zkw).when(master).getZooKeeper();
    // Fake MasterAddressTracker
    MasterAddressTracker tracker = Mockito.mock(MasterAddressTracker.class);
    Mockito.doReturn(tracker).when(master).getMasterAddressTracker();
    Mockito.doReturn(FAKE_HOST).when(tracker).getMasterAddress();
    MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class);
    Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper();
    Mockito.doReturn(rms).when(master).getRegionServerMetrics();
    // Mock admin
    admin = Mockito.mock(Admin.class);
}
Also used : MetricsRegionServerWrapperStub(org.apache.hadoop.hbase.regionserver.MetricsRegionServerWrapperStub) MetricsRegionServer(org.apache.hadoop.hbase.regionserver.MetricsRegionServer) Admin(org.apache.hadoop.hbase.client.Admin) MasterAddressTracker(org.apache.hadoop.hbase.zookeeper.MasterAddressTracker) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ZNodePaths(org.apache.hadoop.hbase.zookeeper.ZNodePaths) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

MasterAddressTracker (org.apache.hadoop.hbase.zookeeper.MasterAddressTracker)8 Test (org.junit.Test)4 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)3 Before (org.junit.Before)3 MetricsHBaseServer (org.apache.hadoop.hbase.ipc.MetricsHBaseServer)2 MetricsHBaseServerWrapperStub (org.apache.hadoop.hbase.ipc.MetricsHBaseServerWrapperStub)2 RpcServerInterface (org.apache.hadoop.hbase.ipc.RpcServerInterface)2 MetricsRegionServer (org.apache.hadoop.hbase.regionserver.MetricsRegionServer)2 MetricsRegionServerWrapperStub (org.apache.hadoop.hbase.regionserver.MetricsRegionServerWrapperStub)2 HashSet (java.util.HashSet)1 Admin (org.apache.hadoop.hbase.client.Admin)1 CacheConfig (org.apache.hadoop.hbase.io.hfile.CacheConfig)1 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)1 RSRpcServices (org.apache.hadoop.hbase.regionserver.RSRpcServices)1 ZKWatcher (org.apache.hadoop.hbase.zookeeper.ZKWatcher)1 ZNodePaths (org.apache.hadoop.hbase.zookeeper.ZNodePaths)1