Java 类org.apache.hadoop.hbase.MiniHBaseCluster 实例源码

项目:ditb    文件:TestAdmin2.java   
@Test (timeout=300000)
public void testMoveToPreviouslyAssignedRS() throws IOException, InterruptedException {
  byte[] tableName = Bytes.toBytes("testMoveToPreviouslyAssignedRS");
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  HBaseAdmin localAdmin = createTable(tableName);
  List<HRegionInfo> tableRegions = localAdmin.getTableRegions(tableName);
  HRegionInfo hri = tableRegions.get(0);
  AssignmentManager am = master.getAssignmentManager();
  assertTrue("Region " + hri.getRegionNameAsString()
    + " should be assigned properly", am.waitForAssignment(hri));
  ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
  localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName()));
  assertEquals("Current region server and region server before move should be same.", server,
    am.getRegionStates().getRegionServerOfRegion(hri));
}
项目:ditb    文件:TestCreateTableHandler.java   
@Test (timeout=300000)
public void testCreateTableCalledTwiceAndFirstOneInProgress() throws Exception {
  final TableName tableName = TableName.valueOf("testCreateTableCalledTwiceAndFirstOneInProgress");
  final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  final HMaster m = cluster.getMaster();
  final HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(FAMILYNAME));
  final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getTableName(), null,
      null) };
  CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      desc, cluster.getConfiguration(), hRegionInfos, m);
  handler.prepare();
  throwException = true;
  handler.process();
  throwException = false;
  CustomCreateTableHandler handler1 = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      desc, cluster.getConfiguration(), hRegionInfos, m);
  handler1.prepare();
  handler1.process();
  for (int i = 0; i < 100; i++) {
    if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) {
      Thread.sleep(200);
    }
  }
  assertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(tableName));
}
项目:ditb    文件:TestCreateTableHandler.java   
@Test (timeout=60000)
public void testMasterRestartAfterEnablingNodeIsCreated() throws Exception {
  byte[] tableName = Bytes.toBytes("testMasterRestartAfterEnablingNodeIsCreated");
  final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  final HMaster m = cluster.getMaster();
  final HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
  desc.addFamily(new HColumnDescriptor(FAMILYNAME));
  final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getTableName(), null,
      null) };
  CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      desc, cluster.getConfiguration(), hRegionInfos, m);
  handler.prepare();
  throwException = true;
  handler.process();
  abortAndStartNewMaster(cluster);
  assertTrue(cluster.getLiveMasterThreads().size() == 1);
}
项目:ditb    文件:TestEnableTableHandler.java   
@Test(timeout = 300000)
public void testDisableTableAndRestart() throws Exception {
  final TableName tableName = TableName.valueOf("testDisableTableAndRestart");
  final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  final HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  final HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(FAMILYNAME));
  admin.createTable(desc);
  admin.disableTable(tableName);
  TEST_UTIL.waitTableDisabled(tableName.getName());

  TEST_UTIL.getHBaseCluster().shutdown();
  TEST_UTIL.getHBaseCluster().waitUntilShutDown();

  TEST_UTIL.restartHBaseCluster(2);

  admin.enableTable(tableName);
  TEST_UTIL.waitTableEnabled(tableName);
}
项目:ditb    文件:TestMasterObserver.java   
@Test (timeout=180000)
public void testStarted() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  assertTrue("Master should be active", master.isActiveMaster());
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  assertNotNull("CoprocessorHost should not be null", host);
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);

  // check basic lifecycle
  assertTrue("MasterObserver should have been started", cp.wasStarted());
  assertTrue("preMasterInitialization() hook should have been called",
      cp.wasMasterInitializationCalled());
  assertTrue("postStartMaster() hook should have been called",
      cp.wasStartMasterCalled());
}
项目:ditb    文件:TestMasterObserver.java   
@Test (timeout=180000)
public void testTableDescriptorsEnumeration() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  cp.resetStates();

  GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null);
  master.getMasterRpcServices().getTableDescriptors(null, req);

  assertTrue("Coprocessor should be called on table descriptors request",
    cp.wasGetTableDescriptorsCalled());
}
项目:ditb    文件:TestRegionServerCoprocessorExceptionWithAbort.java   
@Test(timeout=60000)
public void testExceptionDuringInitialization() throws Exception {
  Configuration conf = TEST_UTIL.getConfiguration();
  conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);  // Let's fail fast.
  conf.setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, true);
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, "");
  TEST_UTIL.startMiniCluster(2);
  try {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    // Trigger one regionserver to fail as if it came up with a coprocessor
    // that fails during initialization
    final HRegionServer regionServer = cluster.getRegionServer(0);
    conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
      FailedInitializationObserver.class.getName());
    regionServer.getRegionServerCoprocessorHost().loadSystemCoprocessors(conf,
      CoprocessorHost.REGION_COPROCESSOR_CONF_KEY);
    TEST_UTIL.waitFor(10000, 1000, new Predicate<Exception>() {
      @Override
      public boolean evaluate() throws Exception {
        return regionServer.isAborted();
      }
    });
  } finally {
    TEST_UTIL.shutdownMiniCluster();
  }
}
项目:beam    文件:HBaseIOTest.java   
@BeforeClass
public static void beforeClass() throws Exception {
  conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
  // Try to bind the hostname to localhost to solve an issue when it is not configured or
  // no DNS resolution available.
  conf.setStrings("hbase.master.hostname", "localhost");
  conf.setStrings("hbase.regionserver.hostname", "localhost");
  htu = new HBaseTestingUtility(conf);

  // We don't use the full htu.startMiniCluster() to avoid starting unneeded HDFS/MR daemons
  htu.startMiniZKCluster();
  MiniHBaseCluster hbm = htu.startMiniHBaseCluster(1, 4);
  hbm.waitForActiveAndReadyMaster();

  admin = htu.getHBaseAdmin();
}
项目:LCIndex-HBase-0.94.16    文件:TestFromClientSide.java   
/**
 * test of that unmanaged HConnections are able to reconnect
 * properly (see HBASE-5058)
 *
 * @throws Exception
 */
@Test
public void testUnmanagedHConnectionReconnect() throws Exception {
  final byte[] tableName = Bytes.toBytes("testUnmanagedHConnectionReconnect");
  HTable t = createUnmangedHConnectionHTable(tableName);
  HConnection conn = t.getConnection();
  HBaseAdmin ha = new HBaseAdmin(conn);
  assertTrue(ha.tableExists(tableName));
  assertTrue(t.get(new Get(ROW)).isEmpty());

  // stop the master
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  cluster.stopMaster(0, false);
  cluster.waitOnMaster(0);

  // start up a new master
  cluster.startMaster();
  assertTrue(cluster.waitForActiveAndReadyMaster());

  // test that the same unmanaged connection works with a new
  // HBaseAdmin and can connect to the new master;
  HBaseAdmin newAdmin = new HBaseAdmin(conn);
  assertTrue(newAdmin.tableExists(tableName));
  assert(newAdmin.getClusterStatus().getServersSize() == SLAVES);
}
项目:LCIndex-HBase-0.94.16    文件:TestCreateTableHandler.java   
@Test
public void testCreateTableCalledTwiceAndFirstOneInProgress() throws Exception {
  final byte[] tableName = Bytes.toBytes("testCreateTableCalledTwiceAndFirstOneInProgress");
  final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  final HMaster m = cluster.getMaster();
  final HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(FAMILYNAME));
  final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getName(), null,
      null) };
  CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      m.getServerManager(), desc, cluster.getConfiguration(), hRegionInfos,
      m.getCatalogTracker(), m.getAssignmentManager());
  throwException = true;
  handler.process();
  throwException = false;
  CustomCreateTableHandler handler1 = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      m.getServerManager(), desc, cluster.getConfiguration(), hRegionInfos,
      m.getCatalogTracker(), m.getAssignmentManager());
  handler1.process();
  for (int i = 0; i < 100; i++) {
    if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) {
      Thread.sleep(200);
    }
  }
  assertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(tableName));
}
项目:LCIndex-HBase-0.94.16    文件:TestCreateTableHandler.java   
@Test (timeout=60000)
public void testMasterRestartAfterEnablingNodeIsCreated() throws Exception {
  byte[] tableName = Bytes.toBytes("testMasterRestartAfterEnablingNodeIsCreated");
  final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  final HMaster m = cluster.getMaster();
  final HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(FAMILYNAME));
  final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getName(), null,
      null) };
  CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      m.getServerManager(), desc, cluster.getConfiguration(), hRegionInfos,
      m.getCatalogTracker(), m.getAssignmentManager());
  throwException = true;
  handler.process();
  abortAndStartNewMaster(cluster);
  assertTrue(cluster.getLiveMasterThreads().size() == 1);
}
项目:yuzhouwan    文件:HBaseMiniCluster.java   
private HBaseTestingUtility hbaseOperation() throws Exception {

        HBaseTestingUtility hbaseTestingUtility = new HBaseTestingUtility();
        /**
         * # fsOwner's name is Benedict Jin, will throw exception: Illegal character in path at index 42
         * hbaseTestingUtility.getTestFileSystem().setOwner(new Path(BASE_PATH.concat("/owner")), "Benedict Jin", "supergroup");
         */
        MiniHBaseCluster hbaseCluster = hbaseTestingUtility.startMiniCluster();

        hbaseTestingUtility.createTable(Bytes.toBytes(TABLE_NAME), Bytes.toBytes("context"));
        hbaseTestingUtility.deleteTable(Bytes.toBytes(TABLE_NAME));

        Configuration config = hbaseCluster.getConf();
        Connection conn = ConnectionFactory.createConnection(config);
        HBaseAdmin hbaseAdmin = new HBaseAdmin(conn);

        HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
        hbaseAdmin.createTable(desc);
        return hbaseTestingUtility;
    }
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testEnabledIndexTableShouldBeDisabledIfUserTableDisabledAndMasterRestarted()
    throws Exception {
  String tableName = "testEnabledIndexTableDisabledIfUserTableDisabledAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(tableName);
  admin.enableTable(indexTableName);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be disabled.", admin.isTableDisabled(tableName));
  assertTrue("Index table should be disabled.", admin.isTableDisabled(indexTableName));
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testDisabledIndexTableShouldBeEnabledIfUserTableInEnablingAndMasterRestarted()
    throws Exception {
  String tableName = "testDisabledIndexTableEnabledIfUserTableInEnablingAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(indexTableName);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  master.getAssignmentManager().getZKTable().setEnablingTable(TableName.valueOf(tableName));
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be enabled.", admin.isTableEnabled(tableName));
  assertTrue("Index table should be enabled.", admin.isTableEnabled(indexTableName));
}
项目:pbase    文件:TestAdmin2.java   
@Test (timeout=300000)
public void testMoveToPreviouslyAssignedRS() throws IOException, InterruptedException {
  byte[] tableName = Bytes.toBytes("testMoveToPreviouslyAssignedRS");
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  HBaseAdmin localAdmin = createTable(tableName);
  List<HRegionInfo> tableRegions = localAdmin.getTableRegions(tableName);
  HRegionInfo hri = tableRegions.get(0);
  AssignmentManager am = master.getAssignmentManager();
  assertTrue("Region " + hri.getRegionNameAsString()
    + " should be assigned properly", am.waitForAssignment(hri));
  ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
  localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName()));
  assertEquals("Current region server and region server before move should be same.", server,
    am.getRegionStates().getRegionServerOfRegion(hri));
}
项目:pbase    文件:TestCreateTableHandler.java   
@Test (timeout=300000)
public void testCreateTableCalledTwiceAndFirstOneInProgress() throws Exception {
  final TableName tableName = TableName.valueOf("testCreateTableCalledTwiceAndFirstOneInProgress");
  final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  final HMaster m = cluster.getMaster();
  final HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(FAMILYNAME));
  final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getTableName(), null,
      null) };
  CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      desc, cluster.getConfiguration(), hRegionInfos, m);
  handler.prepare();
  throwException = true;
  handler.process();
  throwException = false;
  CustomCreateTableHandler handler1 = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      desc, cluster.getConfiguration(), hRegionInfos, m);
  handler1.prepare();
  handler1.process();
  for (int i = 0; i < 100; i++) {
    if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) {
      Thread.sleep(200);
    }
  }
  assertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(tableName));
}
项目:pbase    文件:TestCreateTableHandler.java   
@Test (timeout=60000)
public void testMasterRestartAfterEnablingNodeIsCreated() throws Exception {
  byte[] tableName = Bytes.toBytes("testMasterRestartAfterEnablingNodeIsCreated");
  final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  final HMaster m = cluster.getMaster();
  final HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
  desc.addFamily(new HColumnDescriptor(FAMILYNAME));
  final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getTableName(), null,
      null) };
  CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      desc, cluster.getConfiguration(), hRegionInfos, m);
  handler.prepare();
  throwException = true;
  handler.process();
  abortAndStartNewMaster(cluster);
  assertTrue(cluster.getLiveMasterThreads().size() == 1);
}
项目:pbase    文件:TestMasterObserver.java   
@Test
public void testStarted() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  assertTrue("Master should be active", master.isActiveMaster());
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  assertNotNull("CoprocessorHost should not be null", host);
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);

  // check basic lifecycle
  assertTrue("MasterObserver should have been started", cp.wasStarted());
  assertTrue("preMasterInitialization() hook should have been called",
      cp.wasMasterInitializationCalled());
  assertTrue("postStartMaster() hook should have been called",
      cp.wasStartMasterCalled());
}
项目:pbase    文件:TestMasterObserver.java   
@Test
public void testTableDescriptorsEnumeration() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  cp.resetStates();

  GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null);
  master.getMasterRpcServices().getTableDescriptors(null, req);

  assertTrue("Coprocessor should be called on table descriptors request",
    cp.wasGetTableDescriptorsCalled());
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testDisabledIndexTableShouldBeEnabledIfUserTableEnabledAndMasterRestarted()
    throws Exception {
  String tableName = "testDisabledIndexTableEnabledIfUserTableEnabledAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(indexTableName);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be enabled.", admin.isTableEnabled(tableName));
  assertTrue("Index table should be enabled.", admin.isTableEnabled(indexTableName));
}
项目:HIndex    文件:TestSecIndexLoadBalancer.java   
@Test(timeout = 180000)
public void testRoundRobinAssignmentDuringIndexTableCreation() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  String tableName = "testRoundRobinAssignmentDuringIndexTableCreation";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  char c = 'A';
  byte[][] split = new byte[20][];
  for (int i = 0; i < 20; i++) {
    byte[] b = { (byte) c };
    split[i] = b;
    c++;
  }
  admin.createTable(iHtd, split);
  boolean isRegionColocated = TestUtils.checkForColocation(master, tableName, indexTableName);
  assertTrue("User regions and index regions should colocate.", isRegionColocated);
}
项目:HIndex    文件:TestFromClientSide.java   
/**
 * test of that unmanaged HConnections are able to reconnect
 * properly (see HBASE-5058)
 *
 * @throws Exception
 */
@Test
public void testUnmanagedHConnectionReconnect() throws Exception {
  final byte[] tableName = Bytes.toBytes("testUnmanagedHConnectionReconnect");
  HTable t = createUnmangedHConnectionHTable(tableName);
  HConnection conn = t.getConnection();
  HBaseAdmin ha = new HBaseAdmin(conn);
  assertTrue(ha.tableExists(tableName));
  assertTrue(t.get(new Get(ROW)).isEmpty());

  // stop the master
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  cluster.stopMaster(0, false);
  cluster.waitOnMaster(0);

  // start up a new master
  cluster.startMaster();
  assertTrue(cluster.waitForActiveAndReadyMaster());

  // test that the same unmanaged connection works with a new
  // HBaseAdmin and can connect to the new master;
  HBaseAdmin newAdmin = new HBaseAdmin(conn);
  assertTrue(newAdmin.tableExists(tableName));
  assert(newAdmin.getClusterStatus().getServersSize() == SLAVES);
}
项目:HIndex    文件:TestCreateTableHandler.java   
@Test (timeout=300000)
public void testCreateTableCalledTwiceAndFirstOneInProgress() throws Exception {
  final byte[] tableName = Bytes.toBytes("testCreateTableCalledTwiceAndFirstOneInProgress");
  final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  final HMaster m = cluster.getMaster();
  final HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
  desc.addFamily(new HColumnDescriptor(FAMILYNAME));
  final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getTableName(), null,
      null) };
  CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      desc, cluster.getConfiguration(), hRegionInfos, m);
  handler.prepare();
  throwException = true;
  handler.process();
  throwException = false;
  CustomCreateTableHandler handler1 = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
      desc, cluster.getConfiguration(), hRegionInfos, m);
  handler1.prepare();
  handler1.process();
  for (int i = 0; i < 100; i++) {
    if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) {
      Thread.sleep(200);
    }
  }
  assertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(tableName));
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testIndexTableCreationAfterMasterRestart() throws Exception {
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor("testIndexTableCreationAfterMasterRestart", "cf",
        "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable("testIndexTableCreationAfterMasterRestart" + Constants.INDEX_TABLE_SUFFIX);
  admin.deleteTable("testIndexTableCreationAfterMasterRestart" + Constants.INDEX_TABLE_SUFFIX);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  cluster.abortMaster(0);
  cluster.waitOnMaster(0);
  // start up a new master
  cluster.startMaster();
  assertTrue(cluster.waitForActiveAndReadyMaster());
  String indexTableName =
      "testIndexTableCreationAfterMasterRestart" + Constants.INDEX_TABLE_SUFFIX;

  assertTrue("Index tables is not created.", admin.isTableAvailable(indexTableName));
}
项目:HIndex    文件:TestZKBasedOpenCloseRegion.java   
/**
 * Test we reopen a region once closed.
 * @throws Exception
 */
@Test (timeout=300000) public void testReOpenRegion()
throws Exception {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  LOG.info("Number of region servers = " +
    cluster.getLiveRegionServerThreads().size());

  int rsIdx = 0;
  HRegionServer regionServer =
    TEST_UTIL.getHBaseCluster().getRegionServer(rsIdx);
  HRegionInfo hri = getNonMetaRegion(ProtobufUtil.getOnlineRegions(regionServer));
  LOG.debug("Asking RS to close region " + hri.getRegionNameAsString());

  LOG.info("Unassign " + hri.getRegionNameAsString());
  cluster.getMaster().assignmentManager.unassign(hri);

  while (!cluster.getMaster().assignmentManager.wasClosedHandlerCalled(hri)) {
    Threads.sleep(100);
  }

  while (!cluster.getMaster().assignmentManager.wasOpenedHandlerCalled(hri)) {
    Threads.sleep(100);
  }

  LOG.info("Done with testReOpenRegion");
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testEnabledIndexTableShouldBeDisabledIfUserTableInDisablingAndMasterRestarted()
    throws Exception {
  String tableName = "testEnabledIndexTableDisabledIfUserTableInDisablingAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  master.getAssignmentManager().getZKTable().setDisablingTable(TableName.valueOf(tableName));
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be disabled.", admin.isTableDisabled(tableName));
  assertTrue("Index table should be disabled.", admin.isTableDisabled(indexTableName));
}
项目:ditb    文件:SecureTestUtil.java   
private static List<AccessController> getAccessControllers(MiniHBaseCluster cluster) {
  List<AccessController> result = Lists.newArrayList();
  for (RegionServerThread t: cluster.getLiveRegionServerThreads()) {
    for (Region region: t.getRegionServer().getOnlineRegionsLocalContext()) {
      Coprocessor cp = region.getCoprocessorHost()
        .findCoprocessor(AccessController.class.getName());
      if (cp != null) {
        result.add((AccessController)cp);
      }
    }
  }
  return result;
}
项目:ditb    文件:SecureTestUtil.java   
private static Map<AccessController,Long> getAuthManagerMTimes(MiniHBaseCluster cluster) {
  Map<AccessController,Long> result = Maps.newHashMap();
  for (AccessController ac: getAccessControllers(cluster)) {
    result.put(ac, ac.getAuthManager().getMTime());
  }
  return result;
}
项目:ditb    文件:TestFromClientSide.java   
/**
 * test of that unmanaged HConnections are able to reconnect
 * properly (see HBASE-5058)
 *
 * @throws Exception
 */
@Test
public void testUnmanagedHConnectionReconnect() throws Exception {
  final TableName tableName = TableName.valueOf("testUnmanagedHConnectionReconnect");
  HTable t = createUnmangedHConnectionHTable(tableName);
  Connection conn = t.getConnection();
  try (HBaseAdmin ha = new HBaseAdmin(conn)) {
    assertTrue(ha.tableExists(tableName));
    assertTrue(t.get(new Get(ROW)).isEmpty());
  }

  // stop the master
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  cluster.stopMaster(0, false);
  cluster.waitOnMaster(0);

  // start up a new master
  cluster.startMaster();
  assertTrue(cluster.waitForActiveAndReadyMaster());

  // test that the same unmanaged connection works with a new
  // HBaseAdmin and can connect to the new master;
  try (HBaseAdmin newAdmin = new HBaseAdmin(conn)) {
    assertTrue(newAdmin.tableExists(tableName));
    assertTrue(newAdmin.getClusterStatus().getServersSize() == SLAVES);
  }
}
项目:ditb    文件:TestHTableMultiplexerFlushCache.java   
@Test
public void testOnRegionChange() throws Exception {
  TableName TABLE = TableName.valueOf("testOnRegionChange");
  final int NUM_REGIONS = 10;
  HTable htable = TEST_UTIL.createTable(TABLE, new byte[][] { FAMILY }, 3,
    Bytes.toBytes("aaaaa"), Bytes.toBytes("zzzzz"), NUM_REGIONS);

  HTableMultiplexer multiplexer = new HTableMultiplexer(TEST_UTIL.getConfiguration(), 
    PER_REGIONSERVER_QUEUE_SIZE);

  byte[][] startRows = htable.getStartKeys();
  byte[] row = startRows[1];
  assertTrue("2nd region should not start with empty row", row != null && row.length > 0);

  Put put = new Put(row).add(FAMILY, QUALIFIER1, VALUE1);
  assertTrue("multiplexer.put returns", multiplexer.put(TABLE, put));

  checkExistence(htable, row, FAMILY, QUALIFIER1, VALUE1);

  // Now let's shutdown the regionserver and let regions moved to other servers.
  HRegionLocation loc = htable.getRegionLocation(row);
  MiniHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster(); 
  hbaseCluster.stopRegionServer(loc.getServerName());
  TEST_UTIL.waitUntilAllRegionsAssigned(TABLE);

  // put with multiplexer.
  put = new Put(row).add(FAMILY, QUALIFIER2, VALUE2);
  assertTrue("multiplexer.put returns", multiplexer.put(TABLE, put));

  checkExistence(htable, row, FAMILY, QUALIFIER2, VALUE2);
}
项目:ditb    文件:TestRegionPlacement.java   
/**
 * Verify the number of region movement is expected
 */
private void verifyRegionMovementNum(int expected)
    throws InterruptedException, IOException {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HMaster m = cluster.getMaster();
  int lastRegionOpenedCount = m.assignmentManager.getNumRegionsOpened();
  // get the assignments start to execute
  m.balance();

  int retry = 10;
  long sleep = 3000;
  int attempt = 0;
  int currentRegionOpened, regionMovement;
  do {
    currentRegionOpened = m.assignmentManager.getNumRegionsOpened();
    regionMovement= currentRegionOpened - lastRegionOpenedCount;
    LOG.debug("There are " + regionMovement + "/" + expected +
        " regions moved after " + attempt + " attempts");
    Thread.sleep((++attempt) * sleep);
  } while (regionMovement != expected && attempt <= retry);

  // update the lastRegionOpenedCount
  lastRegionOpenedCount = currentRegionOpened;

  assertEquals("There are only " + regionMovement + " instead of "
        + expected + " region movement for " + attempt + " attempts",
        regionMovement, expected);
}
项目:ditb    文件:TestAssignmentManagerOnCluster.java   
/**
 * Test force unassign/assign a region of a disabled table
 */
@Test (timeout=60000)
public void testAssignDisabledRegion() throws Exception {
  TableName table = TableName.valueOf("testAssignDisabledRegion");
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  MyMaster master = null;
  try {
    HTableDescriptor desc = new HTableDescriptor(table);
    desc.addFamily(new HColumnDescriptor(FAMILY));
    admin.createTable(desc);

    Table meta = new HTable(conf, TableName.META_TABLE_NAME);
    HRegionInfo hri = new HRegionInfo(
      desc.getTableName(), Bytes.toBytes("A"), Bytes.toBytes("Z"));
    MetaTableAccessor.addRegionToMeta(meta, hri);

    // Assign the region
    master = (MyMaster)cluster.getMaster();
    master.assignRegion(hri);
    AssignmentManager am = master.getAssignmentManager();
    RegionStates regionStates = am.getRegionStates();
    assertTrue(am.waitForAssignment(hri));

    // Disable the table
    admin.disableTable(table);
    assertTrue(regionStates.isRegionOffline(hri));

    // You can't assign a disabled region
    am.assign(hri, true, true);
    assertTrue(regionStates.isRegionOffline(hri));

    // You can't unassign a disabled region either
    am.unassign(hri, true);
    assertTrue(regionStates.isRegionOffline(hri));
  } finally {
    TEST_UTIL.deleteTable(table);
  }
}
项目:ditb    文件:TestMaster.java   
@Test
public void testMoveRegionWhenNotInitialized() {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HMaster m = cluster.getMaster();
  try {
    m.setInitialized(false); // fake it, set back later
    HRegionInfo meta = HRegionInfo.FIRST_META_REGIONINFO;
    m.move(meta.getEncodedNameAsBytes(), null);
    fail("Region should not be moved since master is not initialized");
  } catch (IOException ioe) {
    assertTrue(ioe instanceof PleaseHoldException);
  } finally {
    m.setInitialized(true);
  }
}
项目:ditb    文件:TestGetLastFlushedSequenceId.java   
@Test
public void test() throws IOException, InterruptedException {
  testUtil.getHBaseAdmin().createNamespace(
    NamespaceDescriptor.create(tableName.getNamespaceAsString()).build());
  HTable table = testUtil.createTable(tableName, families);
  table.put(new Put(Bytes.toBytes("k")).add(family, Bytes.toBytes("q"), Bytes.toBytes("v")));
  table.flushCommits();
  MiniHBaseCluster cluster = testUtil.getMiniHBaseCluster();
  List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
  Region region = null;
  for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
    HRegionServer hrs = rsts.get(i).getRegionServer();
    for (Region r : hrs.getOnlineRegions(tableName)) {
      region = r;
      break;
    }
  }
  assertNotNull(region);
  Thread.sleep(2000);
  RegionStoreSequenceIds ids =
      testUtil.getHBaseCluster().getMaster()
          .getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes());
  assertEquals(HConstants.NO_SEQNUM, ids.getLastFlushedSequenceId());
  // This will be the sequenceid just before that of the earliest edit in memstore.
  long storeSequenceId = ids.getStoreSequenceId(0).getSequenceId();
  assertTrue(storeSequenceId > 0);
  testUtil.getHBaseAdmin().flush(tableName);
  Thread.sleep(2000);
  ids =
      testUtil.getHBaseCluster().getMaster()
          .getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes());
  assertTrue(ids.getLastFlushedSequenceId() + " > " + storeSequenceId,
    ids.getLastFlushedSequenceId() > storeSequenceId);
  assertEquals(ids.getLastFlushedSequenceId(), ids.getStoreSequenceId(0).getSequenceId());
  table.close();
}
项目:ditb    文件:TestCreateTableHandler.java   
@Test (timeout=300000)
public void testCreateTableWithSplitRegion() throws Exception {
  final TableName tableName = TableName.valueOf("testCreateTableWithSplitRegion");
  final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  final HMaster m = cluster.getMaster();
  final HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(FAMILYNAME));
  byte[] splitPoint = Bytes.toBytes("split-point");
  long ts = System.currentTimeMillis();
  HRegionInfo d1 = new HRegionInfo(desc.getTableName(), null, splitPoint, false, ts);
  HRegionInfo d2 = new HRegionInfo(desc.getTableName(), splitPoint, null, false, ts + 1);
  HRegionInfo parent = new HRegionInfo(desc.getTableName(), null, null, true, ts + 2);
  parent.setOffline(true);

  Path tempdir = m.getMasterFileSystem().getTempDir();
  FileSystem fs = m.getMasterFileSystem().getFileSystem();
  Path tempTableDir = FSUtils.getTableDir(tempdir, desc.getTableName());
  fs.delete(tempTableDir, true); // Clean up temp table dir if exists

  final HRegionInfo[] hRegionInfos = new HRegionInfo[] {d1, d2, parent};
  CreateTableHandler handler = new CreateTableHandler(m, m.getMasterFileSystem(),
    desc, cluster.getConfiguration(), hRegionInfos, m);
  handler.prepare();
  handler.process();
  for (int i = 0; i < 100; i++) {
    if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) {
      Thread.sleep(300);
    }
  }
  assertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(tableName));
  assertTrue(TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName));
  assertTrue(TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName, new byte[][] { splitPoint }));
  RegionStates regionStates = m.getAssignmentManager().getRegionStates();
  assertTrue("Parent should be in SPLIT state",
    regionStates.isRegionInState(parent, State.SPLIT));
}
项目:ditb    文件:TestCreateTableHandler.java   
private void abortAndStartNewMaster(final MiniHBaseCluster cluster) throws IOException {
  cluster.abortMaster(0);
  cluster.waitOnMaster(0);
  LOG.info("Starting new master");
  cluster.startMaster();
  LOG.info("Waiting for master to become active.");
  cluster.waitForActiveAndReadyMaster();
}
项目:ditb    文件:TestMasterFailoverBalancerPersistence.java   
/**
 * Test that if the master fails, the load balancer maintains its
 * state (running or not) when the next master takes over
 *
 * @throws Exception
 */
