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