@Test(expected = IllegalArgumentException.class) public void testFileIsNotAFile() throws Exception { final List<String> paths = new ArrayList<>(); String path = "/1"; FileStatus status = mock(FileStatus.class); when(fs.getFileStatus(new Path(path))).thenReturn(status); when(status.getLen()).thenReturn(1000L); when(status.isFile()).thenReturn(false); paths.add(path); // Quota is not in violation now SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, Long.MAX_VALUE); policy.initialize(rss, tableName, snapshot); // If the file to bulk load isn't a file, this should throw an exception policy.computeBulkLoadSize(fs, paths); }
@Test(expected = SpaceLimitingException.class) public void testSumOfFilesOverLimit() throws Exception { final List<String> paths = new ArrayList<>(); final List<FileStatus> statuses = new ArrayList<>(); final long length = 1024L; for (int i = 0; i < 5; i++) { String path = "/" + i; FileStatus status = mock(FileStatus.class); when(fs.getFileStatus(new Path(path))).thenReturn(status); when(status.getLen()).thenReturn(length); when(status.isFile()).thenReturn(true); paths.add(path); statuses.add(status); } // Quota is not in violation now, but 5*1024 files would push us to violation SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, 5000L); policy.initialize(rss, tableName, snapshot); policy.computeBulkLoadSize(fs, paths); } }
@Test public void testFilesUnderLimit() throws Exception { final List<String> paths = new ArrayList<>(); final List<FileStatus> statuses = new ArrayList<>(); final long length = 100L * 1024L; for (int i = 0; i < 5; i++) { String path = "/" + i; FileStatus status = mock(FileStatus.class); when(fs.getFileStatus(new Path(path))).thenReturn(status); when(status.getLen()).thenReturn(length); when(status.isFile()).thenReturn(true); paths.add(path); statuses.add(status); } // Quota is not in violation now SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, length * 6); policy.initialize(rss, tableName, snapshot); policy.computeBulkLoadSize(fs, paths); }
@Test(expected = SpaceLimitingException.class) public void testOneFileInBatchOverLimit() throws Exception { final List<String> paths = new ArrayList<>(); final List<FileStatus> statuses = new ArrayList<>(); final long length = 1000L * 1024L; for (int i = 0; i < 5; i++) { String path = "/" + i; FileStatus status = mock(FileStatus.class); when(fs.getFileStatus(new Path(path))).thenReturn(status); when(status.getLen()).thenReturn(length); when(status.isFile()).thenReturn(true); paths.add(path); statuses.add(status); } // Quota is not in violation now SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, 1024L); policy.initialize(rss, tableName, snapshot); policy.computeBulkLoadSize(fs, paths); }
/** * Constructs the appropriate {@link SpaceViolationPolicyEnforcement} for tables that are * in violation of their space quota. */ public SpaceViolationPolicyEnforcement create( RegionServerServices rss, TableName tableName, SpaceQuotaSnapshot snapshot) { SpaceViolationPolicyEnforcement enforcement; SpaceQuotaStatus status = snapshot.getQuotaStatus(); if (!status.isInViolation()) { throw new IllegalArgumentException(tableName + " is not in violation. Snapshot=" + snapshot); } switch (status.getPolicy().get()) { case DISABLE: enforcement = new DisableTableViolationPolicyEnforcement(); break; case NO_WRITES_COMPACTIONS: enforcement = new NoWritesCompactionsViolationPolicyEnforcement(); break; case NO_WRITES: enforcement = new NoWritesViolationPolicyEnforcement(); break; case NO_INSERTS: enforcement = new NoInsertsViolationPolicyEnforcement(); break; default: throw new IllegalArgumentException("Unhandled SpaceViolationPolicy: " + status.getPolicy()); } enforcement.initialize(rss, tableName, snapshot); return enforcement; }
@Test(expected = IllegalArgumentException.class) public void testFileIsNotAFile() throws Exception { final List<String> paths = new ArrayList<>(); String path = "/1"; FileStatus status = mock(FileStatus.class); when(fs.getFileStatus(new Path(path))).thenReturn(status); when(status.getLen()).thenReturn(1000L); when(status.isFile()).thenReturn(false); paths.add(path); // Quota is not in violation now SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, Long.MAX_VALUE); policy.initialize(rss, tableName, snapshot); // If the file to bulk load isn't a file, this should throw an exception policy.checkBulkLoad(fs, paths); }
@Test(expected = SpaceLimitingException.class) public void testOneFileInBatchOverLimit() throws Exception { final List<String> paths = new ArrayList<>(); final List<FileStatus> statuses = new ArrayList<>(); final long length = 1000L * 1024L; for (int i = 0; i < 5; i++) { String path = "/" + i; FileStatus status = mock(FileStatus.class); when(fs.getFileStatus(new Path(path))).thenReturn(status); when(status.getLen()).thenReturn(length); when(status.isFile()).thenReturn(true); paths.add(path); statuses.add(status); } // Quota is not in violation now SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, 1024L); policy.initialize(rss, tableName, snapshot); policy.checkBulkLoad(fs, paths); }
@Test public void testFilesUnderLimit() throws Exception { final List<String> paths = new ArrayList<>(); final List<FileStatus> statuses = new ArrayList<>(); final long length = 100L * 1024L; for (int i = 0; i < 5; i++) { String path = "/" + i; FileStatus status = mock(FileStatus.class); when(fs.getFileStatus(new Path(path))).thenReturn(status); when(status.getLen()).thenReturn(length); when(status.isFile()).thenReturn(true); paths.add(path); statuses.add(status); } // Quota is not in violation now SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, length * 6); policy.initialize(rss, tableName, snapshot); policy.checkBulkLoad(fs, paths); }
@Test(expected = SpaceLimitingException.class) public void testSumOfFilesOverLimit() throws Exception { final List<String> paths = new ArrayList<>(); final List<FileStatus> statuses = new ArrayList<>(); final long length = 1024L; for (int i = 0; i < 5; i++) { String path = "/" + i; FileStatus status = mock(FileStatus.class); when(fs.getFileStatus(new Path(path))).thenReturn(status); when(status.getLen()).thenReturn(length); when(status.isFile()).thenReturn(true); paths.add(path); statuses.add(status); } // Quota is not in violation now, but 5*1024 files would push us to violation SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, 5000L); policy.initialize(rss, tableName, snapshot); policy.checkBulkLoad(fs, paths); } }