Skip to content

Commit

Permalink
HDFS-17214. RBF: The Quota class' andByStorageType method res has an …
Browse files Browse the repository at this point in the history
…incorrect initial value. (#6135)

Co-authored-by: xiaojunxiang <[email protected]>
  • Loading branch information
xiaojunxiang2023 and xiaojunxiang2023 authored Oct 3, 2023
1 parent fe3984a commit 0cfffb3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public static boolean orByStorageType(Predicate<StorageType> predicate) {
* @return true if bitwise AND by all storage type returns true, false otherwise.
*/
public static boolean andByStorageType(Predicate<StorageType> predicate) {
boolean res = false;
boolean res = true;
for (StorageType type : StorageType.values()) {
res &= predicate.test(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
import java.util.Arrays;
import java.util.function.Predicate;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CreateFlag;
Expand Down Expand Up @@ -1168,6 +1170,34 @@ public void testQuotaUpdateWhenDestinationNotPresent() throws Exception {
assertEquals(0, quotaUsage.getSpaceConsumed());
}

@Test
public void testAndByStorageType() {
long[] typeQuota = new long[StorageType.values().length];
Arrays.fill(typeQuota, HdfsConstants.QUOTA_DONT_SET);

Predicate<StorageType> predicate = new Predicate<StorageType>() {
@Override
public boolean test(StorageType storageType) {
return typeQuota[storageType.ordinal()] == HdfsConstants.QUOTA_DONT_SET;
}
};

assertTrue(Quota.andByStorageType(predicate));

// This is a value to test for,
// as long as it is not equal to HdfsConstants.QUOTA_DONT_SET
typeQuota[0] = HdfsConstants.QUOTA_RESET;
assertFalse(Quota.andByStorageType(predicate));

Arrays.fill(typeQuota, HdfsConstants.QUOTA_DONT_SET);
typeQuota[1] = HdfsConstants.QUOTA_RESET;
assertFalse(Quota.andByStorageType(predicate));

Arrays.fill(typeQuota, HdfsConstants.QUOTA_DONT_SET);
typeQuota[typeQuota.length-1] = HdfsConstants.QUOTA_RESET;
assertFalse(Quota.andByStorageType(predicate));
}

/**
* Add three mount tables.
* /dir-1 --> ns0---/dir-1 [nsQuota, ssQuota]
Expand Down

0 comments on commit 0cfffb3

Please sign in to comment.