org.apache.hadoop.hbase.HBaseTestingUtility.getHBaseAdmin()

Here are the examples of the java api org.apache.hadoop.hbase.HBaseTestingUtility.getHBaseAdmin() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

260 Examples 7

19 Source : TestFlushSnapshotFromClient.java
with Apache License 2.0
from fengchen8086

private void waitRegionsAfterMerge(final long numRegionsAfterMerge) throws IOException, InterruptedException {
    Admin admin = UTIL.getHBaseAdmin();
    // Verify that there's one region less
    long startTime = System.currentTimeMillis();
    while (admin.getTableRegions(TABLE_NAME).size() != numRegionsAfterMerge) {
        // This may be flaky... if after 15sec the merge is not complete give up
        // it will fail in the replacedertEquals(numRegionsAfterMerge).
        if ((System.currentTimeMillis() - startTime) > 15000)
            break;
        Thread.sleep(100);
    }
    SnapshotTestingUtils.waitForTableToBeOnline(UTIL, TABLE_NAME);
}

19 Source : TestOpenTableInCoprocessor.java
with Apache License 2.0
from fengchen8086

@After
public void cleanupTestTable() throws Exception {
    UTIL.getHBaseAdmin().disableTable(primaryTable);
    UTIL.getHBaseAdmin().deleteTable(primaryTable);
    UTIL.getHBaseAdmin().disableTable(otherTable);
    UTIL.getHBaseAdmin().deleteTable(otherTable);
}

19 Source : TestConstraint.java
with Apache License 2.0
from fengchen8086

@After
public void cleanup() throws Exception {
    // cleanup
    CheckWasRunConstraint.wasRun = false;
    util.getHBaseAdmin().disableTable(tableName);
    util.getHBaseAdmin().deleteTable(tableName);
}

19 Source : TruncateTableAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    // Don't try the truncate if we're stopping
    if (context.isStopping()) {
        return;
    }
    boolean preserveSplits = random.nextBoolean();
    LOG.info("Performing action: Truncate table " + tableName.getNamereplacedtring() + "preserve splits " + preserveSplits);
    admin.truncateTable(tableName, preserveSplits);
}

19 Source : SplitAllRegionOfTableAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    // Don't try the split if we're stopping
    if (context.isStopping()) {
        return;
    }
    // Don't always split. This should allow splitting of a full table later in the run
    if (ThreadLocalRandom.current().nextDouble() < (((double) splits) / ((double) maxFullTableSplits)) / ((double) 2)) {
        splits++;
        LOG.info("Performing action: Split all regions of  " + tableName);
        admin.split(tableName);
    } else {
        LOG.info("Skipping split of all regions.");
    }
}

19 Source : SnapshotTableAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    String snapshotName = tableName + "-it-" + System.currentTimeMillis();
    Admin admin = util.getHBaseAdmin();
    // Don't try the snapshot if we're stopping
    if (context.isStopping()) {
        return;
    }
    LOG.info("Performing action: Snapshot table " + tableName);
    admin.snapshot(snapshotName, tableName);
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
}

19 Source : FlushTableAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    // Don't try the flush if we're stopping
    if (context.isStopping()) {
        return;
    }
    LOG.info("Performing action: Flush table " + tableName);
    try {
        admin.flush(tableName);
    } catch (Exception ex) {
        LOG.warn("Flush failed, might be caused by other chaos: " + ex.getMessage());
    }
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
}

19 Source : DecreaseMaxHFileSizeAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    HTableDescriptor htd = admin.getTableDescriptor(tableName);
    // Try and get the current value.
    long currentValue = htd.getMaxFileSize();
    // If the current value is not set use the default for the cluster.
    // If configs are really weird this might not work.
    // That's ok. We're trying to cause chaos.
    if (currentValue <= 0) {
        currentValue = context.getHBaseCluster().getConf().getLong(HConstants.HREGION_MAX_FILESIZE, HConstants.DEFAULT_MAX_FILE_SIZE);
    }
    // Decrease by 10% at a time.
    long newValue = (long) (currentValue * 0.9);
    // We don't want to go too far below 1gb.
    // So go to about 1gb +/- 512 on each side.
    newValue = Math.max(minFileSize, newValue) - (512 - random.nextInt(1024));
    // Change the table descriptor.
    htd.setMaxFileSize(newValue);
    // Don't try the modify if we're stopping
    if (context.isStopping()) {
        return;
    }
    // modify the table.
    admin.modifyTable(tableName, htd);
    // Sleep some time.
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
}

