Search in sources :

Example 1 with QuotaFilter

use of org.apache.hadoop.hbase.quotas.QuotaFilter in project hbase by apache.

the class TestAsyncQuotaAdminApi method testQuotaRetrieverFilter.

@Test
public void testQuotaRetrieverFilter() throws Exception {
    TableName[] tables = new TableName[] { TableName.valueOf("T0"), TableName.valueOf("T01"), TableName.valueOf("NS0:T2") };
    String[] namespaces = new String[] { "NS0", "NS01", "NS2" };
    String[] users = new String[] { "User0", "User01", "User2" };
    for (String user : users) {
        admin.setQuota(QuotaSettingsFactory.throttleUser(user, ThrottleType.REQUEST_NUMBER, 1, TimeUnit.MINUTES)).get();
        for (TableName table : tables) {
            admin.setQuota(QuotaSettingsFactory.throttleUser(user, table, ThrottleType.REQUEST_NUMBER, 2, TimeUnit.MINUTES)).get();
        }
        for (String ns : namespaces) {
            admin.setQuota(QuotaSettingsFactory.throttleUser(user, ns, ThrottleType.REQUEST_NUMBER, 3, TimeUnit.MINUTES)).get();
        }
    }
    assertNumResults(21, null);
    for (TableName table : tables) {
        admin.setQuota(QuotaSettingsFactory.throttleTable(table, ThrottleType.REQUEST_NUMBER, 4, TimeUnit.MINUTES)).get();
    }
    assertNumResults(24, null);
    for (String ns : namespaces) {
        admin.setQuota(QuotaSettingsFactory.throttleNamespace(ns, ThrottleType.REQUEST_NUMBER, 5, TimeUnit.MINUTES)).get();
    }
    assertNumResults(27, null);
    assertNumResults(7, new QuotaFilter().setUserFilter("User0"));
    assertNumResults(0, new QuotaFilter().setUserFilter("User"));
    assertNumResults(21, new QuotaFilter().setUserFilter("User.*"));
    assertNumResults(3, new QuotaFilter().setUserFilter("User.*").setTableFilter("T0"));
    assertNumResults(3, new QuotaFilter().setUserFilter("User.*").setTableFilter("NS.*"));
    assertNumResults(0, new QuotaFilter().setUserFilter("User.*").setTableFilter("T"));
    assertNumResults(6, new QuotaFilter().setUserFilter("User.*").setTableFilter("T.*"));
    assertNumResults(3, new QuotaFilter().setUserFilter("User.*").setNamespaceFilter("NS0"));
    assertNumResults(0, new QuotaFilter().setUserFilter("User.*").setNamespaceFilter("NS"));
    assertNumResults(9, new QuotaFilter().setUserFilter("User.*").setNamespaceFilter("NS.*"));
    assertNumResults(6, new QuotaFilter().setUserFilter("User.*").setTableFilter("T0").setNamespaceFilter("NS0"));
    assertNumResults(1, new QuotaFilter().setTableFilter("T0"));
    assertNumResults(0, new QuotaFilter().setTableFilter("T"));
    assertNumResults(2, new QuotaFilter().setTableFilter("T.*"));
    assertNumResults(3, new QuotaFilter().setTableFilter(".*T.*"));
    assertNumResults(1, new QuotaFilter().setNamespaceFilter("NS0"));
    assertNumResults(0, new QuotaFilter().setNamespaceFilter("NS"));
    assertNumResults(3, new QuotaFilter().setNamespaceFilter("NS.*"));
    for (String user : users) {
        admin.setQuota(QuotaSettingsFactory.unthrottleUser(user)).get();
        for (TableName table : tables) {
            admin.setQuota(QuotaSettingsFactory.unthrottleUser(user, table)).get();
        }
        for (String ns : namespaces) {
            admin.setQuota(QuotaSettingsFactory.unthrottleUser(user, ns)).get();
        }
    }
    assertNumResults(6, null);
    for (TableName table : tables) {
        admin.setQuota(QuotaSettingsFactory.unthrottleTable(table)).get();
    }
    assertNumResults(3, null);
    for (String ns : namespaces) {
        admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(ns)).get();
    }
    assertNumResults(0, null);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) QuotaFilter(org.apache.hadoop.hbase.quotas.QuotaFilter) Test(org.junit.Test)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)1 QuotaFilter (org.apache.hadoop.hbase.quotas.QuotaFilter)1 Test (org.junit.Test)1