/** * 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 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); }
@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)); }
@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()); }
@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 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 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)); }
@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); }
@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()); }
@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 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 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()); }