19 Source : CompactTableAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    boolean major = RandomUtils.nextInt(100) < majorRatio;
    LOG.info("Performing action: Compact table " + tableName + ", major=" + major);
    try {
        if (major) {
            admin.majorCompact(tableName);
        } else {
            admin.compact(tableName);
        }
    } catch (Exception ex) {
        LOG.warn("Compaction failed, might be caused by other chaos: " + ex.getMessage());
    }
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
}

19 Source : ChangeSplitPolicyAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    LOG.info("Performing action: Change split policy of table " + tableName);
    HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
    String chosenPolicy = possiblePolicies[random.nextInt(possiblePolicies.length)];
    tableDescriptor.setRegionSplitPolicyClreplacedName(chosenPolicy);
    LOG.info("Changing " + tableName + " split policy to " + chosenPolicy);
    admin.modifyTable(tableName, tableDescriptor);
}

18 Source : TestSnapshotClientRetries.java
with Apache License 2.0
from fengchen8086

public void cloneAndreplacedertOneRetry(final String snapshotName, final TableName tableName) throws Exception {
    MasterSyncObserver observer = getMasterSyncObserver();
    observer.cloneCount = new AtomicInteger(0);
    TEST_UTIL.getHBaseAdmin().cloneSnapshot(snapshotName, tableName);
    replacedertEquals(1, observer.cloneCount.get());
}

18 Source : TestRestoreFlushSnapshotFromClient.java
with Apache License 2.0
from fengchen8086

@After
public void tearDown() throws Exception {
    SnapshotTestingUtils.deleteAllSnapshots(UTIL.getHBaseAdmin());
    SnapshotTestingUtils.deleteArchiveDirectory(UTIL);
}

18 Source : TestNamespaceCommands.java
with Apache License 2.0
from fengchen8086

@AfterClreplaced
public static void afterClreplaced() throws Exception {
    UTIL.getHBaseAdmin().deleteNamespace(TEST_NAMESPACE);
    UTIL.getHBaseAdmin().deleteNamespace(TEST_NAMESPACE2);
    UTIL.shutdownMiniCluster();
}

18 Source : SecureTestUtil.java
with Apache License 2.0
from fengchen8086

public static void deleteNamespace(HBaseTestingUtility testUtil, String namespace) throws Exception {
    testUtil.getHBaseAdmin().deleteNamespace(namespace);
}

18 Source : TestProcedureManager.java
with Apache License 2.0
from fengchen8086

@Test
public void testSimpleProcedureManager() throws IOException {
    Admin admin = util.getHBaseAdmin();
    byte[] result = admin.execProcedureWithRet(SimpleMasterProcedureManager.SIMPLE_SIGNATURE, "mytest", new HashMap<String, String>());
    replacedertArrayEquals("Incorrect return data from execProcedure", SimpleMasterProcedureManager.SIMPLE_DATA.getBytes(), result);
}

18 Source : TestLoadIncrementalHFiles.java
with Apache License 2.0
from fengchen8086

protected static void setupNamespace() throws Exception {
    util.getHBaseAdmin().createNamespace(NamespaceDescriptor.create(NAMESPACE).build());
}

18 Source : TestSnapshotFromClient.java
with Apache License 2.0
from fengchen8086

/**
 * Test snapshotting not allowed hbase:meta and -ROOT-
 * @throws Exception
 */
@Test(timeout = 300000)
public void testMetaTablesSnapshot() throws Exception {
    Admin admin = UTIL.getHBaseAdmin();
    byte[] snapshotName = Bytes.toBytes("metaSnapshot");
    try {
        admin.snapshot(snapshotName, TableName.META_TABLE_NAME);
        fail("taking a snapshot of hbase:meta should not be allowed");
    } catch (IllegalArgumentException e) {
    // expected
    }
}

18 Source : TestReplicasClient.java
with Apache License 2.0
from fengchen8086

@Before
public void before() throws IOException {
    HTU.getHBaseAdmin().getConnection().clearRegionCache();
    try {
        openRegion(hriPrimary);
    } catch (Exception ignored) {
    }
    try {
        openRegion(hriSecondary);
    } catch (Exception ignored) {
    }
}

18 Source : TestLeaseRenewal.java
with Apache License 2.0
from fengchen8086

