当前位置: 首页>>代码示例>>Java>>正文


Java HConnectionTestingUtility.getMockedConnectionAndDecorate方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.client.HConnectionTestingUtility.getMockedConnectionAndDecorate方法的典型用法代码示例。如果您正苦于以下问题:Java HConnectionTestingUtility.getMockedConnectionAndDecorate方法的具体用法?Java HConnectionTestingUtility.getMockedConnectionAndDecorate怎么用?Java HConnectionTestingUtility.getMockedConnectionAndDecorate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.client.HConnectionTestingUtility的用法示例。


在下文中一共展示了HConnectionTestingUtility.getMockedConnectionAndDecorate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MockServer

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
MockServer(final HBaseTestingUtility htu)
throws NotAllMetaRegionsOnlineException, IOException, InterruptedException {
  this.c = htu.getConfiguration();
  // Mock an HConnection and a HRegionInterface implementation.  Have the
  // HConnection return the HRI.  Have the HRI return a few mocked up responses
  // to make our test work.
  this.connection =
    HConnectionTestingUtility.getMockedConnectionAndDecorate(this.c,
      Mockito.mock(HRegionInterface.class),
      new ServerName("example.org,12345,6789"),
      HRegionInfo.FIRST_META_REGIONINFO);
  // Set hbase.rootdir into test dir.
  FileSystem fs = FileSystem.get(this.c);
  Path rootdir = fs.makeQualified(new Path(this.c.get(HConstants.HBASE_DIR)));
  this.c.set(HConstants.HBASE_DIR, rootdir.toString());
  this.ct = Mockito.mock(CatalogTracker.class);
  HRegionInterface hri = Mockito.mock(HRegionInterface.class);
  Mockito.when(this.ct.getConnection()).thenReturn(this.connection);
  Mockito.when(ct.waitForMetaServerConnection(Mockito.anyLong())).thenReturn(hri);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:21,代码来源:TestCatalogJanitor.java

示例2: MockServer

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
MockServer(final HBaseTestingUtility htu)
throws NotAllMetaRegionsOnlineException, IOException, InterruptedException {
  this.c = htu.getConfiguration();
  ClientProtos.ClientService.BlockingInterface ri =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
  MutateResponse.Builder builder = MutateResponse.newBuilder();
  builder.setProcessed(true);
  try {
    Mockito.when(ri.mutate(
      (RpcController)Mockito.any(), (MutateRequest)Mockito.any())).
        thenReturn(builder.build());
  } catch (ServiceException se) {
    throw ProtobufUtil.getRemoteException(se);
  }
  // Mock an HConnection and a AdminProtocol implementation.  Have the
  // HConnection return the HRI.  Have the HRI return a few mocked up responses
  // to make our test work.
  this.connection =
    HConnectionTestingUtility.getMockedConnectionAndDecorate(this.c,
      Mockito.mock(AdminProtos.AdminService.BlockingInterface.class), ri,
        ServerName.valueOf("example.org,12345,6789"),
      HRegionInfo.FIRST_META_REGIONINFO);
  // Set hbase.rootdir into test dir.
  FileSystem fs = FileSystem.get(this.c);
  Path rootdir = FSUtils.getRootDir(this.c);
  FSUtils.setRootDir(this.c, rootdir);
  this.ct = Mockito.mock(CatalogTracker.class);
  AdminProtos.AdminService.BlockingInterface hri =
    Mockito.mock(AdminProtos.AdminService.BlockingInterface.class);
  Mockito.when(this.ct.getConnection()).thenReturn(this.connection);
  Mockito.when(ct.waitForMetaServerConnection(Mockito.anyLong())).thenReturn(hri);
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:33,代码来源:TestCatalogJanitor.java

示例3: MockServer

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
MockServer(final HBaseTestingUtility htu)
throws NotAllMetaRegionsOnlineException, IOException, InterruptedException {
  this.c = htu.getConfiguration();
  ClientProtocol ri = Mockito.mock(ClientProtocol.class);
  MutateResponse.Builder builder = MutateResponse.newBuilder();
  builder.setProcessed(true);
  try {
    Mockito.when(ri.mutate(
      (RpcController)Mockito.any(), (MutateRequest)Mockito.any())).
        thenReturn(builder.build());
  } catch (ServiceException se) {
    throw ProtobufUtil.getRemoteException(se);
  }
  // Mock an HConnection and a AdminProtocol implementation.  Have the
  // HConnection return the HRI.  Have the HRI return a few mocked up responses
  // to make our test work.
  this.connection =
    HConnectionTestingUtility.getMockedConnectionAndDecorate(this.c,
      Mockito.mock(AdminProtocol.class), ri,
      new ServerName("example.org,12345,6789"),
      HRegionInfo.FIRST_META_REGIONINFO);
  // Set hbase.rootdir into test dir.
  FileSystem fs = FileSystem.get(this.c);
  Path rootdir = fs.makeQualified(new Path(this.c.get(HConstants.HBASE_DIR)));
  this.c.set(HConstants.HBASE_DIR, rootdir.toString());
  this.ct = Mockito.mock(CatalogTracker.class);
  AdminProtocol hri = Mockito.mock(AdminProtocol.class);
  Mockito.when(this.ct.getConnection()).thenReturn(this.connection);
  Mockito.when(ct.waitForMetaServerConnectionDefault()).thenReturn(hri);
}
 
开发者ID:daidong,项目名称:DominoHBase,代码行数:31,代码来源:TestCatalogJanitor.java

示例4: testNotPullingDeadRegionServerFromZK

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
@Test
public void testNotPullingDeadRegionServerFromZK()
    throws IOException, KeeperException, InterruptedException {
  final Configuration conf = TESTUTIL.getConfiguration();
  final ServerName newServer = ServerName.valueOf("test.sample", 1, 101);
  final ServerName deadServer = ServerName.valueOf("test.sample", 1, 100);
  final MockRegionServer rs0 = new MockRegionServer(conf, newServer);

  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TESTUTIL.getConfiguration());
  HMaster master = new HMaster(conf, cp) {
    @Override
    void assignMeta(MonitoredTask status, Set<ServerName> previouslyFailedMeatRSs, int replicaId)
    { }

    @Override
    void initializeZKBasedSystemTrackers() throws IOException,
    InterruptedException, KeeperException, CoordinatedStateException {
      super.initializeZKBasedSystemTrackers();
      // Record a newer server in server manager at first
      serverManager.recordNewServerWithLock(newServer, ServerLoad.EMPTY_SERVERLOAD);

      List<ServerName> onlineServers = new ArrayList<ServerName>();
      onlineServers.add(deadServer);
      onlineServers.add(newServer);
      // Mock the region server tracker to pull the dead server from zk
      regionServerTracker = Mockito.spy(regionServerTracker);
      Mockito.doReturn(onlineServers).when(
        regionServerTracker).getOnlineServers();
    }

    @Override
    public ClusterConnection getConnection() {
      // Insert a mock for the connection, use TESTUTIL.getConfiguration rather than
      // the conf from the master; the conf will already have an HConnection
      // associate so the below mocking of a connection will fail.
      try {
        return HConnectionTestingUtility.getMockedConnectionAndDecorate(
          TESTUTIL.getConfiguration(), rs0, rs0, rs0.getServerName(),
          HRegionInfo.FIRST_META_REGIONINFO);
      } catch (IOException e) {
        return null;
      }
    }

    @Override
    void initNamespace() {
    }
  };
  master.start();

  try {
    // Wait till master is initialized.
    while (!master.isInitialized()) Threads.sleep(10);
    LOG.info("Master is initialized");

    assertFalse("The dead server should not be pulled in",
      master.serverManager.isServerOnline(deadServer));
  } finally {
    master.stopMaster();
    master.join();
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:64,代码来源:TestMasterNoCluster.java

示例5: setUpMockedAssignmentManager

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * Create an {@link AssignmentManagerWithExtrasForTesting} that has mocked
 * {@link CatalogTracker} etc.
 * @param server
 * @param manager
 * @return An AssignmentManagerWithExtras with mock connections, etc.
 * @throws IOException
 * @throws KeeperException
 */
private AssignmentManagerWithExtrasForTesting setUpMockedAssignmentManager(final Server server,
    final ServerManager manager)
throws IOException, KeeperException {
  // We need a mocked catalog tracker. Its used by our AM instance.
  CatalogTracker ct = Mockito.mock(CatalogTracker.class);
  // Make an RS Interface implementation. Make it so a scanner can go against
  // it and a get to return the single region, REGIONINFO, this test is
  // messing with. Needed when "new master" joins cluster. AM will try and
  // rebuild its list of user regions and it will also get the HRI that goes
  // with an encoded name by doing a Get on .META.
  HRegionInterface ri = Mockito.mock(HRegionInterface.class);
  // Get a meta row result that has region up on SERVERNAME_A for REGIONINFO
  Result[] result = null;
  if (enabling) {
    result = new Result[2];
    result[0] = getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
    result[1] = getMetaTableRowResult(REGIONINFO_2, SERVERNAME_A);
  }
  Result r = getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
  Mockito.when(ri .openScanner((byte[]) Mockito.any(), (Scan) Mockito.any())).
    thenReturn(System.currentTimeMillis());
 if (enabling) {
    Mockito.when(ri.next(Mockito.anyLong(), Mockito.anyInt())).thenReturn(result, result, result,
        (Result[]) null);
    // If a get, return the above result too for REGIONINFO_2
    Mockito.when(ri.get((byte[]) Mockito.any(), (Get) Mockito.any())).thenReturn(
        getMetaTableRowResult(REGIONINFO_2, SERVERNAME_A));
  } else {
    // Return good result 'r' first and then return null to indicate end of scan
    Mockito.when(ri.next(Mockito.anyLong(), Mockito.anyInt())).thenReturn(new Result[] { r });
    // If a get, return the above result too for REGIONINFO
    Mockito.when(ri.get((byte[]) Mockito.any(), (Get) Mockito.any())).thenReturn(r);
  }
  // Get a connection w/ mocked up common methods.
  HConnection connection = HConnectionTestingUtility.
    getMockedConnectionAndDecorate(HTU.getConfiguration(), ri, SERVERNAME_B,
      REGIONINFO);
  // Make it so we can get the connection from our mocked catalogtracker
  Mockito.when(ct.getConnection()).thenReturn(connection);
  // Create and startup an executor. Used by AM handling zk callbacks.
  ExecutorService executor = startupMasterExecutor("mockedAMExecutor");
  this.balancer = LoadBalancerFactory.getLoadBalancer(server.getConfiguration());
  AssignmentManagerWithExtrasForTesting am = new AssignmentManagerWithExtrasForTesting(
      server, manager, ct, balancer, executor);
  return am;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:56,代码来源:TestAssignmentManager.java

示例6: testNotPullingDeadRegionServerFromZK

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
@Test
public void testNotPullingDeadRegionServerFromZK()
    throws IOException, KeeperException, InterruptedException {
  final Configuration conf = TESTUTIL.getConfiguration();
  final ServerName newServer = ServerName.valueOf("test.sample", 1, 101);
  final ServerName deadServer = ServerName.valueOf("test.sample", 1, 100);
  final MockRegionServer rs0 = new MockRegionServer(conf, newServer);

  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TESTUTIL.getConfiguration());
  HMaster master = new HMaster(conf, cp) {
    @Override
    void assignMeta(MonitoredTask status, Set<ServerName> previouslyFailedMeatRSs) {
    }

    @Override
    void initializeZKBasedSystemTrackers() throws IOException,
    InterruptedException, KeeperException, CoordinatedStateException {
      super.initializeZKBasedSystemTrackers();
      // Record a newer server in server manager at first
      serverManager.recordNewServerWithLock(newServer, ServerLoad.EMPTY_SERVERLOAD);

      List<ServerName> onlineServers = new ArrayList<ServerName>();
      onlineServers.add(deadServer);
      onlineServers.add(newServer);
      // Mock the region server tracker to pull the dead server from zk
      regionServerTracker = Mockito.spy(regionServerTracker);
      Mockito.doReturn(onlineServers).when(
        regionServerTracker).getOnlineServers();
    }

    @Override
    public ClusterConnection getConnection() {
      // Insert a mock for the connection, use TESTUTIL.getConfiguration rather than
      // the conf from the master; the conf will already have an HConnection
      // associate so the below mocking of a connection will fail.
      try {
        return HConnectionTestingUtility.getMockedConnectionAndDecorate(
          TESTUTIL.getConfiguration(), rs0, rs0, rs0.getServerName(),
          HRegionInfo.FIRST_META_REGIONINFO);
      } catch (IOException e) {
        return null;
      }
    }

    @Override
    void initNamespace() {
    }
  };
  master.start();

  try {
    // Wait till master is initialized.
    while (!master.initialized) Threads.sleep(10);
    LOG.info("Master is initialized");

    assertFalse("The dead server should not be pulled in",
      master.serverManager.isServerOnline(deadServer));
  } finally {
    master.stopMaster();
    master.join();
  }
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:64,代码来源:TestMasterNoCluster.java

示例7: processServerShutdownHandler

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
private void processServerShutdownHandler(AssignmentManager am, boolean splitRegion)
    throws IOException, ServiceException {
  // Make sure our new AM gets callbacks; once registered, can't unregister.
  // Thats ok because we make a new zk watcher for each test.
  this.watcher.registerListenerFirst(am);

  // Need to set up a fake scan of meta for the servershutdown handler
  // Make an RS Interface implementation.  Make it so a scanner can go against it.
  ClientProtos.ClientService.BlockingInterface implementation =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
  // Get a meta row result that has region up on SERVERNAME_A

  Result r;
  if (splitRegion) {
    r = MetaMockingUtil.getMetaTableRowResultAsSplitRegion(REGIONINFO, SERVERNAME_A);
  } else {
    r = MetaMockingUtil.getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
  }

  final ScanResponse.Builder builder = ScanResponse.newBuilder();
  builder.setMoreResults(true);
  builder.addCellsPerResult(r.size());
  final List<CellScannable> cellScannables = new ArrayList<CellScannable>(1);
  cellScannables.add(r);
  Mockito.when(implementation.scan(
    (RpcController)Mockito.any(), (ScanRequest)Mockito.any())).
    thenAnswer(new Answer<ScanResponse>() {
        @Override
        public ScanResponse answer(InvocationOnMock invocation) throws Throwable {
          PayloadCarryingRpcController controller = (PayloadCarryingRpcController) invocation
              .getArguments()[0];
          if (controller != null) {
            controller.setCellScanner(CellUtil.createCellScanner(cellScannables));
          }
          return builder.build();
        }
    });

  // Get a connection w/ mocked up common methods.
  ClusterConnection connection =
    HConnectionTestingUtility.getMockedConnectionAndDecorate(HTU.getConfiguration(),
      null, implementation, SERVERNAME_B, REGIONINFO);
  // These mocks were done up when all connections were managed.  World is different now we
  // moved to unmanaged connections.  It messes up the intercepts done in these tests.
  // Just mark connections as marked and then down in MetaTableAccessor, it will go the path
  // that picks up the above mocked up 'implementation' so 'scans' of meta return the expected
  // result.  Redo in new realm of unmanaged connections.
  Mockito.when(connection.isManaged()).thenReturn(true);
  try {
    // Make it so we can get a catalogtracker from servermanager.. .needed
    // down in guts of server shutdown handler.
    Mockito.when(this.server.getConnection()).thenReturn(connection);

    // Now make a server shutdown handler instance and invoke process.
    // Have it that SERVERNAME_A died.
    DeadServer deadServers = new DeadServer();
    deadServers.add(SERVERNAME_A);
    // I need a services instance that will return the AM
    MasterFileSystem fs = Mockito.mock(MasterFileSystem.class);
    Mockito.doNothing().when(fs).setLogRecoveryMode();
    Mockito.when(fs.getLogRecoveryMode()).thenReturn(RecoveryMode.LOG_REPLAY);
    MasterServices services = Mockito.mock(MasterServices.class);
    Mockito.when(services.getAssignmentManager()).thenReturn(am);
    Mockito.when(services.getServerManager()).thenReturn(this.serverManager);
    Mockito.when(services.getZooKeeper()).thenReturn(this.watcher);
    Mockito.when(services.getMasterFileSystem()).thenReturn(fs);
    Mockito.when(services.getConnection()).thenReturn(connection);
    ServerShutdownHandler handler = new ServerShutdownHandler(this.server,
        services, deadServers, SERVERNAME_A, false);
    am.failoverCleanupDone.set(true);
    handler.process();
    // The region in r will have been assigned.  It'll be up in zk as unassigned.
  } finally {
    if (connection != null) connection.close();
  }
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:77,代码来源:TestAssignmentManager.java

示例8: setUpMockedAssignmentManager

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * Create an {@link AssignmentManagerWithExtrasForTesting} that has mocked
 * {@link CatalogTracker} etc.
 * @param server
 * @param manager
 * @return An AssignmentManagerWithExtras with mock connections, etc.
 * @throws IOException
 * @throws KeeperException
 */
private AssignmentManagerWithExtrasForTesting setUpMockedAssignmentManager(final Server server,
    final ServerManager manager) throws IOException, KeeperException,
      ServiceException, CoordinatedStateException {
  // Make an RS Interface implementation. Make it so a scanner can go against
  // it and a get to return the single region, REGIONINFO, this test is
  // messing with. Needed when "new master" joins cluster. AM will try and
  // rebuild its list of user regions and it will also get the HRI that goes
  // with an encoded name by doing a Get on hbase:meta
  ClientProtos.ClientService.BlockingInterface ri =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
  // Get a meta row result that has region up on SERVERNAME_A for REGIONINFO
  Result r = MetaMockingUtil.getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
  final ScanResponse.Builder builder = ScanResponse.newBuilder();
  builder.setMoreResults(true);
  builder.addCellsPerResult(r.size());
  final List<CellScannable> rows = new ArrayList<CellScannable>(1);
  rows.add(r);
  Answer<ScanResponse> ans = new Answer<ClientProtos.ScanResponse>() {
    @Override
    public ScanResponse answer(InvocationOnMock invocation) throws Throwable {
      PayloadCarryingRpcController controller = (PayloadCarryingRpcController) invocation
          .getArguments()[0];
      if (controller != null) {
        controller.setCellScanner(CellUtil.createCellScanner(rows));
      }
      return builder.build();
    }
  };
  if (enabling) {
    Mockito.when(ri.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any()))
        .thenAnswer(ans).thenAnswer(ans).thenAnswer(ans).thenAnswer(ans).thenAnswer(ans)
        .thenReturn(ScanResponse.newBuilder().setMoreResults(false).build());
  } else {
    Mockito.when(ri.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any())).thenAnswer(
        ans);
  }
  // If a get, return the above result too for REGIONINFO
  GetResponse.Builder getBuilder = GetResponse.newBuilder();
  getBuilder.setResult(ProtobufUtil.toResult(r));
  Mockito.when(ri.get((RpcController)Mockito.any(), (GetRequest) Mockito.any())).
    thenReturn(getBuilder.build());
  // Get a connection w/ mocked up common methods.
  ClusterConnection connection = (ClusterConnection)HConnectionTestingUtility.
    getMockedConnectionAndDecorate(HTU.getConfiguration(), null,
      ri, SERVERNAME_B, REGIONINFO);
  // These mocks were done up when all connections were managed.  World is different now we
  // moved to unmanaged connections.  It messes up the intercepts done in these tests.
  // Just mark connections as marked and then down in MetaTableAccessor, it will go the path
  // that picks up the above mocked up 'implementation' so 'scans' of meta return the expected
  // result.  Redo in new realm of unmanaged connections.
  Mockito.when(connection.isManaged()).thenReturn(true);
  // Make it so we can get the connection from our mocked catalogtracker
  // Create and startup an executor. Used by AM handling zk callbacks.
  ExecutorService executor = startupMasterExecutor("mockedAMExecutor");
  this.balancer = LoadBalancerFactory.getLoadBalancer(server.getConfiguration());
  AssignmentManagerWithExtrasForTesting am = new AssignmentManagerWithExtrasForTesting(
    server, connection, manager, this.balancer, executor, new NullTableLockManager());
  return am;
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:69,代码来源:TestAssignmentManager.java

示例9: processServerShutdownHandler

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
private void processServerShutdownHandler(CatalogTracker ct, AssignmentManager am, boolean splitRegion)
    throws IOException, ServiceException {
  // Make sure our new AM gets callbacks; once registered, can't unregister.
  // Thats ok because we make a new zk watcher for each test.
  this.watcher.registerListenerFirst(am);

  // Need to set up a fake scan of meta for the servershutdown handler
  // Make an RS Interface implementation.  Make it so a scanner can go against it.
  ClientProtos.ClientService.BlockingInterface implementation =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
  // Get a meta row result that has region up on SERVERNAME_A

  Result r;
  if (splitRegion) {
    r = MetaMockingUtil.getMetaTableRowResultAsSplitRegion(REGIONINFO, SERVERNAME_A);
  } else {
    r = MetaMockingUtil.getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
  }

  final ScanResponse.Builder builder = ScanResponse.newBuilder();
  builder.setMoreResults(true);
  builder.addCellsPerResult(r.size());
  final List<CellScannable> cellScannables = new ArrayList<CellScannable>(1);
  cellScannables.add(r);
  Mockito.when(implementation.scan(
    (RpcController)Mockito.any(), (ScanRequest)Mockito.any())).
    thenAnswer(new Answer<ScanResponse>() {
        @Override
        public ScanResponse answer(InvocationOnMock invocation) throws Throwable {
          PayloadCarryingRpcController controller = (PayloadCarryingRpcController) invocation
              .getArguments()[0];
          if (controller != null) {
            controller.setCellScanner(CellUtil.createCellScanner(cellScannables));
          }
          return builder.build();
        }
    });

  // Get a connection w/ mocked up common methods.
  HConnection connection =
    HConnectionTestingUtility.getMockedConnectionAndDecorate(HTU.getConfiguration(),
      null, implementation, SERVERNAME_B, REGIONINFO);

  // Make it so we can get a catalogtracker from servermanager.. .needed
  // down in guts of server shutdown handler.
  Mockito.when(ct.getConnection()).thenReturn(connection);
  Mockito.when(this.server.getCatalogTracker()).thenReturn(ct);

  // Now make a server shutdown handler instance and invoke process.
  // Have it that SERVERNAME_A died.
  DeadServer deadServers = new DeadServer();
  deadServers.add(SERVERNAME_A);
  // I need a services instance that will return the AM
  MasterServices services = Mockito.mock(MasterServices.class);
  Mockito.when(services.getAssignmentManager()).thenReturn(am);
  Mockito.when(services.getServerManager()).thenReturn(this.serverManager);
  Mockito.when(services.getZooKeeper()).thenReturn(this.watcher);
  ServerShutdownHandler handler = new ServerShutdownHandler(this.server,
    services, deadServers, SERVERNAME_A, false);
  am.failoverCleanupDone.set(true);
  handler.process();
  // The region in r will have been assigned.  It'll be up in zk as unassigned.
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:64,代码来源:TestAssignmentManager.java

示例10: setUpMockedAssignmentManager

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * Create an {@link AssignmentManagerWithExtrasForTesting} that has mocked
 * {@link CatalogTracker} etc.
 * @param server
 * @param manager
 * @return An AssignmentManagerWithExtras with mock connections, etc.
 * @throws IOException
 * @throws KeeperException
 */
private AssignmentManagerWithExtrasForTesting setUpMockedAssignmentManager(final Server server,
    final ServerManager manager) throws IOException, KeeperException, ServiceException {
  // We need a mocked catalog tracker. Its used by our AM instance.
  CatalogTracker ct = Mockito.mock(CatalogTracker.class);
  // Make an RS Interface implementation. Make it so a scanner can go against
  // it and a get to return the single region, REGIONINFO, this test is
  // messing with. Needed when "new master" joins cluster. AM will try and
  // rebuild its list of user regions and it will also get the HRI that goes
  // with an encoded name by doing a Get on hbase:meta
  ClientProtos.ClientService.BlockingInterface ri =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
  // Get a meta row result that has region up on SERVERNAME_A for REGIONINFO
  Result r = MetaMockingUtil.getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
  final ScanResponse.Builder builder = ScanResponse.newBuilder();
  builder.setMoreResults(true);
  builder.addCellsPerResult(r.size());
  final List<CellScannable> rows = new ArrayList<CellScannable>(1);
  rows.add(r);
  Answer<ScanResponse> ans = new Answer<ClientProtos.ScanResponse>() {
    @Override
    public ScanResponse answer(InvocationOnMock invocation) throws Throwable {
      PayloadCarryingRpcController controller = (PayloadCarryingRpcController) invocation
          .getArguments()[0];
      if (controller != null) {
        controller.setCellScanner(CellUtil.createCellScanner(rows));
      }
      return builder.build();
    }
  };
  if (enabling) {
    Mockito.when(ri.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any()))
        .thenAnswer(ans).thenAnswer(ans).thenAnswer(ans).thenAnswer(ans).thenAnswer(ans)
        .thenReturn(ScanResponse.newBuilder().setMoreResults(false).build());
  } else {
    Mockito.when(ri.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any())).thenAnswer(
        ans);
  }
  // If a get, return the above result too for REGIONINFO
  GetResponse.Builder getBuilder = GetResponse.newBuilder();
  getBuilder.setResult(ProtobufUtil.toResult(r));
  Mockito.when(ri.get((RpcController)Mockito.any(), (GetRequest) Mockito.any())).
    thenReturn(getBuilder.build());
  // Get a connection w/ mocked up common methods.
  HConnection connection = HConnectionTestingUtility.
    getMockedConnectionAndDecorate(HTU.getConfiguration(), null,
      ri, SERVERNAME_B, REGIONINFO);
  // Make it so we can get the connection from our mocked catalogtracker
  Mockito.when(ct.getConnection()).thenReturn(connection);
  // Create and startup an executor. Used by AM handling zk callbacks.
  ExecutorService executor = startupMasterExecutor("mockedAMExecutor");
  this.balancer = LoadBalancerFactory.getLoadBalancer(server.getConfiguration());
  AssignmentManagerWithExtrasForTesting am = new AssignmentManagerWithExtrasForTesting(
    server, manager, ct, this.balancer, executor, new NullTableLockManager());
  return am;
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:65,代码来源:TestAssignmentManager.java

示例11: testNotPullingDeadRegionServerFromZK

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
@Test
public void testNotPullingDeadRegionServerFromZK()
    throws IOException, KeeperException, InterruptedException {
  final Configuration conf = TESTUTIL.getConfiguration();
  final ServerName newServer = ServerName.valueOf("test.sample", 1, 101);
  final ServerName deadServer = ServerName.valueOf("test.sample", 1, 100);
  final MockRegionServer rs0 = new MockRegionServer(conf, newServer);

  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TESTUTIL.getConfiguration());
  HMaster master = new HMaster(conf, cp) {
    @Override
    void assignMeta(MonitoredTask status, Set<ServerName> previouslyFailedMeatRSs) {
    }

    @Override
    void initializeZKBasedSystemTrackers() throws IOException,
    InterruptedException, KeeperException, CoordinatedStateException {
      super.initializeZKBasedSystemTrackers();
      // Record a newer server in server manager at first
      serverManager.recordNewServerWithLock(newServer, ServerLoad.EMPTY_SERVERLOAD);

      List<ServerName> onlineServers = new ArrayList<ServerName>();
      onlineServers.add(deadServer);
      onlineServers.add(newServer);
      // Mock the region server tracker to pull the dead server from zk
      regionServerTracker = Mockito.spy(regionServerTracker);
      Mockito.doReturn(onlineServers).when(
        regionServerTracker).getOnlineServers();
    }

    @Override
    protected CatalogTracker createCatalogTracker() throws IOException {
      // Insert a mock for the connection used by the CatalogTracker.  Any
      // regionserver should do.  Use TESTUTIL.getConfiguration rather than
      // the conf from the master; the conf will already have an HConnection
      // associate so the below mocking of a connection will fail.
      HConnection connection =
        HConnectionTestingUtility.getMockedConnectionAndDecorate(TESTUTIL.getConfiguration(),
          rs0, rs0, rs0.getServerName(), HRegionInfo.FIRST_META_REGIONINFO);
      return new CatalogTracker(getZooKeeper(), getConfiguration(), connection, this);
    }

    @Override
    void initNamespace() {
    }
  };
  master.start();

  try {
    // Wait till master is initialized.
    while (!master.initialized) Threads.sleep(10);
    LOG.info("Master is initialized");

    assertFalse("The dead server should not be pulled in",
      master.serverManager.isServerOnline(deadServer));
  } finally {
    master.stopMaster();
    master.join();
  }
}
 
开发者ID:shenli-uiuc,项目名称:PyroDB,代码行数:62,代码来源:TestMasterNoCluster.java

示例12: setUpMockedAssignmentManager

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * Create an {@link AssignmentManagerWithExtrasForTesting} that has mocked
 * {@link CatalogTracker} etc.
 * @param server
 * @param manager
 * @return An AssignmentManagerWithExtras with mock connections, etc.
 * @throws IOException
 * @throws KeeperException
 */
private AssignmentManagerWithExtrasForTesting setUpMockedAssignmentManager(final Server server,
    final ServerManager manager) throws IOException, KeeperException,
      ServiceException, CoordinatedStateException {
  // We need a mocked catalog tracker. Its used by our AM instance.
  CatalogTracker ct = Mockito.mock(CatalogTracker.class);
  // Make an RS Interface implementation. Make it so a scanner can go against
  // it and a get to return the single region, REGIONINFO, this test is
  // messing with. Needed when "new master" joins cluster. AM will try and
  // rebuild its list of user regions and it will also get the HRI that goes
  // with an encoded name by doing a Get on hbase:meta
  ClientProtos.ClientService.BlockingInterface ri =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
  // Get a meta row result that has region up on SERVERNAME_A for REGIONINFO
  Result r = MetaMockingUtil.getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
  final ScanResponse.Builder builder = ScanResponse.newBuilder();
  builder.setMoreResults(true);
  builder.addCellsPerResult(r.size());
  final List<CellScannable> rows = new ArrayList<CellScannable>(1);
  rows.add(r);
  Answer<ScanResponse> ans = new Answer<ClientProtos.ScanResponse>() {
    @Override
    public ScanResponse answer(InvocationOnMock invocation) throws Throwable {
      PayloadCarryingRpcController controller = (PayloadCarryingRpcController) invocation
          .getArguments()[0];
      if (controller != null) {
        controller.setCellScanner(CellUtil.createCellScanner(rows));
      }
      return builder.build();
    }
  };
  if (enabling) {
    Mockito.when(ri.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any()))
        .thenAnswer(ans).thenAnswer(ans).thenAnswer(ans).thenAnswer(ans).thenAnswer(ans)
        .thenReturn(ScanResponse.newBuilder().setMoreResults(false).build());
  } else {
    Mockito.when(ri.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any())).thenAnswer(
        ans);
  }
  // If a get, return the above result too for REGIONINFO
  GetResponse.Builder getBuilder = GetResponse.newBuilder();
  getBuilder.setResult(ProtobufUtil.toResult(r));
  Mockito.when(ri.get((RpcController)Mockito.any(), (GetRequest) Mockito.any())).
    thenReturn(getBuilder.build());
  // Get a connection w/ mocked up common methods.
  HConnection connection = HConnectionTestingUtility.
    getMockedConnectionAndDecorate(HTU.getConfiguration(), null,
      ri, SERVERNAME_B, REGIONINFO);
  // Make it so we can get the connection from our mocked catalogtracker
  Mockito.when(ct.getConnection()).thenReturn(connection);
  // Create and startup an executor. Used by AM handling zk callbacks.
  ExecutorService executor = startupMasterExecutor("mockedAMExecutor");
  this.balancer = LoadBalancerFactory.getLoadBalancer(server.getConfiguration());
  AssignmentManagerWithExtrasForTesting am = new AssignmentManagerWithExtrasForTesting(
    server, manager, ct, this.balancer, executor, new NullTableLockManager());
  return am;
}
 
开发者ID:shenli-uiuc,项目名称:PyroDB,代码行数:66,代码来源:TestAssignmentManager.java

示例13: processServerShutdownHandler

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
private void processServerShutdownHandler(CatalogTracker ct, AssignmentManager am, boolean splitRegion)
    throws IOException, ServiceException {
  // Make sure our new AM gets callbacks; once registered, can't unregister.
  // Thats ok because we make a new zk watcher for each test.
  this.watcher.registerListenerFirst(am);

  // Need to set up a fake scan of meta for the servershutdown handler
  // Make an RS Interface implementation.  Make it so a scanner can go against it.
  ClientProtos.ClientService.BlockingInterface implementation =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
  // Get a meta row result that has region up on SERVERNAME_A

  Result r;
  if (splitRegion) {
    r = MetaMockingUtil.getMetaTableRowResultAsSplitRegion(REGIONINFO, SERVERNAME_A);
  } else {
    r = MetaMockingUtil.getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
  }

  final ScanResponse.Builder builder = ScanResponse.newBuilder();
  builder.setMoreResults(true);
  builder.addCellsPerResult(r.size());
  final List<CellScannable> cellScannables = new ArrayList<CellScannable>(1);
  cellScannables.add(r);
  Mockito.when(implementation.scan(
    (RpcController)Mockito.any(), (ScanRequest)Mockito.any())).
    thenAnswer(new Answer<ScanResponse>() {
        public ScanResponse answer(InvocationOnMock invocation) throws Throwable {
          PayloadCarryingRpcController controller = (PayloadCarryingRpcController) invocation
              .getArguments()[0];
          if (controller != null) {
            controller.setCellScanner(CellUtil.createCellScanner(cellScannables));
          }
          return builder.build();
        }
    });

  // Get a connection w/ mocked up common methods.
  HConnection connection =
    HConnectionTestingUtility.getMockedConnectionAndDecorate(HTU.getConfiguration(),
      null, implementation, SERVERNAME_B, REGIONINFO);

  // Make it so we can get a catalogtracker from servermanager.. .needed
  // down in guts of server shutdown handler.
  Mockito.when(ct.getConnection()).thenReturn(connection);
  Mockito.when(this.server.getCatalogTracker()).thenReturn(ct);

  // Now make a server shutdown handler instance and invoke process.
  // Have it that SERVERNAME_A died.
  DeadServer deadServers = new DeadServer();
  deadServers.add(SERVERNAME_A);
  // I need a services instance that will return the AM
  MasterServices services = Mockito.mock(MasterServices.class);
  Mockito.when(services.getAssignmentManager()).thenReturn(am);
  Mockito.when(services.getServerManager()).thenReturn(this.serverManager);
  Mockito.when(services.getZooKeeper()).thenReturn(this.watcher);
  ServerShutdownHandler handler = new ServerShutdownHandler(this.server,
    services, deadServers, SERVERNAME_A, false);
  am.failoverCleanupDone.set(true);
  handler.process();
  // The region in r will have been assigned.  It'll be up in zk as unassigned.
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:63,代码来源:TestAssignmentManager.java

示例14: setUpMockedAssignmentManager

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * Create an {@link AssignmentManagerWithExtrasForTesting} that has mocked
 * {@link CatalogTracker} etc.
 * @param server
 * @param manager
 * @return An AssignmentManagerWithExtras with mock connections, etc.
 * @throws IOException
 * @throws KeeperException
 */
private AssignmentManagerWithExtrasForTesting setUpMockedAssignmentManager(final Server server,
    final ServerManager manager) throws IOException, KeeperException, ServiceException {
  // We need a mocked catalog tracker. Its used by our AM instance.
  CatalogTracker ct = Mockito.mock(CatalogTracker.class);
  // Make an RS Interface implementation. Make it so a scanner can go against
  // it and a get to return the single region, REGIONINFO, this test is
  // messing with. Needed when "new master" joins cluster. AM will try and
  // rebuild its list of user regions and it will also get the HRI that goes
  // with an encoded name by doing a Get on hbase:meta
  ClientProtos.ClientService.BlockingInterface ri =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
  // Get a meta row result that has region up on SERVERNAME_A for REGIONINFO
  Result r = MetaMockingUtil.getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
  final ScanResponse.Builder builder = ScanResponse.newBuilder();
  builder.setMoreResults(true);
  builder.addCellsPerResult(r.size());
  final List<CellScannable> rows = new ArrayList<CellScannable>(1);
  rows.add(r);
  Answer<ScanResponse> ans = new Answer<ClientProtos.ScanResponse>() {
    public ScanResponse answer(InvocationOnMock invocation) throws Throwable {
      PayloadCarryingRpcController controller = (PayloadCarryingRpcController) invocation
          .getArguments()[0];
      if (controller != null) {
        controller.setCellScanner(CellUtil.createCellScanner(rows));
      }
      return builder.build();
    }
  };
  if (enabling) {
    Mockito.when(ri.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any()))
        .thenAnswer(ans).thenAnswer(ans).thenAnswer(ans).thenAnswer(ans).thenAnswer(ans)
        .thenReturn(ScanResponse.newBuilder().setMoreResults(false).build());
  } else {
    Mockito.when(ri.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any())).thenAnswer(
        ans);
  }
  // If a get, return the above result too for REGIONINFO
  GetResponse.Builder getBuilder = GetResponse.newBuilder();
  getBuilder.setResult(ProtobufUtil.toResult(r));
  Mockito.when(ri.get((RpcController)Mockito.any(), (GetRequest) Mockito.any())).
    thenReturn(getBuilder.build());
  // Get a connection w/ mocked up common methods.
  HConnection connection = HConnectionTestingUtility.
    getMockedConnectionAndDecorate(HTU.getConfiguration(), null,
      ri, SERVERNAME_B, REGIONINFO);
  // Make it so we can get the connection from our mocked catalogtracker
  Mockito.when(ct.getConnection()).thenReturn(connection);
  // Create and startup an executor. Used by AM handling zk callbacks.
  ExecutorService executor = startupMasterExecutor("mockedAMExecutor");
  this.balancer = LoadBalancerFactory.getLoadBalancer(server.getConfiguration());
  AssignmentManagerWithExtrasForTesting am = new AssignmentManagerWithExtrasForTesting(
    server, manager, ct, this.balancer, executor, new NullTableLockManager());
  return am;
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:64,代码来源:TestAssignmentManager.java

示例15: processServerShutdownHandler

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
private void processServerShutdownHandler(CatalogTracker ct, AssignmentManager am, boolean splitRegion)
    throws IOException, ServiceException {
  // Make sure our new AM gets callbacks; once registered, can't unregister.
  // Thats ok because we make a new zk watcher for each test.
  this.watcher.registerListenerFirst(am);

  // Need to set up a fake scan of meta for the servershutdown handler
  // Make an RS Interface implementation.  Make it so a scanner can go against it.
  ClientProtocol implementation = Mockito.mock(ClientProtocol.class);
  // Get a meta row result that has region up on SERVERNAME_A

  Result r = null;
  if (splitRegion) {
    r = MetaMockingUtil.getMetaTableRowResultAsSplitRegion(REGIONINFO, SERVERNAME_A);
  } else {
    r = MetaMockingUtil.getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
  }

  ScanResponse.Builder builder = ScanResponse.newBuilder();
  builder.setMoreResults(true);
  builder.addResult(ProtobufUtil.toResult(r));
  Mockito.when(implementation.scan(
    (RpcController)Mockito.any(), (ScanRequest)Mockito.any())).
      thenReturn(builder.build());

  // Get a connection w/ mocked up common methods.
  HConnection connection =
    HConnectionTestingUtility.getMockedConnectionAndDecorate(HTU.getConfiguration(),
      null, implementation, SERVERNAME_B, REGIONINFO);

  // Make it so we can get a catalogtracker from servermanager.. .needed
  // down in guts of server shutdown handler.
  Mockito.when(ct.getConnection()).thenReturn(connection);
  Mockito.when(this.server.getCatalogTracker()).thenReturn(ct);

  // Now make a server shutdown handler instance and invoke process.
  // Have it that SERVERNAME_A died.
  DeadServer deadServers = new DeadServer();
  deadServers.add(SERVERNAME_A);
  // I need a services instance that will return the AM
  MasterServices services = Mockito.mock(MasterServices.class);
  Mockito.when(services.getAssignmentManager()).thenReturn(am);
  Mockito.when(services.getServerManager()).thenReturn(this.serverManager);
  Mockito.when(services.getZooKeeper()).thenReturn(this.watcher);
  ServerShutdownHandler handler = new ServerShutdownHandler(this.server,
    services, deadServers, SERVERNAME_A, false);
  am.failoverCleanupDone.set(true);
  handler.process();
  // The region in r will have been assigned.  It'll be up in zk as unassigned.
}
 
开发者ID:daidong,项目名称:DominoHBase,代码行数:51,代码来源:TestAssignmentManager.java


注:本文中的org.apache.hadoop.hbase.client.HConnectionTestingUtility.getMockedConnectionAndDecorate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。