/** * Reads all quota snapshots from the quota table. * * @return The current "view" of space use by each table. */ public Map<TableName, SpaceQuotaSnapshot> fetchSnapshotsFromQuotaTable() throws IOException { try (Table quotaTable = getConnection().getTable(QuotaUtil.QUOTA_TABLE_NAME); ResultScanner scanner = quotaTable.getScanner(QuotaTableUtil.makeQuotaSnapshotScan())) { Map<TableName,SpaceQuotaSnapshot> snapshots = new HashMap<>(); for (Result result : scanner) { try { extractQuotaSnapshot(result, snapshots); } catch (IllegalArgumentException e) { final String msg = "Failed to parse result for row " + Bytes.toString(result.getRow()); LOG.error(msg, e); throw new IOException(msg, e); } } return snapshots; } }
@SuppressWarnings("unchecked") @Before public void setup() throws IOException { conf = HBaseConfiguration.create(); rss = mock(RegionServerServices.class); manager = mock(RegionServerSpaceQuotaManager.class); conn = mock(Connection.class); when(manager.getRegionServerServices()).thenReturn(rss); when(rss.getConfiguration()).thenReturn(conf); chore = mock(SpaceQuotaRefresherChore.class); when(chore.getConnection()).thenReturn(conn); when(chore.getManager()).thenReturn(manager); doCallRealMethod().when(chore).chore(); when(chore.isInViolation(any())).thenCallRealMethod(); doCallRealMethod().when(chore).extractQuotaSnapshot(any(), any()); }
@SuppressWarnings("unchecked") @Before public void setup() throws IOException { conf = HBaseConfiguration.create(); rss = mock(RegionServerServices.class); manager = mock(RegionServerSpaceQuotaManager.class); conn = mock(Connection.class); when(manager.getRegionServerServices()).thenReturn(rss); when(rss.getConfiguration()).thenReturn(conf); chore = mock(SpaceQuotaRefresherChore.class); when(chore.getConnection()).thenReturn(conn); when(chore.getManager()).thenReturn(manager); doCallRealMethod().when(chore).chore(); when(chore.isInViolation(any())).thenCallRealMethod(); doCallRealMethod().when(chore).extractQuotaSnapshot(any(), any()); }