ByteSizeValue.equals should normalize units

currently ByteSizeValue.parse("1GB") is not equal to ByteSizeValue.parse("1024MB")

Closes #13784
This commit is contained in:
Boaz Leskes 2015-09-25 08:35:40 +02:00
parent de73910a13
commit 5a0f2fd1ac
2 changed files with 14 additions and 6 deletions

View File

@ -245,15 +245,16 @@ public class ByteSizeValue implements Streamable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ByteSizeValue sizeValue = (ByteSizeValue) o;
if (size != sizeValue.size) return false;
if (sizeUnit != sizeValue.sizeUnit) return false;
return true;
return bytes() == sizeValue.bytes();
}
@Override

View File

@ -57,6 +57,13 @@ public class ByteSizeValueTests extends ESTestCase {
assertThat(ByteSizeUnit.PB.toPB(10), is(new ByteSizeValue(10, ByteSizeUnit.PB).pb()));
}
public void testEquality() {
String[] equalValues = new String[]{"2GB", "2048MB", "2097152KB", "2147483684B"};
ByteSizeValue value1 = ByteSizeValue.parseBytesSizeValue(randomFrom(equalValues), "equalTest");
ByteSizeValue value2 = ByteSizeValue.parseBytesSizeValue(randomFrom(equalValues), "equalTest");
assertThat(value1, equalTo(value2));
}
@Test
public void testToString() {
assertThat("10b", is(new ByteSizeValue(10, ByteSizeUnit.BYTES).toString()));