@Test(timeout = 240000)
public void testMasterFailoverBalancerPersistence() throws Exception {
  final int NUM_MASTERS = 3;
  final int NUM_RS = 1;

  // Start the cluster
  HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();

  TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();

  assertTrue(cluster.waitForActiveAndReadyMaster());
  HMaster active = cluster.getMaster();
  // check that the balancer is on by default for the active master
  ClusterStatus clusterStatus = active.getClusterStatus();
  assertTrue(clusterStatus.isBalancerOn());

  active = killActiveAndWaitForNewActive(cluster);

  // ensure the load balancer is still running on new master
  clusterStatus = active.getClusterStatus();
  assertTrue(clusterStatus.isBalancerOn());

  // turn off the load balancer
  active.balanceSwitch(false);

  // once more, kill active master and wait for new active master to show up
  active = killActiveAndWaitForNewActive(cluster);

  // ensure the load balancer is not running on the new master
  clusterStatus = active.getClusterStatus();
  assertFalse(clusterStatus.isBalancerOn());

  // Stop the cluster
  TEST_UTIL.shutdownMiniCluster();
}
项目:ditb    文件:TestMasterFailoverBalancerPersistence.java   
/**
 * Kill the master and wait for a new active master to show up
 *
 * @param cluster
 * @return the new active master
 * @throws InterruptedException
 * @throws java.io.IOException
 */