/**
 * @throws java.lang.Exception
 */
@After
public void tearDown() throws Exception {
    for (HTableDescriptor htd : TEST_UTIL.getHBaseAdmin().listTables()) {
        LOG.info("Tear down, remove table=" + htd.getTableName());
        TEST_UTIL.deleteTable(htd.getTableName());
    }
}

18 Source : TestReplicationAdminWithTwoDifferentZKClusters.java
with Apache License 2.0
from fengchen8086

/*
   * Test for HBASE-15393
   */
@Test
public void testEnableTableReplication() throws Exception {
    admin.enableTableRep(tableName);
    replacedertTrue(utility2.getHBaseAdmin().tableExists(tableName));
}

18 Source : TestReplicationAdminWithTwoDifferentZKClusters.java
with Apache License 2.0
from fengchen8086

@Test
public void testDisableTableReplication() throws Exception {
    admin.disableTableRep(tableName);
    replacedertTrue(utility2.getHBaseAdmin().tableExists(tableName));
}

18 Source : TestTableScan.java
with Apache License 2.0
from fengchen8086

@AfterClreplaced
public static void tearDownAfterClreplaced() throws Exception {
    TEST_UTIL.getHBaseAdmin().disableTable(TABLE);
    TEST_UTIL.getHBaseAdmin().deleteTable(TABLE);
    REST_TEST_UTIL.shutdownServletContainer();
    TEST_UTIL.shutdownMiniCluster();
}

17 Source : TestSnapshotClientRetries.java
with Apache License 2.0
from fengchen8086

public void snapshotAndreplacedertOneRetry(final String snapshotName, final TableName tableName) throws Exception {
    MasterSyncObserver observer = getMasterSyncObserver();
    observer.snapshotCount = new AtomicInteger(0);
    TEST_UTIL.getHBaseAdmin().snapshot(snapshotName, tableName);
    replacedertEquals(1, observer.snapshotCount.get());
}

17 Source : TestFlushSnapshotFromClient.java
with Apache License 2.0
from fengchen8086

@After
public void tearDown() throws Exception {
    UTIL.deleteTable(TABLE_NAME);
    SnapshotTestingUtils.deleteAllSnapshots(UTIL.getHBaseAdmin());
    SnapshotTestingUtils.deleteArchiveDirectory(UTIL);
}

17 Source : TestExportSnapshot.java
with Apache License 2.0
from fengchen8086

@After
public void tearDown() throws Exception {
    TEST_UTIL.deleteTable(tableName);
    SnapshotTestingUtils.deleteAllSnapshots(TEST_UTIL.getHBaseAdmin());
    SnapshotTestingUtils.deleteArchiveDirectory(TEST_UTIL);
}

17 Source : SecureTestUtil.java
with Apache License 2.0
from fengchen8086

public static void createNamespace(HBaseTestingUtility testUtil, NamespaceDescriptor nsDesc) throws Exception {
    testUtil.getHBaseAdmin().createNamespace(nsDesc);
}

17 Source : SecureTestUtil.java
with Apache License 2.0
from fengchen8086

public static void deleteTable(HBaseTestingUtility testUtil, TableName tableName) throws Exception {
    deleteTable(testUtil, testUtil.getHBaseAdmin(), tableName);
}

17 Source : SecureTestUtil.java
with Apache License 2.0
from fengchen8086

public static void createTable(HBaseTestingUtility testUtil, HTableDescriptor htd) throws Exception {
    createTable(testUtil, testUtil.getHBaseAdmin(), htd);
}

17 Source : SecureTestUtil.java
with Apache License 2.0
from fengchen8086

public static void createTable(HBaseTestingUtility testUtil, HTableDescriptor htd, byte[][] splitKeys) throws Exception {
    createTable(testUtil, testUtil.getHBaseAdmin(), htd, splitKeys);
}

