org.apache.hadoop.hbase.HBaseTestingUtility Java Examples
The following examples show how to use
org.apache.hadoop.hbase.HBaseTestingUtility.
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: FlushTableAction.java From hbase with Apache License 2.0 | 6 votes |
@Override public void perform() throws Exception { HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility(); Admin admin = util.getAdmin(); // Don't try the flush if we're stopping if (context.isStopping()) { return; } getLogger().info("Performing action: Flush table " + tableName); try { admin.flush(tableName); } catch (Exception ex) { getLogger().warn("Flush failed, might be caused by other chaos: " + ex.getMessage()); } if (sleepTime > 0) { Thread.sleep(sleepTime); } }
Example #2
Source File: TestReplicationStuckWithDeletedTableCFs.java From hbase with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1"); conf1.setInt("replication.source.nb.capacity", 1); utility1 = new HBaseTestingUtility(conf1); utility1.startMiniZKCluster(); MiniZooKeeperCluster miniZK = utility1.getZkCluster(); conf1 = utility1.getConfiguration(); conf2 = HBaseConfiguration.create(conf1); conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2"); utility2 = new HBaseTestingUtility(conf2); utility2.setZkCluster(miniZK); utility1.startMiniCluster(1); utility2.startMiniCluster(1); admin1 = utility1.getAdmin(); admin2 = utility2.getAdmin(); }
Example #3
Source File: RebuildIndexConnectionPropsIT.java From phoenix with Apache License 2.0 | 6 votes |
@BeforeClass public static synchronized void doSetup() throws Exception { Configuration conf = HBaseConfiguration.create(); hbaseTestUtil = new HBaseTestingUtility(conf); Map<String, String> serverProps = new HashMap<>(); serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS); // need at least one retry otherwise test fails serverProps.put(QueryServices.INDEX_REBUILD_RPC_RETRIES_COUNTER, Long.toString(NUM_RPC_RETRIES)); setUpConfigForMiniCluster(conf, new ReadOnlyProps(serverProps.entrySet().iterator())); hbaseTestUtil.startMiniCluster(); // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort(); url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; Properties driverProps = PropertiesUtil.deepCopy(TEST_PROPERTIES); DriverManager.registerDriver(PhoenixDriver.INSTANCE); try (PhoenixConnection phxConn = DriverManager.getConnection(url, driverProps).unwrap(PhoenixConnection.class)) { } }
Example #4
Source File: TestMemStoreSegmentsIterator.java From hbase with Apache License 2.0 | 6 votes |
@Before public void setup() throws IOException { Configuration conf = new Configuration(); HBaseTestingUtility hbaseUtility = new HBaseTestingUtility(conf); TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(TableName.valueOf(TABLE)); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(FAMILY)).build(); tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor); RegionInfo info = RegionInfoBuilder.newBuilder(TableName.valueOf(TABLE)).build(); Path rootPath = hbaseUtility.getDataTestDir(ROOT_SUB_PATH); this.wal = HBaseTestingUtility.createWal(conf, rootPath, info); this.region = HRegion.createHRegion(info, rootPath, conf, tableDescriptorBuilder.build(), this.wal, true); this.store = new HStore(this.region, columnFamilyDescriptor, conf, false); this.comparator = CellComparator.getInstance(); this.compactionKVMax = HConstants.COMPACTION_KV_MAX_DEFAULT; }
Example #5
Source File: TestReplicationStuckWithDroppedTable.java From hbase with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { conf1.set(ZOOKEEPER_ZNODE_PARENT, "/1"); conf1.setInt("replication.source.nb.capacity", 1); utility1 = new HBaseTestingUtility(conf1); utility1.startMiniZKCluster(); MiniZooKeeperCluster miniZK = utility1.getZkCluster(); conf1 = utility1.getConfiguration(); conf2 = HBaseConfiguration.create(conf1); conf2.set(ZOOKEEPER_ZNODE_PARENT, "/2"); utility2 = new HBaseTestingUtility(conf2); utility2.setZkCluster(miniZK); utility1.startMiniCluster(1); utility2.startMiniCluster(1); admin1 = utility1.getAdmin(); admin2 = utility2.getAdmin(); }
Example #6
Source File: TestEnableTable.java From hbase with Apache License 2.0 | 6 votes |
public static void createTable(HBaseTestingUtility testUtil, TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor, byte [][] splitKeys) throws Exception { // NOTE: We need a latch because admin is not sync, // so the postOp coprocessor method may be called after the admin operation returned. MasterSyncObserver observer = testUtil.getHBaseCluster().getMaster() .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class); observer.tableCreationLatch = new CountDownLatch(1); Admin admin = testUtil.getAdmin(); if (splitKeys != null) { admin.createTable(tableDescriptor, splitKeys); } else { admin.createTable(tableDescriptor); } observer.tableCreationLatch.await(); observer.tableCreationLatch = null; testUtil.waitUntilAllRegionsAssigned(tableDescriptor.getTableName()); }
Example #7
Source File: TestRSGroupMajorCompactionTTL.java From hbase with Apache License 2.0 | 6 votes |
@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 #8
Source File: SyncReplicationTestBase.java From hbase with Apache License 2.0 | 6 votes |
protected static void initTestingUtility(HBaseTestingUtility util, String zkParent) { util.setZkCluster(ZK_UTIL.getZkCluster()); Configuration conf = util.getConfiguration(); conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, zkParent); conf.setInt("replication.source.size.capacity", 102400); conf.setLong("replication.source.sleepforretries", 100); conf.setInt("hbase.regionserver.maxlogs", 10); conf.setLong("hbase.master.logcleaner.ttl", 10); conf.setInt("zookeeper.recovery.retry", 1); conf.setInt("zookeeper.recovery.retry.intervalmill", 10); conf.setLong(HConstants.THREAD_WAKE_FREQUENCY, 100); conf.setInt("replication.stats.thread.period.seconds", 5); conf.setBoolean("hbase.tests.use.shortcircuit.reads", false); conf.setLong("replication.sleep.before.failover", 2000); conf.setInt("replication.source.maxretriesmultiplier", 10); conf.setFloat("replication.source.ratio", 1.0f); conf.setBoolean("replication.source.eof.autorecovery", true); }
Example #9
Source File: TestScanner.java From hbase with Apache License 2.0 | 6 votes |
/** * Tests to do a sync flush during the middle of a scan. This is testing the StoreScanner * update readers code essentially. This is not highly concurrent, since its all 1 thread. * HBase-910. */ @Test public void testScanAndSyncFlush() throws Exception { this.region = TEST_UTIL.createLocalHRegion(TESTTABLEDESC, null, null); Table hri = new RegionAsTable(region); try { LOG.info("Added: " + HTestConst.addContent(hri, Bytes.toString(HConstants.CATALOG_FAMILY), Bytes.toString(HConstants.REGIONINFO_QUALIFIER))); int count = count(hri, -1, false); assertEquals(count, count(hri, 100, false)); // do a sync flush. } catch (Exception e) { LOG.error("Failed", e); throw e; } finally { HBaseTestingUtility.closeRegionAndWAL(this.region); } }
Example #10
Source File: TestRegionLocationFinder.java From hbase with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { cluster = TEST_UTIL.startMiniCluster(ServerNum); table = TEST_UTIL.createTable(tableName, FAMILY, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE); TEST_UTIL.waitTableAvailable(tableName, 1000); TEST_UTIL.loadTable(table, FAMILY); for (int i = 0; i < ServerNum; i++) { HRegionServer server = cluster.getRegionServer(i); for (HRegion region : server.getRegions(tableName)) { region.flush(true); } } finder.setConf(TEST_UTIL.getConfiguration()); finder.setServices(cluster.getMaster()); finder.setClusterMetrics(cluster.getMaster().getClusterMetrics()); }
Example #11
Source File: TestAccessControlFilter.java From hbase with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupBeforeClass() throws Exception { TEST_UTIL = new HBaseTestingUtility(); Configuration conf = TEST_UTIL.getConfiguration(); // Up the handlers; this test needs more than usual. conf.setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 10); enableSecurity(conf); verifyConfiguration(conf); // We expect 0.98 scanning semantics conf.setBoolean(AccessControlConstants.CF_ATTRIBUTE_EARLY_OUT, false); TEST_UTIL.startMiniCluster(); TEST_UTIL.waitTableEnabled(PermissionStorage.ACL_TABLE_NAME.getName(), 50000); READER = User.createUserForTesting(conf, "reader", new String[0]); LIMITED = User.createUserForTesting(conf, "limited", new String[0]); DENIED = User.createUserForTesting(conf, "denied", new String[0]); }
Example #12
Source File: TestRegionObserverScannerOpenHook.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testRegionObserverFlushTimeStacking() throws Exception { byte[] ROW = Bytes.toBytes("testRow"); byte[] TABLE = Bytes.toBytes(getClass().getName()); byte[] A = Bytes.toBytes("A"); byte[][] FAMILIES = new byte[][] { A }; // Use new HTU to not overlap with the DFS cluster started in #CompactionStacking Configuration conf = new HBaseTestingUtility().getConfiguration(); HRegion region = initHRegion(TABLE, getClass().getName(), conf, FAMILIES); RegionCoprocessorHost h = region.getCoprocessorHost(); h.load(NoDataFromFlush.class, Coprocessor.PRIORITY_HIGHEST, conf); h.load(EmptyRegionObsever.class, Coprocessor.PRIORITY_USER, conf); // put a row and flush it to disk Put put = new Put(ROW); put.addColumn(A, A, A); region.put(put); region.flush(true); Get get = new Get(ROW); Result r = region.get(get); assertNull( "Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: " + r, r.listCells()); HBaseTestingUtility.closeRegionAndWAL(region); }
Example #13
Source File: TestBucketCache.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testRetrieveFromMultipleFiles() throws Exception { final Path testDirInitial = createAndGetTestDir(); final Path newTestDir = new HBaseTestingUtility().getDataTestDir(); HBASE_TESTING_UTILITY.getTestFileSystem().mkdirs(newTestDir); String ioEngineName = new StringBuilder("files:").append(testDirInitial) .append("/bucket1.cache").append(FileIOEngine.FILE_DELIMITER).append(newTestDir) .append("/bucket2.cache").toString(); testRetrievalUtils(testDirInitial, ioEngineName); int[] smallBucketSizes = new int[]{3 * 1024, 5 * 1024}; String persistencePath = testDirInitial + "/bucket.persistence"; BucketCache bucketCache = new BucketCache(ioEngineName, capacitySize, constructedBlockSize, smallBucketSizes, writeThreads, writerQLen, persistencePath); assertFalse(new File(persistencePath).exists()); assertEquals(0, bucketCache.getAllocator().getUsedSize()); assertEquals(0, bucketCache.backingMap.size()); HBASE_TESTING_UTILITY.cleanupTestDir(); }
Example #14
Source File: TestReplicationKillRS.java From hbase with Apache License 2.0 | 6 votes |
private static Thread killARegionServer(final HBaseTestingUtility utility, final long timeout, final int rs) { Thread killer = new Thread() { @Override public void run() { try { Thread.sleep(timeout); utility.getHBaseCluster().getRegionServer(rs).stop("Stopping as part of the test"); } catch (Exception e) { LOG.error("Couldn't kill a region server", e); } } }; killer.setDaemon(true); killer.start(); return killer; }
Example #15
Source File: TestSyncReplicationActive.java From hbase with Apache License 2.0 | 6 votes |
private void verifyNoClusterIdInRemoteLog(HBaseTestingUtility utility, Path remoteDir, String peerId) throws Exception { FileSystem fs2 = utility.getTestFileSystem(); FileStatus[] files = fs2.listStatus(new Path(remoteDir, peerId)); Assert.assertTrue(files.length > 0); for (FileStatus file : files) { try ( Reader reader = WALFactory.createReader(fs2, file.getPath(), utility.getConfiguration())) { Entry entry = reader.next(); Assert.assertTrue(entry != null); while (entry != null) { Assert.assertEquals(entry.getKey().getClusterIds().size(), 0); entry = reader.next(); } } } }
Example #16
Source File: ContextClassloaderIT.java From phoenix with Apache License 2.0 | 6 votes |
@BeforeClass public static synchronized void setUpBeforeClass() throws Exception { Configuration conf = HBaseConfiguration.create(); setUpConfigForMiniCluster(conf); hbaseTestUtil = new HBaseTestingUtility(conf); hbaseTestUtil.startMiniCluster(); String clientPort = hbaseTestUtil.getConfiguration().get(QueryServices.ZOOKEEPER_PORT_ATTRIB); String url = JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + LOCALHOST + JDBC_PROTOCOL_SEPARATOR + clientPort + JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM; driver = initAndRegisterTestDriver(url, ReadOnlyProps.EMPTY_PROPS); Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement(); stmt.execute("CREATE TABLE test (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR)"); stmt.execute("UPSERT INTO test VALUES (1, 'name1')"); stmt.execute("UPSERT INTO test VALUES (2, 'name2')"); stmt.close(); conn.commit(); conn.close(); badContextClassloader = new URLClassLoader(new URL[] { File.createTempFile("invalid", ".jar").toURI().toURL() }, null); }
Example #17
Source File: CompactTableAction.java From hbase with Apache License 2.0 | 6 votes |
@Override public void perform() throws Exception { HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility(); Admin admin = util.getAdmin(); boolean major = RandomUtils.nextInt(0, 100) < majorRatio; getLogger().info("Performing action: Compact table " + tableName + ", major=" + major); try { if (major) { admin.majorCompact(tableName); } else { admin.compact(tableName); } } catch (Exception ex) { getLogger().warn("Compaction failed, might be caused by other chaos: " + ex.getMessage()); } if (sleepTime > 0) { Thread.sleep(sleepTime); } }
Example #18
Source File: SecureTestUtil.java From hbase with Apache License 2.0 | 6 votes |
/** * Revoke permissions on a namespace from the given user. Will wait until all active * AccessController instances have updated their permissions caches or will * throw an exception upon timeout (10 seconds). */ public static void revokeFromNamespace(final User caller, final HBaseTestingUtility util, final String user, final String namespace, final Permission.Action... actions) throws Exception { SecureTestUtil.updateACLs(util, new Callable<Void>() { @Override public Void call() throws Exception { Configuration conf = util.getConfiguration(); try (Connection connection = ConnectionFactory.createConnection(conf, caller)) { connection.getAdmin().revoke(new UserPermission(user, Permission.newBuilder(namespace).withActions(actions).build())); } return null; } }); }
Example #19
Source File: TestReadAndWriteRegionInfoFile.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testReadAndWriteRegionInfoFile() throws IOException, InterruptedException { RegionInfo ri = RegionInfoBuilder.FIRST_META_REGIONINFO; // Create a region. That'll write the .regioninfo file. FSTableDescriptors fsTableDescriptors = new FSTableDescriptors(FS, ROOT_DIR); FSTableDescriptors.tryUpdateMetaTableDescriptor(CONF, FS, ROOT_DIR, null); HRegion r = HBaseTestingUtility.createRegionAndWAL(ri, ROOT_DIR, CONF, fsTableDescriptors.get(TableName.META_TABLE_NAME)); // Get modtime on the file. long modtime = getModTime(r); HBaseTestingUtility.closeRegionAndWAL(r); Thread.sleep(1001); r = HRegion.openHRegion(ROOT_DIR, ri, fsTableDescriptors.get(TableName.META_TABLE_NAME), null, CONF); // Ensure the file is not written for a second time. long modtime2 = getModTime(r); assertEquals(modtime, modtime2); // Now load the file. HRegionFileSystem.loadRegionInfoFileContent(r.getRegionFileSystem().getFileSystem(), r.getRegionFileSystem().getRegionDir()); HBaseTestingUtility.closeRegionAndWAL(r); }
Example #20
Source File: HBaseMiniCluster.java From yuzhouwan with Apache License 2.0 | 5 votes |
@Test public void miniCluster() throws Exception { /** * https://github.com/apache/hbase/blob/master/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java */ System.setProperty(BASE_TEST_DIRECTORY_KEY, BASE_PATH.concat("data")); System.setProperty("hadoop.home.dir", "D:/apps/hadoop/hadoop-2.7.3/"); HBaseTestingUtility hbaseTestingUtility = hbaseOperation(); mapReduce(hbaseTestingUtility); }
Example #21
Source File: SecureTestUtil.java From hbase with Apache License 2.0 | 5 votes |
public static void checkTablePerms(HBaseTestingUtility testUtil, TableName table, byte[] family, byte[] column, Permission.Action... actions) throws IOException { Permission[] perms = new Permission[actions.length]; for (int i = 0; i < actions.length; i++) { perms[i] = Permission.newBuilder(table).withFamily(family).withQualifier(column) .withActions(actions[i]).build(); } checkTablePerms(testUtil, perms); }
Example #22
Source File: TestRegionReplicaSplit.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testAssignFakeReplicaRegion() throws Exception { TableName tn = TableName.valueOf(this.name.getMethodName()); Table table = null; try { table = createTableAndLoadData(tn); final RegionInfo fakeHri = RegionInfoBuilder.newBuilder(table.getName()).setStartKey(Bytes.toBytes("a")) .setEndKey(Bytes.toBytes("b")).setReplicaId(1) .setRegionId(System.currentTimeMillis()).build(); // To test AssignProcedure can defend this case. HTU.getMiniHBaseCluster().getMaster().getAssignmentManager().assign(fakeHri); // Wait until all assigns are done. HBaseTestingUtility.await(50, () -> { return HTU.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getActiveProcIds() .isEmpty(); }); // Make sure the region is not online. for (RegionServerThread rs : HTU.getMiniHBaseCluster().getRegionServerThreads()) { for (Region r : rs.getRegionServer().getRegions(table.getName())) { assertNotEquals(r.getRegionInfo(), fakeHri); } } } finally { if (table != null) { HTU.deleteTable(tn); } } }
Example #23
Source File: TestReplicationBase.java From hbase with Apache License 2.0 | 5 votes |
private static void startClusters() throws Exception { UTIL1.startMiniZKCluster(); MiniZooKeeperCluster miniZK = UTIL1.getZkCluster(); LOG.info("Setup first Zk"); UTIL2.setZkCluster(miniZK); LOG.info("Setup second Zk"); CONF_WITH_LOCALFS = HBaseConfiguration.create(CONF1); UTIL1.startMiniCluster(NUM_SLAVES1); // Have a bunch of slave servers, because inter-cluster shipping logic uses number of sinks // as a component in deciding maximum number of parallel batches to send to the peer cluster. UTIL2.startMiniCluster(NUM_SLAVES2); hbaseAdmin = ConnectionFactory.createConnection(CONF1).getAdmin(); TableDescriptor table = TableDescriptorBuilder.newBuilder(tableName) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(famName).setMaxVersions(100) .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(noRepfamName)).build(); Connection connection1 = ConnectionFactory.createConnection(CONF1); Connection connection2 = ConnectionFactory.createConnection(CONF2); try (Admin admin1 = connection1.getAdmin()) { admin1.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE); } try (Admin admin2 = connection2.getAdmin()) { admin2.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE); } UTIL1.waitUntilAllRegionsAssigned(tableName); UTIL2.waitUntilAllRegionsAssigned(tableName); htable1 = connection1.getTable(tableName); htable2 = connection2.getTable(tableName); }
Example #24
Source File: TestServerRemoteProcedure.java From hbase with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { util = new HBaseTestingUtility(); this.executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder() .setUncaughtExceptionHandler((t, e) -> LOG.warn("Uncaught: ", e)).build()); master = new MockMasterServices(util.getConfiguration(), this.regionsToRegionServers); rsDispatcher = new MockRSProcedureDispatcher(master); rsDispatcher.setMockRsExecutor(new NoopRSExecutor()); master.start(2, rsDispatcher); am = master.getAssignmentManager(); master.getServerManager().getOnlineServersList().stream() .forEach(serverName -> am.getRegionStates().getOrCreateServer(serverName)); }
Example #25
Source File: TestExportSnapshot.java From hbase with Apache License 2.0 | 5 votes |
static Path getLocalDestinationDir(HBaseTestingUtility htu) { Path path = htu.getDataTestDir("local-export-" + System.currentTimeMillis()); try { FileSystem fs = FileSystem.getLocal(htu.getConfiguration()); LOG.info("Local export destination path: " + path); return path.makeQualified(fs.getUri(), fs.getWorkingDirectory()); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
Example #26
Source File: SyncReplicationTestBase.java From hbase with Apache License 2.0 | 5 votes |
protected final void verifyNotReplicatedThroughRegion(HBaseTestingUtility util, int start, int end) throws IOException { HRegion region = util.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0); for (int i = start; i < end; i++) { assertTrue(region.get(new Get(Bytes.toBytes(i))).isEmpty()); } }
Example #27
Source File: AssignmentTestingUtil.java From hbase with Apache License 2.0 | 5 votes |
public static ServerName getServerHoldingRegion(final HBaseTestingUtility util, final RegionInfo hri) throws Exception { ServerName serverName = util.getMiniHBaseCluster().getServerHoldingRegion( hri.getTable(), hri.getRegionName()); ServerName amServerName = getMaster(util).getAssignmentManager().getRegionStates() .getRegionServerOfRegion(hri); // Make sure AM and MiniCluster agrees on the Server holding the region // and that the server is online. assertEquals(amServerName, serverName); assertEquals(true, getMaster(util).getServerManager().isServerOnline(serverName)); return serverName; }
Example #28
Source File: TestTableSnapshotInputFormat.java From hbase with Apache License 2.0 | 5 votes |
@Override public void testWithMockedMapReduce(HBaseTestingUtility util, String snapshotName, int numRegions, int numSplitsPerRegion, int expectedNumSplits, boolean setLocalityEnabledTo) throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); try { createTableAndSnapshot( util, tableName, snapshotName, getStartRow(), getEndRow(), numRegions); Configuration conf = util.getConfiguration(); conf.setBoolean(SNAPSHOT_INPUTFORMAT_LOCALITY_ENABLED_KEY, setLocalityEnabledTo); Job job = new Job(conf); Path tmpTableDir = util.getDataTestDirOnTestFS(snapshotName); Scan scan = new Scan().withStartRow(getStartRow()).withStopRow(getEndRow()); // limit the scan if (numSplitsPerRegion > 1) { TableMapReduceUtil.initTableSnapshotMapperJob(snapshotName, scan, TestTableSnapshotMapper.class, ImmutableBytesWritable.class, NullWritable.class, job, false, tmpTableDir, new RegionSplitter.UniformSplit(), numSplitsPerRegion); } else { TableMapReduceUtil.initTableSnapshotMapperJob(snapshotName, scan, TestTableSnapshotMapper.class, ImmutableBytesWritable.class, NullWritable.class, job, false, tmpTableDir); } verifyWithMockedMapReduce(job, numRegions, expectedNumSplits, getStartRow(), getEndRow()); } finally { util.getAdmin().deleteSnapshot(snapshotName); util.deleteTable(tableName); } }
Example #29
Source File: SnapshotTestingUtils.java From hbase with Apache License 2.0 | 5 votes |
public static void deleteArchiveDirectory(final HBaseTestingUtility util) throws IOException { // Ensure the archiver to be empty MasterFileSystem mfs = util.getMiniHBaseCluster().getMaster().getMasterFileSystem(); Path archiveDir = new Path(mfs.getRootDir(), HConstants.HFILE_ARCHIVE_DIRECTORY); mfs.getFileSystem().delete(archiveDir, true); }
Example #30
Source File: TestSCP.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testConcurrentSCPForSameServer() throws Exception { final TableName tableName = TableName.valueOf("testConcurrentSCPForSameServer"); try (Table t = createTable(tableName)) { // Load the table with a bit of data so some logs to split and some edits in each region. this.util.loadTable(t, HBaseTestingUtility.COLUMNS[0]); final int count = HBaseTestingUtility.countRows(t); assertTrue("expected some rows", count > 0); // find the first server that match the request and executes the test ServerName rsToKill = null; for (RegionInfo hri : util.getAdmin().getRegions(tableName)) { final ServerName serverName = AssignmentTestingUtil.getServerHoldingRegion(util, hri); if (AssignmentTestingUtil.isServerHoldingMeta(util, serverName) == true) { rsToKill = serverName; break; } } HMaster master = util.getHBaseCluster().getMaster(); final ProcedureExecutor<MasterProcedureEnv> pExecutor = master.getMasterProcedureExecutor(); ServerCrashProcedure procB = new ServerCrashProcedure(pExecutor.getEnvironment(), rsToKill, false, false); AssignmentTestingUtil.killRs(util, rsToKill); long procId = getSCPProcId(pExecutor); Procedure<?> procA = pExecutor.getProcedure(procId); LOG.info("submit SCP procedureA"); util.waitFor(5000, () -> procA.hasLock()); LOG.info("procedureA acquired the lock"); assertEquals(Procedure.LockState.LOCK_EVENT_WAIT, procB.acquireLock(pExecutor.getEnvironment())); LOG.info("procedureB should not be able to get the lock"); util.waitFor(60000, () -> procB.acquireLock(pExecutor.getEnvironment()) == Procedure.LockState.LOCK_ACQUIRED); LOG.info("when procedure B get the lock, procedure A should be finished"); assertTrue(procA.isFinished()); } }