@Test public void testViolatingQuotaCachesNothing() { final TableName tableName = TableName.valueOf("my_table"); SpaceViolationPolicyEnforcement policyEnforcement = mock(SpaceViolationPolicyEnforcement.class); final Map<TableName,SpaceViolationPolicyEnforcement> activePolicies = new HashMap<>(); activePolicies.put(tableName, policyEnforcement); final ActivePolicyEnforcement ape = new ActivePolicyEnforcement( activePolicies, Collections.emptyMap(), rss); assertTrue(ape.getPolicyEnforcement(tableName) == policyEnforcement); assertEquals(0, ape.getLocallyCachedPolicies().size()); } }
@Test public void testNoPolicyReturnsNoopEnforcement() { ActivePolicyEnforcement ape = new ActivePolicyEnforcement( new HashMap<>(), Collections.emptyMap(), mock(RegionServerServices.class)); SpaceViolationPolicyEnforcement enforcement = ape.getPolicyEnforcement( TableName.valueOf("nonexistent")); assertNotNull(enforcement); assertTrue( "Expected an instance of MissingSnapshotViolationPolicyEnforcement, but got " + enforcement.getClass(), enforcement instanceof MissingSnapshotViolationPolicyEnforcement); }
/** * Returns the proper {@link SpaceViolationPolicyEnforcement} implementation for the given table. * If the given table does not have a violation policy enforced, a "no-op" policy will * be returned which always allows an action. * * @see #getPolicyEnforcement(TableName) */ public SpaceViolationPolicyEnforcement getPolicyEnforcement(Region r) { return getPolicyEnforcement(Objects.requireNonNull(r).getTableDescriptor().getTableName()); }
/** * Creates an object well-suited for the RegionServer to use in verifying active policies. */ public ActivePolicyEnforcement getActiveEnforcements() { return new ActivePolicyEnforcement(copyActiveEnforcements(), copyQuotaSnapshots(), rsServices); }
@Test public void testGetter() { final TableName tableName = TableName.valueOf("table"); Map<TableName, SpaceViolationPolicyEnforcement> map = new HashMap<>(); map.put(tableName, new NoWritesViolationPolicyEnforcement()); ActivePolicyEnforcement ape = new ActivePolicyEnforcement(map, Collections.emptyMap(), null); assertEquals(map.get(tableName), ape.getPolicyEnforcement(tableName)); }
@Override public boolean evaluate() throws Exception { ActivePolicyEnforcement enforcements = manager.getActiveEnforcements(); SpaceViolationPolicyEnforcement enforcement = enforcements.getPolicyEnforcement(tn); // Signifies that we're waiting on the quota snapshot to be fetched if (enforcement instanceof MissingSnapshotViolationPolicyEnforcement) { return false; } return enforcement.getQuotaSnapshot().getQuotaStatus().isInViolation(); } });
@Test public void testNoQuotaReturnsSingletonPolicyEnforcement() { final ActivePolicyEnforcement ape = new ActivePolicyEnforcement( Collections.emptyMap(), Collections.emptyMap(), rss); final TableName tableName = TableName.valueOf("my_table"); SpaceViolationPolicyEnforcement policyEnforcement = ape.getPolicyEnforcement(tableName); // This should be the same exact instance, the singleton assertTrue(policyEnforcement == MissingSnapshotViolationPolicyEnforcement.getInstance()); assertEquals(1, ape.getLocallyCachedPolicies().size()); Entry<TableName,SpaceViolationPolicyEnforcement> entry = ape.getLocallyCachedPolicies().entrySet().iterator().next(); assertTrue(policyEnforcement == entry.getValue()); }
@Test public void testNoBulkLoadChecksOnNoSnapshot() { ActivePolicyEnforcement ape = new ActivePolicyEnforcement( new HashMap<TableName, SpaceViolationPolicyEnforcement>(), Collections.<TableName,SpaceQuotaSnapshot> emptyMap(), mock(RegionServerServices.class)); SpaceViolationPolicyEnforcement enforcement = ape.getPolicyEnforcement( TableName.valueOf("nonexistent")); assertFalse("Should not check bulkloads", enforcement.shouldCheckBulkLoads()); }
++countOfCompleteMutation; checkCellSizeLimit(region, put); spaceQuotaEnforcement.getPolicyEnforcement(region).check(put); rm.add(put); break; Delete del = ProtobufUtil.toDelete(action.getMutation(), cellScanner); ++countOfCompleteMutation; spaceQuotaEnforcement.getPolicyEnforcement(region).check(del); rm.add(del); break;
@Test public void testNonViolatingQuotaCachesPolicyEnforcment() { final Map<TableName,SpaceQuotaSnapshot> snapshots = new HashMap<>(); final TableName tableName = TableName.valueOf("my_table"); snapshots.put(tableName, new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, 1024)); final ActivePolicyEnforcement ape = new ActivePolicyEnforcement( Collections.emptyMap(), snapshots, rss); SpaceViolationPolicyEnforcement policyEnforcement = ape.getPolicyEnforcement(tableName); assertTrue( "Found the wrong class: " + policyEnforcement.getClass(), policyEnforcement instanceof DefaultViolationPolicyEnforcement); SpaceViolationPolicyEnforcement copy = ape.getPolicyEnforcement(tableName); assertTrue("Expected the instance to be cached", policyEnforcement == copy); Entry<TableName,SpaceViolationPolicyEnforcement> entry = ape.getLocallyCachedPolicies().entrySet().iterator().next(); assertTrue(policyEnforcement == entry.getValue()); }
@Test public void testGetter() { final TableName tableName = TableName.valueOf("table"); Map<TableName, SpaceViolationPolicyEnforcement> map = new HashMap<>(); map.put(tableName, new NoWritesViolationPolicyEnforcement()); ActivePolicyEnforcement ape = new ActivePolicyEnforcement(map, Collections.emptyMap(), null); assertEquals(map.get(tableName), ape.getPolicyEnforcement(tableName)); }
SpaceViolationPolicyEnforcement enforcement = activeSpaceQuotas.getPolicyEnforcement( region); if (enforcement != null) {
@Test public void testViolatingQuotaCachesNothing() { final TableName tableName = TableName.valueOf("my_table"); SpaceViolationPolicyEnforcement policyEnforcement = mock(SpaceViolationPolicyEnforcement.class); final Map<TableName,SpaceViolationPolicyEnforcement> activePolicies = new HashMap<>(); activePolicies.put(tableName, policyEnforcement); final ActivePolicyEnforcement ape = new ActivePolicyEnforcement( activePolicies, Collections.emptyMap(), rss); assertTrue(ape.getPolicyEnforcement(tableName) == policyEnforcement); assertEquals(0, ape.getLocallyCachedPolicies().size()); } }
@Test public void testNoBulkLoadChecksOnNoSnapshot() { ActivePolicyEnforcement ape = new ActivePolicyEnforcement( new HashMap<TableName, SpaceViolationPolicyEnforcement>(), Collections.<TableName,SpaceQuotaSnapshot> emptyMap(), mock(RegionServerServices.class)); SpaceViolationPolicyEnforcement enforcement = ape.getPolicyEnforcement( TableName.valueOf("nonexistent")); assertFalse("Should not check bulkloads", enforcement.shouldCheckBulkLoads()); }
SpaceViolationPolicyEnforcement enforcement = activePolicies.getPolicyEnforcement(tn); assertTrue( "Expected to find Noop policy, but got " + enforcement.getClass().getSimpleName(),
@Test public void testNoQuotaReturnsSingletonPolicyEnforcement() { final ActivePolicyEnforcement ape = new ActivePolicyEnforcement( Collections.emptyMap(), Collections.emptyMap(), rss); final TableName tableName = TableName.valueOf("my_table"); SpaceViolationPolicyEnforcement policyEnforcement = ape.getPolicyEnforcement(tableName); // This should be the same exact instance, the singleton assertTrue(policyEnforcement == MissingSnapshotViolationPolicyEnforcement.getInstance()); assertEquals(1, ape.getLocallyCachedPolicies().size()); Entry<TableName,SpaceViolationPolicyEnforcement> entry = ape.getLocallyCachedPolicies().entrySet().iterator().next(); assertTrue(policyEnforcement == entry.getValue()); }
@Test public void testNoPolicyReturnsNoopEnforcement() { ActivePolicyEnforcement ape = new ActivePolicyEnforcement( new HashMap<>(), Collections.emptyMap(), mock(RegionServerServices.class)); SpaceViolationPolicyEnforcement enforcement = ape.getPolicyEnforcement( TableName.valueOf("nonexistent")); assertNotNull(enforcement); assertTrue( "Expected an instance of MissingSnapshotViolationPolicyEnforcement, but got " + enforcement.getClass(), enforcement instanceof MissingSnapshotViolationPolicyEnforcement); }
checkCellSizeLimit(region, mutation); spaceQuotaEnforcement.getPolicyEnforcement(region).check(mutation); quota.addMutation(mutation);
@Test public void testNonViolatingQuotaCachesPolicyEnforcment() { final Map<TableName,SpaceQuotaSnapshot> snapshots = new HashMap<>(); final TableName tableName = TableName.valueOf("my_table"); snapshots.put(tableName, new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, 1024)); final ActivePolicyEnforcement ape = new ActivePolicyEnforcement( Collections.emptyMap(), snapshots, rss); SpaceViolationPolicyEnforcement policyEnforcement = ape.getPolicyEnforcement(tableName); assertTrue( "Found the wrong class: " + policyEnforcement.getClass(), policyEnforcement instanceof DefaultViolationPolicyEnforcement); SpaceViolationPolicyEnforcement copy = ape.getPolicyEnforcement(tableName); assertTrue("Expected the instance to be cached", policyEnforcement == copy); Entry<TableName,SpaceViolationPolicyEnforcement> entry = ape.getLocallyCachedPolicies().entrySet().iterator().next(); assertTrue(policyEnforcement == entry.getValue()); }
Append append = ProtobufUtil.toAppend(mutation, cellScanner); checkCellSizeLimit(region, append); spaceQuota.getPolicyEnforcement(region).check(append); quota.addMutation(append); Result r = null;