17 Source : TestQuotaThrottle.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000)
public void testNamespaceGlobalThrottle() throws Exception {
    final Admin admin = TEST_UTIL.getHBaseAdmin();
    final String NAMESPACE = "default";
    // Add 6req/min limit
    admin.setQuota(QuotaSettingsFactory.throttleNamespace(NAMESPACE, ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
    triggerNamespaceCacheRefresh(false, TABLE_NAMES[0]);
    // should execute at max 6 requests
    replacedertEquals(6, doPuts(100, tables[0]));
    // wait a minute and you should get other 6 requests executed
    waitMinuteQuota();
    replacedertEquals(6, doPuts(100, tables[1]));
    admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(NAMESPACE));
    triggerNamespaceCacheRefresh(true, TABLE_NAMES[0]);
    replacedertEquals(40, doPuts(40, tables[0]));
}

17 Source : TestQuotaThrottle.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000)
public void testTableGlobalThrottle() throws Exception {
    final Admin admin = TEST_UTIL.getHBaseAdmin();
    // Add 6req/min limit
    admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
    triggerTableCacheRefresh(false, TABLE_NAMES[0]);
    // should execute at max 6 requests
    replacedertEquals(6, doPuts(100, tables[0]));
    // should have no limits
    replacedertEquals(30, doPuts(30, tables[1]));
    // wait a minute and you should get other 6 requests executed
    waitMinuteQuota();
    replacedertEquals(6, doPuts(100, tables[0]));
    // Remove all the limits
    admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
    triggerTableCacheRefresh(true, TABLE_NAMES[0]);
    replacedertEquals(80, doGets(80, tables[0], tables[1]));
}

17 Source : TestWarmupRegion.java
with Apache License 2.0
from fengchen8086

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    table = TEST_UTIL.createTable(TABLENAME, FAMILY);
    // future timestamp
    for (int i = 0; i < numRows; i++) {
        long ts = System.currentTimeMillis() * 2;
        Put put = new Put(ROW, ts);
        put.add(FAMILY, COLUMN, VALUE);
        table.put(put);
    }
    // major compaction, purged future deletes
    TEST_UTIL.getHBaseAdmin().flush(TABLENAME);
    TEST_UTIL.getHBaseAdmin().majorCompact(TABLENAME);
    // waiting for the major compaction to complete
    TEST_UTIL.waitFor(6000, new Waiter.Predicate<IOException>() {

        @Override
        public boolean evaluate() throws IOException {
            return TEST_UTIL.getHBaseAdmin().getCompactionState(TABLENAME) == AdminProtos.GetRegionInfoResponse.CompactionState.NONE;
        }
    });
    table.close();
}

17 Source : TestRowProcessorEndpoint.java
with Apache License 2.0
from fengchen8086

public void prepareTestData() throws Exception {
    try {
        util.getHBaseAdmin().disableTable(TABLE);
        util.getHBaseAdmin().deleteTable(TABLE);
    } catch (Exception e) {
    // ignore table not found
    }
    table = util.createTable(TABLE, FAM);
    {
        Put put = new Put(ROW);
        // B, C are friends of A
        put.add(FAM, A, Bytes.add(B, C));
        // D, E, F are friends of B
        put.add(FAM, B, Bytes.add(D, E, F));
        // G is a friend of C
        put.add(FAM, C, G);
        table.put(put);
        rowSize = put.size();
    }
    Put put = new Put(ROW2);
    put.add(FAM, D, E);
    put.add(FAM, F, G);
    table.put(put);
    row2Size = put.size();
}

17 Source : TestUpdateConfiguration.java
with Apache License 2.0
from fengchen8086

@Test
public void testOnlineConfigChange() throws IOException {
    LOG.debug("Starting the test");
    Admin admin = TEST_UTIL.getHBaseAdmin();
    ServerName server = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
    admin.updateConfiguration(server);
}

17 Source : TestNamespacesInstanceResource.java
with Apache License 2.0
from fengchen8086

@Test
public void testCannotDeleteDefaultAndHbaseNamespaces() throws IOException {
    String defaultPath = "/namespaces/default";
    String hbasePath = "/namespaces/hbase";
    Response response;
    // Check that doesn't exist via non-REST call.
    Admin admin = TEST_UTIL.getHBaseAdmin();
    replacedertNotNull(findNamespace(admin, "default"));
    replacedertNotNull(findNamespace(admin, "hbase"));
    // Try (but fail) to delete namespaces via REST.
    response = client.delete(defaultPath);
    replacedertEquals(503, response.getCode());
    response = client.delete(hbasePath);
    replacedertEquals(503, response.getCode());
    replacedertNotNull(findNamespace(admin, "default"));
    replacedertNotNull(findNamespace(admin, "hbase"));
}

17 Source : SplitRandomRegionOfTableAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    LOG.info("Performing action: Split random region of table " + tableName);
    List<HRegionInfo> regions = admin.getTableRegions(tableName);
    if (regions == null || regions.isEmpty()) {
        LOG.info("Table " + tableName + " doesn't have regions to split");
        return;
    }
    // Don't try the split if we're stopping
    if (context.isStopping()) {
        return;
    }
    HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(regions.toArray(new HRegionInfo[regions.size()]));
    LOG.debug("Splitting region " + region.getRegionNamereplacedtring());
    try {
        admin.splitRegion(region.getRegionName());
    } catch (Exception ex) {
        LOG.warn("Split failed, might be caused by other chaos: " + ex.getMessage());
    }
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
}

17 Source : MoveRandomRegionOfTableAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    LOG.info("Performing action: Move random region of table " + tableName);
    List<HRegionInfo> regions = admin.getTableRegions(tableName);
    if (regions == null || regions.isEmpty()) {
        LOG.info("Table " + tableName + " doesn't have regions to move");
        return;
    }
    HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(regions.toArray(new HRegionInfo[regions.size()]));
    LOG.debug("Unreplacedigning region " + region.getRegionNamereplacedtring());
    admin.unreplacedign(region.getRegionName(), false);
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
}

17 Source : FlushRandomRegionOfTableAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    LOG.info("Performing action: Flush random region of table " + tableName);
    List<HRegionInfo> regions = admin.getTableRegions(tableName);
    if (regions == null || regions.isEmpty()) {
        LOG.info("Table " + tableName + " doesn't have regions to flush");
        return;
    }
    HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(regions.toArray(new HRegionInfo[regions.size()]));
    LOG.debug("Flushing region " + region.getRegionNamereplacedtring());
    try {
        admin.flushRegion(region.getRegionName());
    } catch (Exception ex) {
        LOG.warn("Flush failed, might be caused by other chaos: " + ex.getMessage());
    }
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
}

17 Source : CompactRandomRegionOfTableAction.java
with Apache License 2.0
from fengchen8086

@Override
public void perform() throws Exception {
    HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getHBaseAdmin();
    boolean major = RandomUtils.nextInt(100) < majorRatio;
    LOG.info("Performing action: Compact random region of table " + tableName + ", major=" + major);
    List<HRegionInfo> regions = admin.getTableRegions(tableName);
    if (regions == null || regions.isEmpty()) {
        LOG.info("Table " + tableName + " doesn't have regions to compact");
        return;
    }
    HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(regions.toArray(new HRegionInfo[regions.size()]));
    try {
        if (major) {
            LOG.debug("Major compacting region " + region.getRegionNamereplacedtring());
            admin.majorCompactRegion(region.getRegionName());
        } else {
            LOG.debug("Compacting region " + region.getRegionNamereplacedtring());
            admin.compactRegion(region.getRegionName());
        }
    } catch (Exception ex) {
        LOG.warn("Compaction failed, might be caused by other chaos: " + ex.getMessage());
    }
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
}

16 Source : TestSnapshotClientRetries.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000, expected = SnapshotExistsException.clreplaced)
public void testSnapshotAlreadyExist() throws Exception {
    final String snapshotName = "testSnapshotAlreadyExist";
    TEST_UTIL.createTable(TEST_TABLE.getTableName(), "f");
    TEST_UTIL.getHBaseAdmin().snapshot(snapshotName, TEST_TABLE.getTableName());
    snapshotAndreplacedertOneRetry(snapshotName, TEST_TABLE.getTableName());
}

