org.apache.hadoop.hbase.MiniHBaseCluster Java Examples

The following examples show how to use org.apache.hadoop.hbase.MiniHBaseCluster. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRegionMover.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegionServerPort() {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HRegionServer regionServer = cluster.getRegionServer(0);
  String rsName = regionServer.getServerName().getHostname();

  final int PORT = 16021;
  Configuration conf = TEST_UTIL.getConfiguration();
  String originalPort = conf.get(HConstants.REGIONSERVER_PORT);
  conf.set(HConstants.REGIONSERVER_PORT, Integer.toString(PORT));
  RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, conf);
  assertEquals(PORT, rmBuilder.port);
  if (originalPort != null) {
    conf.set(HConstants.REGIONSERVER_PORT, originalPort);
  }
}
 
Example #2
Source File: TestMasterObserver.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testNamespaceOperations() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  String testNamespace = "observed_ns";
  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);

  // create a table
  Admin admin = UTIL.getAdmin();

  admin.listNamespaces();
  assertTrue("preListNamespaces should have been called", cp.preListNamespacesCalled);
  assertTrue("postListNamespaces should have been called", cp.postListNamespacesCalled);

  admin.createNamespace(NamespaceDescriptor.create(testNamespace).build());
  assertTrue("Test namespace should be created", cp.wasCreateNamespaceCalled());

  assertNotNull(admin.getNamespaceDescriptor(testNamespace));
  assertTrue("Test namespace descriptor should have been called",
      cp.wasGetNamespaceDescriptorCalled());
  // This test used to do a bunch w/ bypass but bypass of these table and namespace stuff has
  // been removed so the testing code was removed.
}
 
Example #3
Source File: TestMasterObserver.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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 = host.findCoprocessor(CPMasterObserver.class);
  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());
}
 
Example #4
Source File: IndexLoadBalancerIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 180000)
public void testRandomAssignmentDuringIndexTableEnable() throws Exception {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    master.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", false);
    TableName tableName = TableName.valueOf("testRandomAssignmentDuringIndexTableEnable");
    TableName indexTableName =
            TableName.valueOf("testRandomAssignmentDuringIndexTableEnable_index");
    createUserAndIndexTable(tableName, indexTableName);
    admin.disableTable(tableName);
    admin.disableTable(indexTableName);
    admin.enableTable(tableName);
    admin.enableTable(indexTableName);
    boolean isRegionColocated =
            checkForColocation(master, tableName.getNameAsString(), indexTableName
                    .getNameAsString());
    assertTrue("User regions and index regions should colocate.", isRegionColocated);

}
 
Example #5
Source File: TestRSGroupMajorCompactionTTL.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
  utility = new HBaseTestingUtility();
  Configuration conf = utility.getConfiguration();
  RSGroupUtil.enableRSGroup(conf);
  conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, NUM_SLAVES_BASE);
  conf.setInt("hbase.hfile.compaction.discharger.interval", 10);
  utility.startMiniCluster(NUM_SLAVES_BASE);
  MiniHBaseCluster cluster = utility.getHBaseCluster();
  final HMaster master = cluster.getMaster();

  //wait for balancer to come online
  utility.waitFor(60000, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() {
      return master.isInitialized() &&
          ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline();
    }
  });
  admin = utility.getAdmin();
}
 
Example #6
Source File: TestRSGroupsOfflineMode.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  TEST_UTIL = new HBaseTestingUtility();
  RSGroupUtil.enableRSGroup(TEST_UTIL.getConfiguration());
  TEST_UTIL.getConfiguration().set(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, "1");
  StartMiniClusterOption option =
    StartMiniClusterOption.builder().numMasters(2).numRegionServers(3).numDataNodes(3).build();
  TEST_UTIL.startMiniCluster(option);
  cluster = TEST_UTIL.getHBaseCluster();
  master = ((MiniHBaseCluster) cluster).getMaster();
  master.balanceSwitch(false);
  hbaseAdmin = TEST_UTIL.getAdmin();
  // wait till the balancer is in online mode
  TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      return master.isInitialized() &&
        ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline() &&
        master.getServerManager().getOnlineServersList().size() >= 3;
    }
  });
}
 
