Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ public Response getFileCounts(
if (bucket != null && !bucket.equals(key.getBucket())) {
matches = false;
}

if (fileSize > 0 && fileSize != key.getFileSizeUpperBound()) {
matches = false;
}

if (matches && count != null && count > 0) {
FileCountBySize record = new FileCountBySize();
record.setVolume(key.getVolume());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,15 @@ public void testGetFileCounts() throws Exception {
assertEquals(2L, rocksCount3.longValue(), "Expected RocksDB bin 1024 to have count 2 for vol2/bucket1");

// --- Now test the query endpoints of the utilization service ---
verifyFileCountQueries();
}

/**
* Verify the filtering behaviour of the fileCount endpoint against the
* bins written by {@link #testGetFileCounts()}: vol1/bucket1:1024,
* vol1/bucket1:131072 and vol2/bucket1:1024, each with count 2.
*/
private void verifyFileCountQueries() {
Response response = utilizationEndpoint.getFileCounts(null, null, 0);
List<FileCountBySize> resultSet =
(List<FileCountBySize>) response.getEntity();
Expand Down Expand Up @@ -952,6 +961,32 @@ public void testGetFileCounts() throws Exception {
resultSet = (List<FileCountBySize>) response.getEntity();
assertEquals(0, resultSet.size());

// Test for "fileSize" query param on its own.
response = utilizationEndpoint.getFileCounts(null, null, 131072);
resultSet = (List<FileCountBySize>) response.getEntity();
assertEquals(1, resultSet.size());
assertTrue(resultSet.stream().allMatch(o -> o.getVolume().equals("vol1") &&
o.getBucket().equals("bucket1") && o.getFileSize() == 131072L));

// Test for "volume" + "fileSize" query params, without bucket.
response = utilizationEndpoint.getFileCounts("vol1", null, 131072);
resultSet = (List<FileCountBySize>) response.getEntity();
assertEquals(1, resultSet.size());
assertTrue(resultSet.stream().allMatch(o -> o.getVolume().equals("vol1") &&
o.getFileSize() == 131072L));

// Test for "bucket" + "fileSize" query params, without volume.
response = utilizationEndpoint.getFileCounts(null, "bucket1", 1024);
resultSet = (List<FileCountBySize>) response.getEntity();
assertEquals(2, resultSet.size());
assertTrue(resultSet.stream().allMatch(o -> o.getBucket().equals("bucket1") &&
o.getFileSize() == 1024L));

// Test for a fileSize that is not a bin upper bound, without volume and bucket.
response = utilizationEndpoint.getFileCounts(null, null, 1310725);
resultSet = (List<FileCountBySize>) response.getEntity();
assertEquals(0, resultSet.size());

// Test for "volume" + "bucket" + "fileSize" query params.
response = utilizationEndpoint.getFileCounts("vol1", "bucket1", 131072);
resultSet = (List<FileCountBySize>) response.getEntity();
Expand Down