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


Java HConnectionTestingUtility.getMockedConnection方法代码示例

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


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

示例1: mockConnection

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * @param implementation An {@link HRegionInterface} instance; you'll likely
 * want to pass a mocked HRS; can be null.
 * @return Mock up a connection that returns a {@link org.apache.hadoop.conf.Configuration} when
 * {@link HConnection#getConfiguration()} is called, a 'location' when
 * {@link HConnection#getRegionLocation(byte[], byte[], boolean)} is called,
 * and that returns the passed {@link HRegionInterface} instance when
 * {@link HConnection#getHRegionConnection(String, int)}
 * is called (Be sure call
 * {@link HConnectionManager#deleteConnection(org.apache.hadoop.conf.Configuration)}
 * when done with this mocked Connection.
 * @throws IOException
 */
private HConnection mockConnection(final HRegionInterface implementation)
throws IOException {
  HConnection connection =
    HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
  Mockito.doNothing().when(connection).close();
  // Make it so we return any old location when asked.
  final HRegionLocation anyLocation =
    new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN.getHostname(),
      SN.getPort());
  Mockito.when(connection.getRegionLocation((byte[]) Mockito.any(),
      (byte[]) Mockito.any(), Mockito.anyBoolean())).
    thenReturn(anyLocation);
  Mockito.when(connection.locateRegion((byte[]) Mockito.any(),
      (byte[]) Mockito.any())).
    thenReturn(anyLocation);
  if (implementation != null) {
    // If a call to getHRegionConnection, return this implementation.
    Mockito.when(connection.getHRegionConnection(Mockito.anyString(), Mockito.anyInt())).
      thenReturn(implementation);
  }
  return connection;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:36,代码来源:TestCatalogTracker.java

示例2: mockConnection

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * @param admin An {@link AdminProtos.AdminService.BlockingInterface} instance; you'll likely
 * want to pass a mocked HRS; can be null.
 * @param client A mocked ClientProtocol instance, can be null
 * @return Mock up a connection that returns a {@link Configuration} when
 * {@link HConnection#getConfiguration()} is called, a 'location' when
 * {@link HConnection#getRegionLocation(byte[], byte[], boolean)} is called,
 * and that returns the passed {@link AdminProtos.AdminService.BlockingInterface} instance when
 * {@link HConnection#getAdmin(ServerName)} is called, returns the passed
 * {@link ClientProtos.ClientService.BlockingInterface} instance when
 * {@link HConnection#getClient(ServerName)} is called.
 * @throws IOException
 */
private ClusterConnection mockConnection(final AdminProtos.AdminService.BlockingInterface admin,
    final ClientProtos.ClientService.BlockingInterface client)
throws IOException {
  ClusterConnection connection =
    HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
  Mockito.doNothing().when(connection).close();
  // Make it so we return any old location when asked.
  final HRegionLocation anyLocation = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN);
  Mockito.when(connection.getRegionLocation((TableName) Mockito.any(),
      (byte[]) Mockito.any(), Mockito.anyBoolean())).
    thenReturn(anyLocation);
  Mockito.when(connection.locateRegion((TableName) Mockito.any(),
      (byte[]) Mockito.any())).
    thenReturn(anyLocation);
  if (admin != null) {
    // If a call to getHRegionConnection, return this implementation.
    Mockito.when(connection.getAdmin(Mockito.any(ServerName.class))).
      thenReturn(admin);
  }
  if (client != null) {
    // If a call to getClient, return this implementation.
    Mockito.when(connection.getClient(Mockito.any(ServerName.class))).
      thenReturn(client);
  }
  return connection;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:40,代码来源:TestMetaTableLocator.java

示例3: testTimeoutWaitForMeta

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
@Test (expected = RetriesExhaustedException.class)
public void testTimeoutWaitForMeta()
throws IOException, InterruptedException {
  HConnection connection =
    HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
  final CatalogTracker ct = constructAndStartCatalogTracker(connection);
  ct.waitForMeta(100);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:9,代码来源:TestCatalogTracker.java

示例4: mockConnection

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * @param admin An {@link AdminProtos.AdminService.BlockingInterface} instance; you'll likely
 * want to pass a mocked HRS; can be null.
 * @param client A mocked ClientProtocol instance, can be null
 * @return Mock up a connection that returns a {@link Configuration} when
 * {@link HConnection#getConfiguration()} is called, a 'location' when
 * {@link HConnection#getRegionLocation(byte[], byte[], boolean)} is called,
 * and that returns the passed {@link AdminProtos.AdminService.BlockingInterface} instance when
 * {@link HConnection#getAdmin(ServerName)} is called, returns the passed
 * {@link ClientProtos.ClientService.BlockingInterface} instance when
 * {@link HConnection#getClient(ServerName)} is called (Be sure to call
 * {@link HConnectionManager#deleteConnection(org.apache.hadoop.conf.Configuration)}
 * when done with this mocked Connection.
 * @throws IOException
 */
private HConnection mockConnection(final AdminProtos.AdminService.BlockingInterface admin,
    final ClientProtos.ClientService.BlockingInterface client)
throws IOException {
  HConnection connection =
    HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
  Mockito.doNothing().when(connection).close();
  // Make it so we return any old location when asked.
  final HRegionLocation anyLocation =
    new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN);
  Mockito.when(connection.getRegionLocation((TableName) Mockito.any(),
      (byte[]) Mockito.any(), Mockito.anyBoolean())).
    thenReturn(anyLocation);
  Mockito.when(connection.locateRegion((TableName) Mockito.any(),
      (byte[]) Mockito.any())).
    thenReturn(anyLocation);
  if (admin != null) {
    // If a call to getHRegionConnection, return this implementation.
    Mockito.when(connection.getAdmin(Mockito.any(ServerName.class))).
      thenReturn(admin);
  }
  if (client != null) {
    // If a call to getClient, return this implementation.
    Mockito.when(connection.getClient(Mockito.any(ServerName.class))).
      thenReturn(client);
  }
  return connection;
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:43,代码来源:TestCatalogTracker.java

示例5: testMasterMonitorCollableRetries

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * Verify that PleaseHoldException gets retried.
 * HBASE-8764
 * @throws IOException 
 * @throws ZooKeeperConnectionException 
 * @throws MasterNotRunningException 
 * @throws ServiceException 
 */
@Test
public void testMasterMonitorCollableRetries()
throws MasterNotRunningException, ZooKeeperConnectionException, IOException, ServiceException {
  Configuration configuration = HBaseConfiguration.create();
  // Set the pause and retry count way down.
  configuration.setLong(HConstants.HBASE_CLIENT_PAUSE, 1);
  final int count = 10;
  configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, count);
  // Get mocked connection.   Getting the connection will register it so when HBaseAdmin is
  // constructed with same configuration, it will find this mocked connection.
  HConnection connection = HConnectionTestingUtility.getMockedConnection(configuration);
  // Mock so we get back the master interface.  Make it so when createTable is called, we throw
  // the PleaseHoldException.
  MasterKeepAliveConnection masterAdmin =
    Mockito.mock(MasterKeepAliveConnection.class);
  Mockito.when(masterAdmin.createTable((RpcController)Mockito.any(),
    (CreateTableRequest)Mockito.any())).
      thenThrow(new ServiceException("Test fail").initCause(new PleaseHoldException("test")));
  Mockito.when(connection.getKeepAliveMasterService()).thenReturn(masterAdmin);
  // Mock up our admin Interfaces
  HBaseAdmin admin = new HBaseAdmin(configuration);
  try {
    HTableDescriptor htd =
        new HTableDescriptor(TableName.valueOf("testMasterMonitorCollableRetries"));
    // Pass any old htable descriptor; not important
    try {
      admin.createTable(htd, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
      fail();
    } catch (RetriesExhaustedException e) {
      Log.info("Expected fail", e);
    }
    // Assert we were called 'count' times.
    Mockito.verify(masterAdmin, Mockito.atLeast(count)).createTable((RpcController)Mockito.any(),
      (CreateTableRequest)Mockito.any());
  } finally {
    admin.close();
    if (connection != null)HConnectionManager.deleteConnection(configuration);
  }
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:48,代码来源:TestHBaseAdminNoCluster.java

示例6: mockConnection

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * @param admin An {@link AdminProtos.AdminService.BlockingInterface} instance; you'll likely
 * want to pass a mocked HRS; can be null.
 * @param client A mocked ClientProtocol instance, can be null
 * @return Mock up a connection that returns a {@link Configuration} when
 * {@link org.apache.hadoop.hbase.client.ClusterConnection#getConfiguration()} is called, a 'location' when
 * {@link org.apache.hadoop.hbase.client.RegionLocator#getRegionLocation(byte[], boolean)} is called,
 * and that returns the passed {@link AdminProtos.AdminService.BlockingInterface} instance when
 * {@link org.apache.hadoop.hbase.client.ClusterConnection#getAdmin(ServerName)} is called, returns the passed
 * {@link ClientProtos.ClientService.BlockingInterface} instance when
 * {@link org.apache.hadoop.hbase.client.ClusterConnection#getClient(ServerName)} is called.
 * @throws IOException
 */
private ClusterConnection mockConnection(final AdminProtos.AdminService.BlockingInterface admin,
    final ClientProtos.ClientService.BlockingInterface client)
throws IOException {
  ClusterConnection connection =
    HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
  Mockito.doNothing().when(connection).close();
  // Make it so we return any old location when asked.
  final HRegionLocation anyLocation = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN);
  Mockito.when(connection.getRegionLocation((TableName) Mockito.any(),
      (byte[]) Mockito.any(), Mockito.anyBoolean())).
    thenReturn(anyLocation);
  Mockito.when(connection.locateRegion((TableName) Mockito.any(),
      (byte[]) Mockito.any())).
    thenReturn(anyLocation);
  if (admin != null) {
    // If a call to getHRegionConnection, return this implementation.
    Mockito.when(connection.getAdmin(Mockito.any())).
      thenReturn(admin);
  }
  if (client != null) {
    // If a call to getClient, return this implementation.
    Mockito.when(connection.getClient(Mockito.any())).
      thenReturn(client);
  }
  return connection;
}
 
开发者ID:apache,项目名称:hbase,代码行数:40,代码来源:TestMetaTableLocator.java

示例7: testTimeoutWaitForMeta

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
@Test (expected = RetriesExhaustedException.class)
public void testTimeoutWaitForMeta()
throws IOException, InterruptedException {
  HConnection connection =
    HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
  try {
    final CatalogTracker ct = constructAndStartCatalogTracker(connection);
    ct.waitForMeta(100);
  } finally {
    HConnectionManager.deleteConnection(UTIL.getConfiguration());
  }
}
 
开发者ID:zwqjsj0404,项目名称:HBase-Research,代码行数:13,代码来源:TestCatalogTracker.java

示例8: testTimeoutWaitForMeta

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
@Test (expected = RetriesExhaustedException.class)
public void testTimeoutWaitForMeta()
throws IOException, InterruptedException {
  HConnection connection =
    HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
  try {
    final CatalogTracker ct = constructAndStartCatalogTracker(connection);
    ct.waitForMeta(100);
  } finally {
    HConnectionManager.deleteConnection(UTIL.getConfiguration(), true);
  }
}
 
开发者ID:daidong,项目名称:DominoHBase,代码行数:13,代码来源:TestCatalogTracker.java

示例9: mockConnection

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
/**
 * @param admin An {@link AdminProtocol} instance; you'll likely
 * want to pass a mocked HRS; can be null.
 * @param client A mocked ClientProtocol instance, can be null
 * @return Mock up a connection that returns a {@link Configuration} when
 * {@link HConnection#getConfiguration()} is called, a 'location' when
 * {@link HConnection#getRegionLocation(byte[], byte[], boolean)} is called,
 * and that returns the passed {@link AdminProtocol} instance when
 * {@link HConnection#getAdmin(String, int)} is called, returns the passed
 * {@link ClientProtocol} instance when {@link HConnection#getClient(String, int)}
 * is called (Be sure call
 * {@link HConnectionManager#deleteConnection(org.apache.hadoop.conf.Configuration, boolean)}
 * when done with this mocked Connection.
 * @throws IOException
 */
private HConnection mockConnection(final AdminProtocol admin,
    final ClientProtocol client) throws IOException {
  HConnection connection =
    HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
  Mockito.doNothing().when(connection).close();
  // Make it so we return any old location when asked.
  final HRegionLocation anyLocation =
    new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN.getHostname(),
      SN.getPort());
  Mockito.when(connection.getRegionLocation((byte[]) Mockito.any(),
      (byte[]) Mockito.any(), Mockito.anyBoolean())).
    thenReturn(anyLocation);
  Mockito.when(connection.locateRegion((byte[]) Mockito.any(),
      (byte[]) Mockito.any())).
    thenReturn(anyLocation);
  if (admin != null) {
    // If a call to getHRegionConnection, return this implementation.
    Mockito.when(connection.getAdmin(Mockito.anyString(), Mockito.anyInt())).
      thenReturn(admin);
  }
  if (client != null) {
    // If a call to getClient, return this implementation.
    Mockito.when(connection.getClient(Mockito.anyString(), Mockito.anyInt())).
      thenReturn(client);
  }
  return connection;
}
 
开发者ID:daidong,项目名称:DominoHBase,代码行数:43,代码来源:TestCatalogTracker.java

示例10: before

import org.apache.hadoop.hbase.client.HConnectionTestingUtility; //导入方法依赖的package包/类
@Before
public void before() throws ZooKeeperConnectionException, IOException {
  // TODO: Make generic versions of what we do below and put up in a mocking
  // utility class or move up into HBaseTestingUtility.

  // Mock a Server.  Have it return a legit Configuration and ZooKeeperWatcher.
  // If abort is called, be sure to fail the test (don't just swallow it
  // silently as is mockito default).
  this.server = Mockito.mock(Server.class);
  Mockito.when(server.getServerName()).thenReturn(ServerName.valueOf("master,1,1"));
  Mockito.when(server.getConfiguration()).thenReturn(HTU.getConfiguration());
  this.watcher =
    new ZooKeeperWatcher(HTU.getConfiguration(), "mockedServer", this.server, true);
  Mockito.when(server.getZooKeeper()).thenReturn(this.watcher);
  Mockito.doThrow(new RuntimeException("Aborted")).
    when(server).abort(Mockito.anyString(), (Throwable)Mockito.anyObject());

  cp = new ZkCoordinatedStateManager();
  cp.initialize(this.server);
  cp.start();

  mtl = Mockito.mock(MetaTableLocator.class);

  Mockito.when(server.getCoordinatedStateManager()).thenReturn(cp);
  Mockito.when(server.getMetaTableLocator()).thenReturn(mtl);

  // Get a connection w/ mocked up common methods.
  this.connection =
    (ClusterConnection)HConnectionTestingUtility.getMockedConnection(HTU.getConfiguration());

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

  // Mock a ServerManager.  Say server SERVERNAME_{A,B} are online.  Also
  // make it so if close or open, we return 'success'.
  this.serverManager = Mockito.mock(ServerManager.class);
  Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(true);
  Mockito.when(this.serverManager.isServerOnline(SERVERNAME_B)).thenReturn(true);
  Mockito.when(this.serverManager.getDeadServers()).thenReturn(new DeadServer());
  final Map<ServerName, ServerLoad> onlineServers = new HashMap<ServerName, ServerLoad>();
  onlineServers.put(SERVERNAME_B, ServerLoad.EMPTY_SERVERLOAD);
  onlineServers.put(SERVERNAME_A, ServerLoad.EMPTY_SERVERLOAD);
  Mockito.when(this.serverManager.getOnlineServersList()).thenReturn(
      new ArrayList<ServerName>(onlineServers.keySet()));
  Mockito.when(this.serverManager.getOnlineServers()).thenReturn(onlineServers);

  List<ServerName> avServers = new ArrayList<ServerName>();
  avServers.addAll(onlineServers.keySet());
  Mockito.when(this.serverManager.createDestinationServersList()).thenReturn(avServers);
  Mockito.when(this.serverManager.createDestinationServersList(null)).thenReturn(avServers);

  Mockito.when(this.serverManager.sendRegionClose(SERVERNAME_A, REGIONINFO, -1)).
    thenReturn(true);
  Mockito.when(this.serverManager.sendRegionClose(SERVERNAME_B, REGIONINFO, -1)).
    thenReturn(true);
  // Ditto on open.
  Mockito.when(this.serverManager.sendRegionOpen(SERVERNAME_A, REGIONINFO, -1, null)).
    thenReturn(RegionOpeningState.OPENED);
  Mockito.when(this.serverManager.sendRegionOpen(SERVERNAME_B, REGIONINFO, -1, null)).
    thenReturn(RegionOpeningState.OPENED);
  this.master = Mockito.mock(HMaster.class);

  Mockito.when(this.master.getServerManager()).thenReturn(serverManager);
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:66,代码来源:TestAssignmentManager.java


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