16 Source : TestQuotaThrottle.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000)
public void testUserAndTableThrottle() throws Exception {
    final Admin admin = TEST_UTIL.getHBaseAdmin();
    final String userName = User.getCurrent().getShortName();
    // Add 6req/min limit for the user on tables[0]
    admin.setQuota(QuotaSettingsFactory.throttleUser(userName, TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
    triggerUserCacheRefresh(false, TABLE_NAMES[0]);
    // Add 12req/min limit for the user
    admin.setQuota(QuotaSettingsFactory.throttleUser(userName, ThrottleType.REQUEST_NUMBER, 12, TimeUnit.MINUTES));
    triggerUserCacheRefresh(false, TABLE_NAMES[1], TABLE_NAMES[2]);
    // Add 8req/min limit for the tables[1]
    admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[1], ThrottleType.REQUEST_NUMBER, 8, TimeUnit.MINUTES));
    triggerTableCacheRefresh(false, TABLE_NAMES[1]);
    // Add a lower table level throttle on tables[0]
    admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 3, TimeUnit.MINUTES));
    triggerTableCacheRefresh(false, TABLE_NAMES[0]);
    // should execute at max 12 requests
    replacedertEquals(12, doGets(100, tables[2]));
    // should execute at max 8 requests
    waitMinuteQuota();
    replacedertEquals(8, doGets(100, tables[1]));
    // should execute at max 3 requests
    waitMinuteQuota();
    replacedertEquals(3, doPuts(100, tables[0]));
    // Remove all the throttling rules
    admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, TABLE_NAMES[0]));
    admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName));
    triggerUserCacheRefresh(true, TABLE_NAMES[0], TABLE_NAMES[1]);
    admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[1]));
    triggerTableCacheRefresh(true, TABLE_NAMES[1]);
    waitMinuteQuota();
    replacedertEquals(40, doGets(40, tables[1]));
    admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
    triggerTableCacheRefresh(true, TABLE_NAMES[0]);
    waitMinuteQuota();
    replacedertEquals(40, doGets(40, tables[0]));
}

16 Source : TestQuotaThrottle.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000)
public void testUserTableThrottle() throws Exception {
    final Admin admin = TEST_UTIL.getHBaseAdmin();
    final String userName = User.getCurrent().getShortName();
    // Add 6req/min limit
    admin.setQuota(QuotaSettingsFactory.throttleUser(userName, TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
    triggerUserCacheRefresh(false, TABLE_NAMES[0]);
    // should execute at max 6 requests on tables[0] and have no limit on tables[1]
    replacedertEquals(6, doPuts(100, tables[0]));
    replacedertEquals(30, doPuts(30, tables[1]));
    // wait a minute and you should get other 6 requests executed
    waitMinuteQuota();
    replacedertEquals(6, doPuts(100, tables[0]));
    // Remove all the limits
    admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, TABLE_NAMES[0]));
    triggerUserCacheRefresh(true, TABLE_NAMES);
    replacedertEquals(60, doPuts(60, tables));
    replacedertEquals(60, doGets(60, tables));
}

16 Source : TestQuotaThrottle.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000)
public void testUserGlobalThrottle() throws Exception {
    final Admin admin = TEST_UTIL.getHBaseAdmin();
    final String userName = User.getCurrent().getShortName();
    // Add 6req/min limit
    admin.setQuota(QuotaSettingsFactory.throttleUser(userName, ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
    triggerUserCacheRefresh(false, TABLE_NAMES);
    // should execute at max 6 requests
    replacedertEquals(6, doPuts(100, tables));
    // wait a minute and you should get other 6 requests executed
    waitMinuteQuota();
    replacedertEquals(6, doPuts(100, tables));
    // Remove all the limits
    admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName));
    triggerUserCacheRefresh(true, TABLE_NAMES);
    replacedertEquals(60, doPuts(60, tables));
    replacedertEquals(60, doGets(60, tables));
}

16 Source : TestQuotaThrottle.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000)
public void testUserGlobalBypreplacedThrottle() throws Exception {
    final Admin admin = TEST_UTIL.getHBaseAdmin();
    final String userName = User.getCurrent().getShortName();
    final String NAMESPACE = "default";
    // Add 6req/min limit for tables[0]
    admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
    triggerTableCacheRefresh(false, TABLE_NAMES[0]);
    // Add 13req/min limit for the user
    admin.setQuota(QuotaSettingsFactory.throttleNamespace(NAMESPACE, ThrottleType.REQUEST_NUMBER, 13, TimeUnit.MINUTES));
    triggerNamespaceCacheRefresh(false, TABLE_NAMES[1]);
    // should execute at max 6 requests on table[0] and (13 - 6) on table[1]
    replacedertEquals(6, doPuts(100, tables[0]));
    replacedertEquals(7, doGets(100, tables[1]));
    waitMinuteQuota();
    // Set the global bypreplaced for the user
    admin.setQuota(QuotaSettingsFactory.bypreplacedGlobals(userName, true));
    admin.setQuota(QuotaSettingsFactory.throttleUser(userName, TABLE_NAMES[2], ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
    triggerUserCacheRefresh(false, TABLE_NAMES[2]);
    replacedertEquals(30, doGets(30, tables[0]));
    replacedertEquals(30, doGets(30, tables[1]));
    waitMinuteQuota();
    // Remove the global bypreplaced
    // should execute at max 6 requests on table[0] and (13 - 6) on table[1]
    admin.setQuota(QuotaSettingsFactory.bypreplacedGlobals(userName, false));
    admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, TABLE_NAMES[2]));
    triggerUserCacheRefresh(true, TABLE_NAMES[2]);
    replacedertEquals(6, doPuts(100, tables[0]));
    replacedertEquals(7, doGets(100, tables[1]));
    // unset throttle
    admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
    admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(NAMESPACE));
    waitMinuteQuota();
    triggerTableCacheRefresh(true, TABLE_NAMES[0]);
    triggerNamespaceCacheRefresh(true, TABLE_NAMES[1]);
    replacedertEquals(30, doGets(30, tables[0]));
    replacedertEquals(30, doGets(30, tables[1]));
}

