LOG.trace("Removing quota violation policy on " + tableName); getManager().disableViolationPolicyEnforcement(tableName); LOG.trace("Removing quota violation policy on " + tableName); getManager().disableViolationPolicyEnforcement(tableName);
@Test public void testExceptionOnPolicyEnforcementDisable() throws Exception { final TableName tableName = TableName.valueOf("foo"); final SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot( new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 1024L, 2048L); RegionServerServices rss = mock(RegionServerServices.class); SpaceViolationPolicyEnforcementFactory factory = mock( SpaceViolationPolicyEnforcementFactory.class); SpaceViolationPolicyEnforcement enforcement = mock(SpaceViolationPolicyEnforcement.class); RegionServerSpaceQuotaManager realManager = new RegionServerSpaceQuotaManager(rss, factory); when(factory.create(rss, tableName, snapshot)).thenReturn(enforcement); doNothing().when(enforcement).enable(); doThrow(new IOException("Failed for test!")).when(enforcement).disable(); // Enabling should work realManager.enforceViolationPolicy(tableName, snapshot); Map<TableName, SpaceViolationPolicyEnforcement> enforcements = realManager.copyActiveEnforcements(); assertEquals(1, enforcements.size()); // If the disable fails, we should still treat it as "active" realManager.disableViolationPolicyEnforcement(tableName); enforcements = realManager.copyActiveEnforcements(); assertEquals(1, enforcements.size()); } }
TableName.valueOf("table2"), policiesToEnforce.get(TableName.valueOf("table2"))); verify(manager).disableViolationPolicyEnforcement(TableName.valueOf("table3")); verify(manager).disableViolationPolicyEnforcement(TableName.valueOf("table4"));
@Test public void testPoliciesAreEnforced() throws IOException { // Create a number of policies that should be enforced (usage > limit) final Map<TableName,SpaceQuotaSnapshot> policiesToEnforce = new HashMap<>(); policiesToEnforce.put( TableName.valueOf("table1"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 1024L, 512L)); policiesToEnforce.put( TableName.valueOf("table2"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 2048L, 512L)); policiesToEnforce.put( TableName.valueOf("table3"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 4096L, 512L)); policiesToEnforce.put( TableName.valueOf("table4"), new SpaceQuotaSnapshot( new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES_COMPACTIONS), 8192L, 512L)); // No active enforcements when(manager.copyQuotaSnapshots()).thenReturn(Collections.emptyMap()); // Policies to enforce when(chore.fetchSnapshotsFromQuotaTable()).thenReturn(policiesToEnforce); chore.chore(); for (Entry<TableName,SpaceQuotaSnapshot> entry : policiesToEnforce.entrySet()) { // Ensure we enforce the policy verify(manager).enforceViolationPolicy(entry.getKey(), entry.getValue()); // Don't disable any policies verify(manager, never()).disableViolationPolicyEnforcement(entry.getKey()); } }
@Test public void testNewPolicyOverridesOld() throws IOException { final Map<TableName,SpaceQuotaSnapshot> policiesToEnforce = new HashMap<>(); policiesToEnforce.put( TableName.valueOf("table1"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 1024L, 512L)); policiesToEnforce.put( TableName.valueOf("table2"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 2048L, 512L)); policiesToEnforce.put( TableName.valueOf("table3"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 4096L, 512L)); final Map<TableName,SpaceQuotaSnapshot> previousPolicies = new HashMap<>(); previousPolicies.put( TableName.valueOf("table1"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 8192L, 512L)); // No active enforcements when(manager.getActivePoliciesAsMap()).thenReturn(previousPolicies); // Policies to enforce when(chore.fetchSnapshotsFromQuotaTable()).thenReturn(policiesToEnforce); chore.chore(); for (Entry<TableName,SpaceQuotaSnapshot> entry : policiesToEnforce.entrySet()) { verify(manager).enforceViolationPolicy(entry.getKey(), entry.getValue()); } verify(manager, never()).disableViolationPolicyEnforcement(TableName.valueOf("table1")); }
TableName.valueOf("table2"), policiesToEnforce.get(TableName.valueOf("table2"))); verify(manager).disableViolationPolicyEnforcement(TableName.valueOf("table3")); verify(manager).disableViolationPolicyEnforcement(TableName.valueOf("table4"));
@Test public void testExceptionOnPolicyEnforcementDisable() throws Exception { final TableName tableName = TableName.valueOf("foo"); final SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot( new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 1024L, 2048L); RegionServerServices rss = mock(RegionServerServices.class); SpaceViolationPolicyEnforcementFactory factory = mock( SpaceViolationPolicyEnforcementFactory.class); SpaceViolationPolicyEnforcement enforcement = mock(SpaceViolationPolicyEnforcement.class); RegionServerSpaceQuotaManager realManager = new RegionServerSpaceQuotaManager(rss, factory); when(factory.create(rss, tableName, snapshot)).thenReturn(enforcement); doNothing().when(enforcement).enable(); doThrow(new IOException("Failed for test!")).when(enforcement).disable(); // Enabling should work realManager.enforceViolationPolicy(tableName, snapshot); Map<TableName, SpaceViolationPolicyEnforcement> enforcements = realManager.copyActiveEnforcements(); assertEquals(1, enforcements.size()); // If the disable fails, we should still treat it as "active" realManager.disableViolationPolicyEnforcement(tableName); enforcements = realManager.copyActiveEnforcements(); assertEquals(1, enforcements.size()); } }
@Test public void testNewPolicyOverridesOld() throws IOException { final Map<TableName,SpaceQuotaSnapshot> policiesToEnforce = new HashMap<>(); policiesToEnforce.put( TableName.valueOf("table1"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 1024L, 512L)); policiesToEnforce.put( TableName.valueOf("table2"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 2048L, 512L)); policiesToEnforce.put( TableName.valueOf("table3"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 4096L, 512L)); final Map<TableName,SpaceQuotaSnapshot> previousPolicies = new HashMap<>(); previousPolicies.put( TableName.valueOf("table1"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 8192L, 512L)); // No active enforcements when(manager.getActivePoliciesAsMap()).thenReturn(previousPolicies); // Policies to enforce when(chore.fetchSnapshotsFromQuotaTable()).thenReturn(policiesToEnforce); chore.chore(); for (Entry<TableName,SpaceQuotaSnapshot> entry : policiesToEnforce.entrySet()) { verify(manager).enforceViolationPolicy(entry.getKey(), entry.getValue()); } verify(manager, never()).disableViolationPolicyEnforcement(TableName.valueOf("table1")); }
@Test public void testPoliciesAreEnforced() throws IOException { // Create a number of policies that should be enforced (usage > limit) final Map<TableName,SpaceQuotaSnapshot> policiesToEnforce = new HashMap<>(); policiesToEnforce.put( TableName.valueOf("table1"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 1024L, 512L)); policiesToEnforce.put( TableName.valueOf("table2"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 2048L, 512L)); policiesToEnforce.put( TableName.valueOf("table3"), new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 4096L, 512L)); policiesToEnforce.put( TableName.valueOf("table4"), new SpaceQuotaSnapshot( new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES_COMPACTIONS), 8192L, 512L)); // No active enforcements when(manager.copyQuotaSnapshots()).thenReturn(Collections.emptyMap()); // Policies to enforce when(chore.fetchSnapshotsFromQuotaTable()).thenReturn(policiesToEnforce); chore.chore(); for (Entry<TableName,SpaceQuotaSnapshot> entry : policiesToEnforce.entrySet()) { // Ensure we enforce the policy verify(manager).enforceViolationPolicy(entry.getKey(), entry.getValue()); // Don't disable any policies verify(manager, never()).disableViolationPolicyEnforcement(entry.getKey()); } }