Example #7
Source File: TestWALRecoveryCaching.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * @param cluster
 * @param indexTable
 * @param primaryTable
 * @return
 * @throws Exception
 */
private ServerName getSharedServer(MiniHBaseCluster cluster, byte[] indexTable,
    byte[] primaryTable) throws Exception {
  Set<ServerName> indexServers = getServersForTable(cluster, indexTable);
  Set<ServerName> primaryServers = getServersForTable(cluster, primaryTable);

  Set<ServerName> joinSet = new HashSet<ServerName>(indexServers);
  joinSet.addAll(primaryServers);
  // if there is already an overlap, then find it and return it
  if (joinSet.size() < indexServers.size() + primaryServers.size()) {
    // find the first overlapping server
    for (ServerName server : joinSet) {
      if (indexServers.contains(server) && primaryServers.contains(server)) {
        return server;
      }
    }
    throw new RuntimeException(
        "Couldn't find a matching server on which both the primary and index table live, "
            + "even though they have overlapping server sets");
  }
  return null;
}
 
Example #8
Source File: TestClassLoading.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
// HBASE-3516: Test CP Class loading from local file system
public void testClassLoadingFromLocalFS() throws Exception {
  File jarFile = buildCoprocessorJar(cpName3);

  // create a table that references the jar
  TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf(cpName3));
  tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes("test")).build());
  tdb.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName3 + "|" +
    Coprocessor.PRIORITY_USER);
  TableDescriptor tableDescriptor = tdb.build();
  Admin admin = TEST_UTIL.getAdmin();
  admin.createTable(tableDescriptor);
  waitForTable(tableDescriptor.getTableName());

  // verify that the coprocessor was loaded
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionInfo().getRegionNameAsString().startsWith(cpName3)) {
      found = (region.getCoprocessorHost().findCoprocessor(cpName3) != null);
    }
  }
  assertTrue("Class " + cpName3 + " was missing on a region", found);
}
 
Example #9
Source File: TestWALRecoveryCaching.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * @param cluster
 * @param indexTable
 * @param primaryTable
 * @return
 * @throws Exception
 */
private ServerName getSharedServer(MiniHBaseCluster cluster, byte[] indexTable,
    byte[] primaryTable) throws Exception {
  Set<ServerName> indexServers = getServersForTable(cluster, indexTable);
  Set<ServerName> primaryServers = getServersForTable(cluster, primaryTable);

  Set<ServerName> joinSet = new HashSet<ServerName>(indexServers);
  joinSet.addAll(primaryServers);
  // if there is already an overlap, then find it and return it
  if (joinSet.size() < indexServers.size() + primaryServers.size()) {
    // find the first overlapping server
    for (ServerName server : joinSet) {
      if (indexServers.contains(server) && primaryServers.contains(server)) {
        return server;
      }
    }
    throw new RuntimeException(
        "Couldn't find a matching server on which both the primary and index table live, "
            + "even though they have overlapping server sets");
  }
  return null;
}
 
Example #10
Source File: TestRegionServerCoprocessorExceptionWithAbort.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
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();
  }
}
 
Example #11
Source File: TestRegionMover.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithAck() throws Exception {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HRegionServer regionServer = cluster.getRegionServer(0);
  String rsName = regionServer.getServerName().getAddress().toString();
  int numRegions = regionServer.getNumberOfOnlineRegions();
  RegionMoverBuilder rmBuilder =
    new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8);
  try (RegionMover rm = rmBuilder.build()) {
    LOG.info("Unloading " + regionServer.getServerName());
    rm.unload();
    assertEquals(0, regionServer.getNumberOfOnlineRegions());
    LOG.info("Successfully Unloaded\nNow Loading");
    rm.load();
    assertEquals(numRegions, regionServer.getNumberOfOnlineRegions());
    // Repeat the same load. It should be very fast because all regions are already moved.
    rm.load();
  }
}
 
