private void assertSpaceQuota( long sizeLimit, SpaceViolationPolicy violationPolicy, QuotaSettings actualSettings) { assertTrue("The actual QuotaSettings was not an instance of " + SpaceLimitSettings.class + " but of " + actualSettings.getClass(), actualSettings instanceof SpaceLimitSettings); SpaceLimitRequest spaceLimitRequest = ((SpaceLimitSettings) actualSettings).getProto(); assertEquals(sizeLimit, spaceLimitRequest.getQuota().getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(spaceLimitRequest.getQuota().getViolationPolicy())); }
@Test public void testSpaceLimitSettingsForDeletes() { final String ns = "ns1"; final TableName tn = TableName.valueOf("tn1"); QuotaSettings nsSettings = QuotaSettingsFactory.removeNamespaceSpaceLimit(ns); assertNotNull("QuotaSettings should not be null", nsSettings); assertTrue("Should be an instance of SpaceLimitSettings", nsSettings instanceof SpaceLimitSettings); SpaceLimitRequest nsProto = ((SpaceLimitSettings) nsSettings).getProto(); assertTrue("Request should have a SpaceQuota", nsProto.hasQuota()); assertTrue("The remove attribute should be true", nsProto.getQuota().getRemove()); QuotaSettings tableSettings = QuotaSettingsFactory.removeTableSpaceLimit(tn); assertNotNull("QuotaSettings should not be null", tableSettings); assertTrue("Should be an instance of SpaceLimitSettings", tableSettings instanceof SpaceLimitSettings); SpaceLimitRequest tableProto = ((SpaceLimitSettings) tableSettings).getProto(); assertTrue("Request should have a SpaceQuota", tableProto.hasQuota()); assertTrue("The remove attribute should be true", tableProto.getQuota().getRemove()); } }
@Test public void testSpaceLimitSettings() { final TableName tableName = TableName.valueOf("foo"); final long sizeLimit = 1024L * 1024L * 1024L * 75; // 75GB final SpaceViolationPolicy violationPolicy = SpaceViolationPolicy.NO_INSERTS; QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tableName, sizeLimit, violationPolicy); assertNotNull("QuotaSettings should not be null", settings); assertTrue("Should be an instance of SpaceLimitSettings", settings instanceof SpaceLimitSettings); SpaceLimitSettings spaceLimitSettings = (SpaceLimitSettings) settings; SpaceLimitRequest protoRequest = spaceLimitSettings.getProto(); assertTrue("Request should have a SpaceQuota", protoRequest.hasQuota()); SpaceQuota quota = protoRequest.getQuota(); assertEquals(sizeLimit, quota.getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(quota.getViolationPolicy())); assertFalse("The remove attribute should be false", quota.getRemove()); }
@Test public void testFetchSpaceQuota() throws Exception { Multimap<TableName,QuotaSettings> tables = helper.createTablesWithSpaceQuotas(); // Can pass in an empty map, we're not consulting it. chore.initializeSnapshotStores(Collections.emptyMap()); // All tables that were created should have a quota defined. for (Entry<TableName,QuotaSettings> entry : tables.entries()) { final TableName table = entry.getKey(); final QuotaSettings qs = entry.getValue(); assertTrue("QuotaSettings was an instance of " + qs.getClass(), qs instanceof SpaceLimitSettings); SpaceQuota spaceQuota = null; if (qs.getTableName() != null) { spaceQuota = chore.getTableSnapshotStore().getSpaceQuota(table); assertNotNull("Could not find table space quota for " + table, spaceQuota); } else if (qs.getNamespace() != null) { spaceQuota = chore.getNamespaceSnapshotStore().getSpaceQuota(table.getNamespaceAsString()); assertNotNull("Could not find namespace space quota for " + table.getNamespaceAsString(), spaceQuota); } else { fail("Expected table or namespace space quota"); } final SpaceLimitSettings sls = (SpaceLimitSettings) qs; assertEquals(sls.getProto().getQuota(), spaceQuota); } TableName tableWithoutQuota = helper.createTable(); assertNull(chore.getTableSnapshotStore().getSpaceQuota(tableWithoutQuota)); }
QuotaProtos.SpaceLimitRequest spaceRequest = settingsToMerge.getProto();
assertNull("Namespace should be null", spaceLimit.getNamespace()); assertNull("RegionServer should be null", spaceLimit.getRegionServer()); assertTrue("SpaceLimitSettings should have a SpaceQuota", spaceLimit.getProto().hasQuota()); assertEquals(spaceQuota, spaceLimit.getProto().getQuota()); seenSpace = true; } else {
@Test public void testSpaceLimitSettingsForDeletes() { final String ns = "ns1"; final TableName tn = TableName.valueOf("tn1"); QuotaSettings nsSettings = QuotaSettingsFactory.removeNamespaceSpaceLimit(ns); assertNotNull("QuotaSettings should not be null", nsSettings); assertTrue("Should be an instance of SpaceLimitSettings", nsSettings instanceof SpaceLimitSettings); SpaceLimitRequest nsProto = ((SpaceLimitSettings) nsSettings).getProto(); assertTrue("Request should have a SpaceQuota", nsProto.hasQuota()); assertTrue("The remove attribute should be true", nsProto.getQuota().getRemove()); QuotaSettings tableSettings = QuotaSettingsFactory.removeTableSpaceLimit(tn); assertNotNull("QuotaSettings should not be null", tableSettings); assertTrue("Should be an instance of SpaceLimitSettings", tableSettings instanceof SpaceLimitSettings); SpaceLimitRequest tableProto = ((SpaceLimitSettings) tableSettings).getProto(); assertTrue("Request should have a SpaceQuota", tableProto.hasQuota()); assertTrue("The remove attribute should be true", tableProto.getQuota().getRemove()); } }
@Test public void testSpaceLimitSettings() { final TableName tableName = TableName.valueOf("foo"); final long sizeLimit = 1024L * 1024L * 1024L * 75; // 75GB final SpaceViolationPolicy violationPolicy = SpaceViolationPolicy.NO_INSERTS; QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tableName, sizeLimit, violationPolicy); assertNotNull("QuotaSettings should not be null", settings); assertTrue("Should be an instance of SpaceLimitSettings", settings instanceof SpaceLimitSettings); SpaceLimitSettings spaceLimitSettings = (SpaceLimitSettings) settings; SpaceLimitRequest protoRequest = spaceLimitSettings.getProto(); assertTrue("Request should have a SpaceQuota", protoRequest.hasQuota()); SpaceQuota quota = protoRequest.getQuota(); assertEquals(sizeLimit, quota.getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(quota.getViolationPolicy())); assertFalse("The remove attribute should be false", quota.getRemove()); }
assertNull("Username should be null", spaceLimit.getUserName()); assertNull("Namespace should be null", spaceLimit.getNamespace()); assertTrue("SpaceLimitSettings should have a SpaceQuota", spaceLimit.getProto().hasQuota()); assertEquals(spaceQuota, spaceLimit.getProto().getQuota()); seenSpace = true; } else {
private void assertSpaceQuota( long sizeLimit, SpaceViolationPolicy violationPolicy, QuotaSettings actualSettings) { assertTrue("The actual QuotaSettings was not an instance of " + SpaceLimitSettings.class + " but of " + actualSettings.getClass(), actualSettings instanceof SpaceLimitSettings); SpaceLimitRequest spaceLimitRequest = ((SpaceLimitSettings) actualSettings).getProto(); assertEquals(sizeLimit, spaceLimitRequest.getQuota().getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(spaceLimitRequest.getQuota().getViolationPolicy())); }
@Test public void testFetchSpaceQuota() throws Exception { Multimap<TableName,QuotaSettings> tables = helper.createTablesWithSpaceQuotas(); // Can pass in an empty map, we're not consulting it. chore.initializeSnapshotStores(Collections.emptyMap()); // All tables that were created should have a quota defined. for (Entry<TableName,QuotaSettings> entry : tables.entries()) { final TableName table = entry.getKey(); final QuotaSettings qs = entry.getValue(); assertTrue("QuotaSettings was an instance of " + qs.getClass(), qs instanceof SpaceLimitSettings); SpaceQuota spaceQuota = null; if (qs.getTableName() != null) { spaceQuota = chore.getTableSnapshotStore().getSpaceQuota(table); assertNotNull("Could not find table space quota for " + table, spaceQuota); } else if (qs.getNamespace() != null) { spaceQuota = chore.getNamespaceSnapshotStore().getSpaceQuota(table.getNamespaceAsString()); assertNotNull("Could not find namespace space quota for " + table.getNamespaceAsString(), spaceQuota); } else { fail("Expected table or namespace space quota"); } final SpaceLimitSettings sls = (SpaceLimitSettings) qs; assertEquals(sls.getProto().getQuota(), spaceQuota); } TableName tableWithoutQuota = helper.createTable(); assertNull(chore.getTableSnapshotStore().getSpaceQuota(tableWithoutQuota)); }