private HMaster killActiveAndWaitForNewActive(MiniHBaseCluster cluster)
    throws InterruptedException, IOException {
  int activeIndex = getActiveMasterIndex(cluster);
  HMaster active = cluster.getMaster();
  cluster.stopMaster(activeIndex);
  cluster.waitOnMaster(activeIndex);
  assertTrue(cluster.waitForActiveAndReadyMaster());
  // double check this is actually a new master
  HMaster newActive = cluster.getMaster();
  assertFalse(active == newActive);
  return newActive;
}
项目:ditb    文件:TestMasterFailoverBalancerPersistence.java   
/**
 * return the index of the active master in the cluster
 *
 * @throws org.apache.hadoop.hbase.MasterNotRunningException
 *          if no active master found
 */
private int getActiveMasterIndex(MiniHBaseCluster cluster) throws MasterNotRunningException {
  // get all the master threads
  List<JVMClusterUtil.MasterThread> masterThreads = cluster.getMasterThreads();

  for (int i = 0; i < masterThreads.size(); i++) {
    if (masterThreads.get(i).getMaster().isActiveMaster()) {
      return i;
    }
  }
  throw new MasterNotRunningException();
}
项目:ditb    文件:TestZKBasedOpenCloseRegion.java   
/**
 * Test we reopen a region once closed.
 * @throws Exception
 */
@Test (timeout=300000) public void testReOpenRegion()
throws Exception {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  LOG.info("Number of region servers = " +
    cluster.getLiveRegionServerThreads().size());

  int rsIdx = 0;
  HRegionServer regionServer =
    TEST_UTIL.getHBaseCluster().getRegionServer(rsIdx);
  HRegionInfo hri = getNonMetaRegion(
    ProtobufUtil.getOnlineRegions(regionServer.getRSRpcServices()));
  LOG.debug("Asking RS to close region " + hri.getRegionNameAsString());

  LOG.info("Unassign " + hri.getRegionNameAsString());
  cluster.getMaster().assignmentManager.unassign(hri);

  while (!cluster.getMaster().assignmentManager.wasClosedHandlerCalled(hri)) {
    Threads.sleep(100);
  }

  while (!cluster.getMaster().assignmentManager.wasOpenedHandlerCalled(hri)) {
    Threads.sleep(100);
  }

  LOG.info("Done with testReOpenRegion");
}