Example #12
Source File: TestSeparateClientZKCluster.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testMasterSwitch() throws Exception {
  // get an admin instance and issue some request first
  Connection conn = TEST_UTIL.getConnection();
  try (Admin admin = conn.getAdmin()) {
    LOG.debug("Tables: " + admin.listTableDescriptors());
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    // switch active master
    HMaster master = cluster.getMaster();
    master.stopMaster();
    LOG.info("Stopped master {}", master.getServerName());
    while (!master.isShutDown()) {
      Thread.sleep(200);
    }
    LOG.info("Shutdown master {}", master.getServerName());
    while (cluster.getMaster() == null || !cluster.getMaster().isInitialized()) {
      LOG.info("Get master {}", cluster.getMaster() == null? "null":
        cluster.getMaster().getServerName());
      Thread.sleep(200);
    }
    LOG.info("Got master {}", cluster.getMaster().getServerName());
    // confirm client access still works
    Assert.assertTrue(admin.balance(false));
  }
}
 
Example #13
Source File: TestWALRecoveryCaching.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param cluster
 * @param indexTable
 * @param primaryTable
 * @return
 * @throws Exception
 */
private ServerName getSharedServer(MiniHBaseCluster cluster, byte[] indexTable,
    byte[] primaryTable) throws Exception {
  Set<ServerName> indexServers = getServersForTable(cluster, indexTable);
  Set<ServerName> primaryServers = getServersForTable(cluster, primaryTable);

  Set<ServerName> joinSet = new HashSet<ServerName>(indexServers);
  joinSet.addAll(primaryServers);
  // if there is already an overlap, then find it and return it
  if (joinSet.size() < indexServers.size() + primaryServers.size()) {
    // find the first overlapping server
    for (ServerName server : joinSet) {
      if (indexServers.contains(server) && primaryServers.contains(server)) {
        return server;
      }
    }
    throw new RuntimeException(
        "Couldn't find a matching server on which both the primary and index table live, "
            + "even though they have overlapping server sets");
  }
  return null;
}
 
Example #14
Source File: TestMasterObserver.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testTableDescriptorsEnumeration() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
  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());
}
 
Example #15
Source File: TestMasterObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetProceduresOperation() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

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

  master.getProcedures();
  assertTrue(
    "Coprocessor should be called on get procedures request",
    cp.wasGetProceduresCalled());
}
 
Example #16
Source File: TestMasterObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetLocksOperation() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

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

  master.getLocks();
  assertTrue(
    "Coprocessor should be called on get locks request",
    cp.wasGetLocksCalled());
}
 
Example #17
Source File: MasterProcedureTestingUtility.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void waitBackupMaster(final HBaseTestingUtility testUtil,
    final HMaster oldMaster) throws Exception {
  MiniHBaseCluster cluster = testUtil.getMiniHBaseCluster();

  HMaster newMaster = cluster.getMaster();
  while (newMaster == null || newMaster == oldMaster) {
    Thread.sleep(250);
    newMaster = cluster.getMaster();
  }

  while (!(newMaster.isActiveMaster() && newMaster.isInitialized())) {
    Thread.sleep(250);
  }
}
 
Example #18
Source File: TestRSGroupsCPHookCalled.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRSGroupInfoOfServerCPHookCalled() throws Exception {
  ServerName masterServerName = ((MiniHBaseCluster) CLUSTER).getMaster().getServerName();
  ADMIN.getRSGroup(masterServerName.getAddress());
  assertTrue(OBSERVER.preGetRSGroupInfoOfServerCalled);
  assertTrue(OBSERVER.postGetRSGroupInfoOfServerCalled);
}
 
Example #19
Source File: TestFlushWithThroughputController.java    From hbase with Apache License 2.0 5 votes vote down vote up
private HStore getStoreWithName(TableName tableName) {
  MiniHBaseCluster cluster = hbtu.getMiniHBaseCluster();
  List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
  for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
    HRegionServer hrs = rsts.get(i).getRegionServer();
    for (Region region : hrs.getRegions(tableName)) {
      return ((HRegion) region).getStores().iterator().next();
    }
  }
  return null;
}
 
