@Test public void testMasterCoprocessorsReported() { // HBASE 4070: Improve region server metrics to report loaded coprocessors // to master: verify that the master is reporting the correct set of // loaded coprocessors. final String loadedMasterCoprocessorsVerify = "[" + masterCoprocessor.getSimpleName() + "]"; String loadedMasterCoprocessors = java.util.Arrays.toString( TEST_UTIL.getHBaseCluster().getMaster().getMasterCoprocessors()); assertEquals(loadedMasterCoprocessorsVerify, loadedMasterCoprocessors); }
@Test public void testErrorBeforeUpdate() throws IOException, ReplicationException { ((MockHMaster) UTIL.getHBaseCluster().getMaster()).reset(true); doTest(); }
@Test public void testStopped() throws Exception { //shutdown hbase only. then check flag file. MiniHBaseCluster cluster = UTIL.getHBaseCluster(); LOG.info("shutdown hbase cluster..."); cluster.shutdown(); LOG.info("wait for the hbase cluster shutdown..."); cluster.waitUntilShutDown(); Configuration conf = UTIL.getConfiguration(); FileSystem fs = FileSystem.get(conf); Path resultFile = new Path(UTIL.getDataTestDirOnTestFS(), MASTER_FILE); assertTrue("Master flag file should have been created",fs.exists(resultFile)); resultFile = new Path(UTIL.getDataTestDirOnTestFS(), REGIONSERVER_FILE); assertTrue("RegionServer flag file should have been created",fs.exists(resultFile)); } }
@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); } }
@Test public void testLocateAfter() throws IOException, InterruptedException, ExecutionException { byte[] row = Bytes.toBytes("1"); byte[] splitKey = Arrays.copyOf(row, 2); TEST_UTIL.createTable(TABLE_NAME, FAMILY, new byte[][] { splitKey }); TEST_UTIL.waitTableAvailable(TABLE_NAME); HRegionLocation currentLoc = getDefaultRegionLocation(TABLE_NAME, row, RegionLocateType.CURRENT, false).get(); ServerName currentServerName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName(); assertLocEquals(EMPTY_START_ROW, splitKey, currentServerName, currentLoc); HRegionLocation afterLoc = getDefaultRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER, false).get(); ServerName afterServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()) .filter(rs -> rs.getRegions(TABLE_NAME).stream() .anyMatch(r -> Bytes.equals(splitKey, r.getRegionInfo().getStartKey()))) .findAny().get().getServerName(); assertLocEquals(splitKey, EMPTY_END_ROW, afterServerName, afterLoc); assertSame(afterLoc, getDefaultRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER, false).get()); }
@Test public void testFlushRegionServer() throws Exception { try (Admin admin = TEST_UTIL.getAdmin()) { for (HRegionServer rs : TEST_UTIL.getHBaseCluster() .getLiveRegionServerThreads() .stream().map(JVMClusterUtil.RegionServerThread::getRegionServer) .collect(Collectors.toList())) { admin.flushRegionServer(rs.getServerName()); assertFalse(getRegionInfo(rs).stream().anyMatch(r -> r.getMemStoreDataSize() != 0)); } } }
/** * Atomic bulk load. */ @Test public void testAtomicBulkLoad() throws Exception { TableName TABLE_NAME = TableName.valueOf("atomicBulkLoad"); int millisToRun = 30000; int numScanners = 50; // Set createWALDir to true and use default values for other options. UTIL.startMiniCluster(StartMiniClusterOption.builder().createWALDir(true).build()); try { WAL log = UTIL.getHBaseCluster().getRegionServer(0).getWAL(null); FindBulkHBaseListener listener = new FindBulkHBaseListener(); log.registerWALActionsListener(listener); runAtomicBulkloadTest(TABLE_NAME, millisToRun, numScanners); assertThat(listener.isFound(), is(true)); } finally { UTIL.shutdownMiniCluster(); } }
private void validateSingleRegionServerAssignment(Connection connection, int numRegions, int numReplica) throws IOException { SnapshotOfRegionAssignmentFromMeta snapshot = new SnapshotOfRegionAssignmentFromMeta( connection); snapshot.initialize(); Map<RegionInfo, ServerName> regionToServerMap = snapshot.getRegionToRegionServerMap(); assertEquals(regionToServerMap.size(), numRegions * numReplica); Map<ServerName, List<RegionInfo>> serverToRegionMap = snapshot.getRegionServerToRegionMap(); assertEquals("One Region Only", 1, serverToRegionMap.keySet().size()); for (Map.Entry<ServerName, List<RegionInfo>> entry : serverToRegionMap.entrySet()) { if (entry.getKey().equals(TEST_UTIL.getHBaseCluster().getMaster().getServerName())) { continue; } assertEquals(entry.getValue().size(), numRegions * numReplica); } } }
private void testSwitchRpcThrottle(Admin admin, boolean oldRpcThrottle, boolean newRpcThrottle) throws IOException { boolean state = admin.switchRpcThrottle(newRpcThrottle); Assert.assertEquals(oldRpcThrottle, state); Assert.assertEquals(newRpcThrottle, admin.isRpcThrottleEnabled()); TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream() .forEach(rs -> Assert.assertEquals(newRpcThrottle, rs.getRegionServer().getRegionServerRpcQuotaManager().isRpcThrottleEnabled())); }
private void moveRegion(Table table, int index) throws IOException{ List<Pair<RegionInfo, ServerName>> regions = MetaTableAccessor .getTableRegionsAndLocations(TEST_UTIL.getConnection(), table.getName()); assertEquals(1, regions.size()); RegionInfo regionInfo = regions.get(0).getFirst(); ServerName name = TEST_UTIL.getHBaseCluster().getRegionServer(index).getServerName(); TEST_UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(name.getServerName())); }
private void resetProcExecutorTestingKillFlag() { ProcedureExecutor<MasterProcedureEnv> procExec = UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); assertTrue("expected executor to be running", procExec.isRunning()); }
private void testDeleteWithFailoverAtStep(final int step) throws Exception { final TableName tableName = TableName.valueOf("testDeleteWithFailoverAtStep" + step); // create the table byte[][] splitKeys = null; RegionInfo[] regions = MasterProcedureTestingUtility.createTable( getMasterProcedureExecutor(), tableName, splitKeys, "f1", "f2"); Path tableDir = FSUtils.getTableDir(getRootDir(), tableName); MasterProcedureTestingUtility.validateTableCreation( UTIL.getHBaseCluster().getMaster(), tableName, regions, "f1", "f2"); UTIL.getAdmin().disableTable(tableName); ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); ProcedureTestingUtility.setKillBeforeStoreUpdate(procExec, true); ProcedureTestingUtility.setToggleKillBeforeStoreUpdate(procExec, true); // Start the Delete procedure && kill the executor long procId = procExec.submitProcedure( new DeleteTableProcedure(procExec.getEnvironment(), tableName)); testRecoveryAndDoubleExecution(UTIL, procId, step); MasterProcedureTestingUtility.validateTableDeletion( UTIL.getHBaseCluster().getMaster(), tableName); }
public void setupCluster() throws Exception { setupConf(UTIL.getConfiguration()); StartMiniClusterOption option = StartMiniClusterOption.builder() .numRegionServers(NUM_REGION_SERVERS).numDataNodes(NUM_REGION_SERVERS) .createRootDir(true).build(); UTIL.startMiniCluster(option); rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); fs = rootDir.getFileSystem(UTIL.getConfiguration()); }
@Test public void testObserverAddedByDefault() throws Exception { final HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); final MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost(); Set<String> coprocessorNames = cpHost.getCoprocessors(); assertTrue( "Did not find MasterQuotasObserver in list of CPs: " + coprocessorNames, coprocessorNames.contains(MasterQuotasObserver.class.getSimpleName())); }
@Test public void testGetWALsToSplit() throws Exception { TEST_UTIL.createTable(TABLE_NAME, FAMILY, TEST_UTIL.KEYS_FOR_HBA_CREATE_TABLE); // load table TEST_UTIL.loadTable(TEST_UTIL.getConnection().getTable(TABLE_NAME), FAMILY); ServerName metaServer = TEST_UTIL.getHBaseCluster().getServerHoldingMeta(); List<FileStatus> metaWals = splitWALManager.getWALsToSplit(metaServer, true); Assert.assertEquals(1, metaWals.size()); List<FileStatus> wals = splitWALManager.getWALsToSplit(metaServer, false); Assert.assertEquals(1, wals.size()); ServerName testServer = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream() .map(rs -> rs.getRegionServer().getServerName()).filter(rs -> rs != metaServer).findAny() .get(); metaWals = splitWALManager.getWALsToSplit(testServer, true); Assert.assertEquals(0, metaWals.size()); }
@Test public void testRegionServerCoprocessorServiceError() throws Exception { final ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName(); DummyRegionServerEndpointProtos.DummyRequest request = DummyRegionServerEndpointProtos.DummyRequest.getDefaultInstance(); try { admin .<DummyRegionServerEndpointProtos.DummyService.Stub, DummyRegionServerEndpointProtos.DummyResponse> coprocessorService( DummyRegionServerEndpointProtos.DummyService::newStub, (s, c, done) -> s.dummyThrow(c, request, done), serverName).get(); fail("Should have thrown an exception"); } catch (Exception e) { assertTrue(e.getCause() instanceof RetriesExhaustedException); assertTrue(e.getCause().getMessage().contains(WHAT_TO_THROW.getClass().getName().trim())); } }
@Test public void testErrorAfterUpdate() throws IOException, ReplicationException { ((MockHMaster) UTIL.getHBaseCluster().getMaster()).reset(false); doTest(); }
@Test public void testRegionMove() throws InterruptedException, ExecutionException, IOException { // This will leave a cached entry in location cache HRegionLocation loc = CONN.getRegionLocator(TABLE_NAME).getRegionLocation(ROW).get(); int index = TEST_UTIL.getHBaseCluster().getServerWith(loc.getRegion().getRegionName()); TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(), Bytes.toBytes( TEST_UTIL.getHBaseCluster().getRegionServer(1 - index).getServerName().getServerName())); AsyncTable<?> table = CONN.getTableBuilder(TABLE_NAME).setRetryPause(100, TimeUnit.MILLISECONDS) .setMaxRetries(30).build(); table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)).get(); // move back TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(), Bytes.toBytes(loc.getServerName().getServerName())); Result result = table.get(new Get(ROW).addColumn(FAMILY, QUALIFIER)).get(); assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER)); }
@Test public void testOnlineConfigChange() throws IOException { LOG.debug("Starting the test"); Admin admin = TEST_UTIL.getAdmin(); ServerName server = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName(); admin.updateConfiguration(server); }
@After public void cleanup() throws Exception, KeeperException { for (HTableDescriptor table : ADMIN.listTables()) { ADMIN.disableTable(table.getTableName()); deleteTable(table.getTableName()); } for (NamespaceDescriptor ns : ADMIN.listNamespaceDescriptors()) { if (ns.getName().startsWith(prefix)) { ADMIN.deleteNamespace(ns.getName()); } } assertTrue("Quota manager not initialized", UTIL.getHBaseCluster().getMaster() .getMasterQuotaManager().isQuotaInitialized()); }