16 Source : TestQuotaThrottle.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000)
public void testTableGlobalReadAndWriteThrottle() throws Exception {
    final Admin admin = TEST_UTIL.getHBaseAdmin();
    // Add 6req/min limit for read request
    admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.READ_NUMBER, 6, TimeUnit.MINUTES));
    triggerTableCacheRefresh(false, TABLE_NAMES[0]);
    // should execute at max 6 read requests and have no limit for write request
    replacedertEquals(6, doGets(100, tables[0]));
    replacedertEquals(100, doPuts(100, tables[0]));
    // should have no limits on tables[1]
    replacedertEquals(30, doPuts(30, tables[1]));
    replacedertEquals(30, doGets(30, tables[1]));
    // wait a minute and you should get other 6 requests executed
    waitMinuteQuota();
    // Add 6req/min limit for write request, too
    admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.WRITE_NUMBER, 6, TimeUnit.MINUTES));
    triggerTableCacheRefresh(false, TABLE_NAMES[0]);
    // should execute at max 6 read requests and at max 6 write requests
    replacedertEquals(6, doGets(100, tables[0]));
    replacedertEquals(6, doPuts(100, tables[0]));
    // should have no limits on tables[1]
    replacedertEquals(30, doPuts(30, tables[1]));
    replacedertEquals(30, doGets(30, tables[1]));
    // Remove all the limits
    admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
    triggerTableCacheRefresh(true, TABLE_NAMES[0]);
    replacedertEquals(80, doGets(80, tables[0], tables[1]));
}

16 Source : TestQuotaThrottle.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000)
public void testUserNamespaceThrottle() throws Exception {
    final Admin admin = TEST_UTIL.getHBaseAdmin();
    final String userName = User.getCurrent().getShortName();
    final String NAMESPACE = "default";
    // Add 6req/min limit
    admin.setQuota(QuotaSettingsFactory.throttleUser(userName, NAMESPACE, ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
    triggerUserCacheRefresh(false, TABLE_NAMES[0]);
    // should execute at max 6 requests on tables[0] and have no limit on tables[1]
    replacedertEquals(6, doPuts(100, tables[0]));
    // wait a minute and you should get other 6 requests executed
    waitMinuteQuota();
    replacedertEquals(6, doPuts(100, tables[1]));
    // Remove all the limits
    admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, NAMESPACE));
    triggerUserCacheRefresh(true, TABLE_NAMES);
    replacedertEquals(60, doPuts(60, tables));
    replacedertEquals(60, doGets(60, tables));
}

16 Source : TestQuotaThrottle.java
with Apache License 2.0
from fengchen8086

@Test(timeout = 60000)
public void testNamespaceGlobalReadAndWriteThrottle() throws Exception {
    final Admin admin = TEST_UTIL.getHBaseAdmin();
    final String NAMESPACE = "default";
    // Add 6req/min limit for write request
    admin.setQuota(QuotaSettingsFactory.throttleNamespace(NAMESPACE, ThrottleType.WRITE_NUMBER, 6, TimeUnit.MINUTES));
    triggerNamespaceCacheRefresh(false, TABLE_NAMES[0]);
    // should execute at max 6 write requests and no limit for read request
    replacedertEquals(6, doPuts(100, tables[0]));
    replacedertEquals(100, doGets(100, tables[0]));
    // wait a minute and you should get other 6 requests executed
    waitMinuteQuota();
    // Add 6req/min limit for read request, too
    admin.setQuota(QuotaSettingsFactory.throttleNamespace(NAMESPACE, ThrottleType.READ_NUMBER, 6, TimeUnit.MINUTES));
    triggerNamespaceCacheRefresh(false, TABLE_NAMES[0]);
    // should execute at max 6 write requests and at max 6 read requests
    replacedertEquals(6, doPuts(100, tables[0]));
    replacedertEquals(6, doGets(100, tables[0]));
    admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(NAMESPACE));
    triggerNamespaceCacheRefresh(true, TABLE_NAMES[0]);
    replacedertEquals(40, doPuts(40, tables[0]));
}

