HDFS-5381. ExtendedBlock#hashCode should use both blockId and block pool ID (Benoy Antony via Colin Patrick McCabe)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1593348 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Colin McCabe 2014-05-08 17:50:24 +00:00
parent 4518a0db27
commit 0e76ba79d6
3 changed files with 26 additions and 1 deletions

View File

@ -183,6 +183,10 @@ Release 2.5.0 - UNRELEASED
HDFS-6337. Setfacl testcase is failing due to dash character in username
in TestAclCLI (umamahesh)
HDFS-5381. ExtendedBlock#hashCode should use both blockId and block pool ID
(Benoy Antony via Colin Patrick McCabe)
Release 2.4.1 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -112,7 +112,8 @@ public boolean equals(Object o) {
@Override // Object
public int hashCode() {
return block.hashCode();
int result = 31 + poolId.hashCode();
return (31 * result + block.hashCode());
}
@Override // Object

View File

@ -50,6 +50,26 @@ public void testEquals() {
new ExtendedBlock(POOL_A, BLOCK_1_GS2));
}
@Test
public void testHashcode() {
// Different pools, same block id -> different hashcode
assertNotEquals(
new ExtendedBlock(POOL_A, BLOCK_1_GS1).hashCode(),
new ExtendedBlock(POOL_B, BLOCK_1_GS1).hashCode());
// Same pool, different block id -> different hashcode
assertNotEquals(
new ExtendedBlock(POOL_A, BLOCK_1_GS1).hashCode(),
new ExtendedBlock(POOL_A, BLOCK_2_GS1).hashCode());
// Same block -> same hashcode
assertEquals(
new ExtendedBlock(POOL_A, BLOCK_1_GS1).hashCode(),
new ExtendedBlock(POOL_A, BLOCK_1_GS1).hashCode());
}
private static void assertNotEquals(Object a, Object b) {
assertFalse("expected not equal: '" + a + "' and '" + b + "'",
a.equals(b));