ByteSizeValue.equals should normalize units
currently ByteSizeValue.parse("1GB") is not equal to ByteSizeValue.parse("1024MB") Closes #13784
This commit is contained in:
parent
de73910a13
commit
5a0f2fd1ac
|
@ -245,15 +245,16 @@ public class ByteSizeValue implements Streamable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ByteSizeValue sizeValue = (ByteSizeValue) o;
|
ByteSizeValue sizeValue = (ByteSizeValue) o;
|
||||||
|
|
||||||
if (size != sizeValue.size) return false;
|
return bytes() == sizeValue.bytes();
|
||||||
if (sizeUnit != sizeValue.sizeUnit) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -57,6 +57,13 @@ public class ByteSizeValueTests extends ESTestCase {
|
||||||
assertThat(ByteSizeUnit.PB.toPB(10), is(new ByteSizeValue(10, ByteSizeUnit.PB).pb()));
|
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
|
@Test
|
||||||
public void testToString() {
|
public void testToString() {
|
||||||
assertThat("10b", is(new ByteSizeValue(10, ByteSizeUnit.BYTES).toString()));
|
assertThat("10b", is(new ByteSizeValue(10, ByteSizeUnit.BYTES).toString()));
|
||||||
|
|
Loading…
Reference in New Issue