16 Source : TestOpenTableInCoprocessor.java
with Apache License 2.0
from fengchen8086

private void runCoprocessorConnectionToRemoteTable(Clreplaced<? extends BaseRegionObserver> clazz, boolean[] completeCheck) throws Throwable {
    HTableDescriptor primary = new HTableDescriptor(primaryTable);
    primary.addFamily(new HColumnDescriptor(family));
    // add our coprocessor
    primary.addCoprocessor(clazz.getName());
    HTableDescriptor other = new HTableDescriptor(otherTable);
    other.addFamily(new HColumnDescriptor(family));
    Admin admin = UTIL.getHBaseAdmin();
    admin.createTable(primary);
    admin.createTable(other);
    Table table = new HTable(UTIL.getConfiguration(), TableName.valueOf("primary"));
    Put p = new Put(new byte[] { 'a' });
    p.add(family, null, new byte[] { 'a' });
    table.put(p);
    table.close();
    Table target = new HTable(UTIL.getConfiguration(), otherTable);
    replacedertTrue("Didn't complete update to target table!", completeCheck[0]);
    replacedertEquals("Didn't find inserted row", 1, getKeyValueCount(target));
    target.close();
}

16 Source : TestConstraint.java
with Apache License 2.0
from fengchen8086

/**
 * Check to make sure a constraint is unloaded when it fails
 * @throws Exception
 */
@Test
public void testIsUnloaded() throws Exception {
    // create the table
    HTableDescriptor desc = new HTableDescriptor(tableName);
    // add a family to the table
    for (byte[] family : new byte[][] { dummy, test }) {
        desc.addFamily(new HColumnDescriptor(family));
    }
    // make sure that constraints are unloaded
    Constraints.add(desc, RuntimeFailConstraint.clreplaced);
    // add a constraint to check to see if is run
    Constraints.add(desc, CheckWasRunConstraint.clreplaced);
    CheckWasRunConstraint.wasRun = false;
    util.getHBaseAdmin().createTable(desc);
    Table table = new HTable(util.getConfiguration(), tableName);
    // test that we do fail on violation
    Put put = new Put(row1);
    put.add(dummy, new byte[0], "preplaced".getBytes());
    try {
        table.put(put);
        fail("RuntimeFailConstraint wasn't triggered - this put shouldn't work!");
    } catch (Exception e) {
    // NOOP
    }
    // try the put again, this time constraints are not used, so it works
    table.put(put);
    // and we make sure that constraints were not run...
    replacedertFalse(CheckWasRunConstraint.wasRun);
    table.close();
}

16 Source : TestUpdateConfiguration.java
with Apache License 2.0
from fengchen8086

@Test
public void testMasterOnlineConfigChange() throws IOException {
    LOG.debug("Starting the test");
    Path cnfPath = FileSystems.getDefault().getPath("target/test-clreplacedes/hbase-site.xml");
    Path cnf2Path = FileSystems.getDefault().getPath("target/test-clreplacedes/hbase-site2.xml");
    Path cnf3Path = FileSystems.getDefault().getPath("target/test-clreplacedes/hbase-site3.xml");
    // make a backup of hbase-site.xml
    Files.copy(cnfPath, cnf3Path, StandardCopyOption.REPLACE_EXISTING);
    // update hbase-site.xml by overwriting it
    Files.copy(cnf2Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
    Admin admin = TEST_UTIL.getHBaseAdmin();
    ServerName server = TEST_UTIL.getHBaseCluster().getMaster().getServerName();
    admin.updateConfiguration(server);
    Configuration conf = TEST_UTIL.getMiniHBaseCluster().getMaster().getConfiguration();
    int custom = conf.getInt("hbase.custom.config", 0);
    replacedertEquals(custom, 1000);
    // restore hbase-site.xml
    Files.copy(cnf3Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
}

See More Examples