Example #20
Source File: TestRSGroupsBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void tearDownAfterMethod() throws Exception {
  deleteTableIfNecessary();
  deleteNamespaceIfNecessary();
  deleteGroups();

  for (ServerName sn : ADMIN.listDecommissionedRegionServers()) {
    ADMIN.recommissionRegionServer(sn, null);
  }
  assertTrue(ADMIN.listDecommissionedRegionServers().isEmpty());

  int missing = NUM_SLAVES_BASE - getNumServers();
  LOG.info("Restoring servers: " + missing);
  for (int i = 0; i < missing; i++) {
    ((MiniHBaseCluster) CLUSTER).startRegionServer();
  }
  ADMIN.addRSGroup("master");
  ServerName masterServerName = ((MiniHBaseCluster) CLUSTER).getMaster().getServerName();
  try {
    ADMIN.moveServersToRSGroup(Sets.newHashSet(masterServerName.getAddress()), "master");
  } catch (Exception ex) {
    LOG.warn("Got this on setup, FYI", ex);
  }
  assertTrue(OBSERVER.preMoveServersCalled);
  TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      LOG.info("Waiting for cleanup to finish " + ADMIN.listRSGroups());
      // Might be greater since moving servers back to default
      // is after starting a server

      return ADMIN.getRSGroup(RSGroupInfo.DEFAULT_GROUP).getServers().size() == NUM_SLAVES_BASE;
    }
  });
}
 
Example #21
Source File: TestMasterFailoverBalancerPersistence.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #22
Source File: TestCompactionWithThroughputController.java    From hbase with Apache License 2.0 5 votes vote down vote up
private HStore getStoreWithName(TableName tableName) {
  MiniHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
  List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
  for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
    HRegionServer hrs = rsts.get(i).getRegionServer();
    for (Region region : hrs.getRegions(tableName)) {
      return ((HRegion) region).getStores().iterator().next();
    }
  }
  return null;
}
 
Example #23
Source File: TestMasterObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testTableNamesEnumeration() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

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

  master.getMasterRpcServices().getTableNames(null,
      GetTableNamesRequest.newBuilder().build());
  assertTrue("Coprocessor should be called on table names request",
    cp.wasGetTableNamesCalled());
}
 
Example #24
Source File: TestMasterFailoverBalancerPersistence.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Test that if the master fails, the load balancer maintains its
 * state (running or not) when the next master takes over
 *
 * @throws Exception
 */
@Test
public void testMasterFailoverBalancerPersistence() throws Exception {
  // Start the cluster
  HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();

  StartMiniClusterOption option = StartMiniClusterOption.builder()
      .numMasters(3).build();
  TEST_UTIL.startMiniCluster(option);
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();

  assertTrue(cluster.waitForActiveAndReadyMaster());
  HMaster active = cluster.getMaster();
  // check that the balancer is on by default for the active master
  ClusterMetrics clusterStatus = active.getClusterMetrics();
  assertTrue(clusterStatus.getBalancerOn());

  active = killActiveAndWaitForNewActive(cluster);

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

  // 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.getClusterMetrics();
  assertFalse(clusterStatus.getBalancerOn());

  // Stop the cluster
  TEST_UTIL.shutdownMiniCluster();
}
 
Example #25
Source File: TestGetLastFlushedSequenceId.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {
  testUtil.getAdmin().createNamespace(
    NamespaceDescriptor.create(tableName.getNamespaceAsString()).build());
  Table table = testUtil.createTable(tableName, families);
  table.put(new Put(Bytes.toBytes("k"))
          .addColumn(family, Bytes.toBytes("q"), Bytes.toBytes("v")));
  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.getRegions(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.getAdmin().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();
}
 
Example #26
Source File: TestRegionMover.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * To test that we successfully exclude a server from the unloading process We test for the number
 * of regions on Excluded server and also test that regions are unloaded successfully
 */
@Test
public void testExclude() throws Exception {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  File excludeFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "exclude_file");
  FileWriter fos = new FileWriter(excludeFile);
  HRegionServer excludeServer = cluster.getRegionServer(1);
  String excludeHostname = excludeServer.getServerName().getHostname();
  int excludeServerPort = excludeServer.getServerName().getPort();
  int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions();
  String excludeServerName = excludeHostname + ":" + Integer.toString(excludeServerPort);
  fos.write(excludeServerName);
  fos.close();
  HRegionServer regionServer = cluster.getRegionServer(0);
  String rsName = regionServer.getServerName().getHostname();
  int port = regionServer.getServerName().getPort();
  String rs = rsName + ":" + Integer.toString(port);
  RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs, TEST_UTIL.getConfiguration())
    .ack(true).excludeFile(excludeFile.getCanonicalPath());
  try (RegionMover rm = rmBuilder.build()) {
    rm.unload();
    LOG.info("Unloading " + rs);
    assertEquals(0, regionServer.getNumberOfOnlineRegions());
    assertEquals(regionsExcludeServer, cluster.getRegionServer(1).getNumberOfOnlineRegions());
    LOG.info("Before:" + regionsExcludeServer + " After:" +
      cluster.getRegionServer(1).getNumberOfOnlineRegions());
  }
}
 
