Add missing hashCode method to RecoveryState#File
This commit is contained in:
parent
abc7de96ae
commit
3b41299273
|
@ -655,6 +655,15 @@ public class RecoveryState implements ToXContent, Streamable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = name.hashCode();
|
||||||
|
result = 31 * result + (int) (length ^ (length >>> 32));
|
||||||
|
result = 31 * result + (int) (recovered ^ (recovered >>> 32));
|
||||||
|
result = 31 * result + (reused ? 1 : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "file (name [" + name + "], reused [" + reused + "], length [" + length + "], recovered [" + recovered + "])";
|
return "file (name [" + name + "], reused [" + reused + "], length [" + length + "], recovered [" + recovered + "])";
|
||||||
|
|
|
@ -507,4 +507,23 @@ public class RecoveryStateTest extends ElasticsearchTestCase {
|
||||||
readWriteIndex.join();
|
readWriteIndex.join();
|
||||||
assertThat(readWriteIndex.error.get(), equalTo(null));
|
assertThat(readWriteIndex.error.get(), equalTo(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFileHashCodeAndEquals() {
|
||||||
|
File f = new File("foo", randomIntBetween(0, 100), randomBoolean());
|
||||||
|
File anotherFile = new File(f.name(), f.length(), f.reused());
|
||||||
|
assertEquals(f, anotherFile);
|
||||||
|
assertEquals(f.hashCode(), anotherFile.hashCode());
|
||||||
|
int iters = randomIntBetween(10, 100);
|
||||||
|
for (int i = 0; i < iters; i++) {
|
||||||
|
f = new File("foo", randomIntBetween(0, 100), randomBoolean());
|
||||||
|
anotherFile = new File(f.name(), randomIntBetween(0, 100), randomBoolean());
|
||||||
|
if (f.equals(anotherFile)) {
|
||||||
|
assertEquals(f.hashCode(), anotherFile.hashCode());
|
||||||
|
} else if (f.hashCode() != anotherFile.hashCode()) {
|
||||||
|
assertFalse(f.equals(anotherFile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue