use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus in project hbase by apache.
the class TestQuotaStatusRPCs method testQuotaSnapshotsFromRS.
@Test
public void testQuotaSnapshotsFromRS() throws Exception {
// 1MB
final long sizeLimit = 1024L * 1024L;
// 10KB
final long tableSize = 1024L * 10L;
final int numRegions = 10;
final TableName tn = helper.createTableWithRegions(numRegions);
// Define the quota
QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tn, sizeLimit, SpaceViolationPolicy.NO_INSERTS);
TEST_UTIL.getAdmin().setQuota(settings);
// Write at least `tableSize` data
helper.writeData(tn, tableSize);
final HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
final RegionServerSpaceQuotaManager manager = rs.getRegionServerSpaceQuotaManager();
Waiter.waitFor(TEST_UTIL.getConfiguration(), 30 * 1000, new Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
SpaceQuotaSnapshot snapshot = manager.copyQuotaSnapshots().get(tn);
if (snapshot == null) {
return false;
}
return snapshot.getUsage() >= tableSize;
}
});
@SuppressWarnings("unchecked") Map<TableName, SpaceQuotaSnapshot> snapshots = (Map<TableName, SpaceQuotaSnapshot>) TEST_UTIL.getAdmin().getRegionServerSpaceQuotaSnapshots(rs.getServerName());
SpaceQuotaSnapshot snapshot = snapshots.get(tn);
assertNotNull("Did not find snapshot for " + tn, snapshot);
assertTrue("Observed table usage was " + snapshot.getUsage(), snapshot.getUsage() >= tableSize);
assertEquals(sizeLimit, snapshot.getLimit());
SpaceQuotaStatus pbStatus = snapshot.getQuotaStatus();
assertFalse(pbStatus.isInViolation());
}
use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus in project hbase by apache.
the class TestQuotaTableUtil method testSerDeViolationPolicies.
@Test
public void testSerDeViolationPolicies() throws Exception {
final TableName tn1 = getUniqueTableName();
final SpaceQuotaSnapshot snapshot1 = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 512L, 1024L);
final TableName tn2 = getUniqueTableName();
final SpaceQuotaSnapshot snapshot2 = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 512L, 1024L);
final TableName tn3 = getUniqueTableName();
final SpaceQuotaSnapshot snapshot3 = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 512L, 1024L);
List<Put> puts = new ArrayList<>();
puts.add(QuotaTableUtil.createPutForSpaceSnapshot(tn1, snapshot1));
puts.add(QuotaTableUtil.createPutForSpaceSnapshot(tn2, snapshot2));
puts.add(QuotaTableUtil.createPutForSpaceSnapshot(tn3, snapshot3));
final Map<TableName, SpaceQuotaSnapshot> expectedPolicies = new HashMap<>();
expectedPolicies.put(tn1, snapshot1);
expectedPolicies.put(tn2, snapshot2);
expectedPolicies.put(tn3, snapshot3);
final Map<TableName, SpaceQuotaSnapshot> actualPolicies = new HashMap<>();
try (Table quotaTable = connection.getTable(QuotaUtil.QUOTA_TABLE_NAME)) {
quotaTable.put(puts);
ResultScanner scanner = quotaTable.getScanner(QuotaTableUtil.makeQuotaSnapshotScan());
for (Result r : scanner) {
QuotaTableUtil.extractQuotaSnapshot(r, actualPolicies);
}
scanner.close();
}
assertEquals(expectedPolicies, actualPolicies);
}
Aggregations