Example #27
Source File: TestHBaseStorage.java    From spork with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void oneTimeTearDown() throws Exception {
    // In HBase 0.90.1 and above we can use util.shutdownMiniHBaseCluster()
    // here instead.
    MiniHBaseCluster hbc = util.getHBaseCluster();
    if (hbc != null) {
        hbc.shutdown();
        hbc.join();
    }
    util.shutdownMiniZKCluster();
}
 
Example #28
Source File: TestWALRecoveryCaching.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Set<ServerName> getServersForTable(MiniHBaseCluster cluster, byte[] table)
    throws Exception {
  List<HRegion> indexRegions = cluster.getRegions(table);
  Set<ServerName> indexServers = new HashSet<ServerName>();
  for (HRegion region : indexRegions) {
    indexServers.add(cluster.getServerHoldingRegion(region.getRegionName()));
  }
  return indexServers;
}
 
Example #29
Source File: TestingPhoenixServer.java    From presto with Apache License 2.0 5 votes vote down vote up
private TestingPhoenixServer()
{
    // keep references to prevent GC from resetting the log levels
    apacheLogger = java.util.logging.Logger.getLogger("org.apache");
    apacheLogger.setLevel(Level.SEVERE);
    zookeeperLogger = java.util.logging.Logger.getLogger(ZooKeeperServer.class.getName());
    zookeeperLogger.setLevel(Level.OFF);
    securityLogger = java.util.logging.Logger.getLogger("SecurityLogger.org.apache");
    securityLogger.setLevel(Level.SEVERE);
    // to squelch the SecurityLogger,
    // instantiate logger with config above before config is overriden again in HBase test franework
    org.apache.commons.logging.LogFactory.getLog("SecurityLogger.org.apache.hadoop.hbase.server");
    this.conf.set("hbase.security.logger", "ERROR");
    this.conf.setInt(MASTER_INFO_PORT, -1);
    this.conf.setInt(REGIONSERVER_INFO_PORT, -1);
    this.conf.setInt(HBASE_CLIENT_RETRIES_NUMBER, 1);
    this.conf.setBoolean("phoenix.schema.isNamespaceMappingEnabled", true);
    this.conf.set("hbase.regionserver.wal.codec", "org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec");
    this.hbaseTestingUtility = new HBaseTestingUtility(conf);

    try {
        MiniZooKeeperCluster zkCluster = this.hbaseTestingUtility.startMiniZKCluster();
        port = zkCluster.getClientPort();

        MiniHBaseCluster hbaseCluster = hbaseTestingUtility.startMiniHBaseCluster(1, 4);
        hbaseCluster.waitForActiveAndReadyMaster();
        LOG.info("Phoenix server ready: %s", getJdbcUrl());
    }
    catch (Exception e) {
        throw new RuntimeException("Can't start phoenix server.", e);
    }
}
 
Example #30
Source File: AbstractTestDLS.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void abortMaster(MiniHBaseCluster cluster) throws InterruptedException {
  for (MasterThread mt : cluster.getLiveMasterThreads()) {
    if (mt.getMaster().isActiveMaster()) {
      mt.getMaster().abort("Aborting for tests", new Exception("Trace info"));
      mt.join();
      break;
    }
  }
  LOG.debug("Master is aborted");
}