Skip to content

Commit

Permalink
ByteSizeValue.equals should normalize units
Browse files Browse the repository at this point in the history
currently ByteSizeValue.parse("1GB") is not equal to ByteSizeValue.parse("1024MB")

Closes #13784
  • Loading branch information
bleskes committed Sep 25, 2015
1 parent 2c5b56e commit 6b38841
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Expand Up @@ -245,15 +245,16 @@ public void writeTo(StreamOutput out) throws IOException {

@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
Expand Down
Expand Up @@ -57,6 +57,13 @@ public void testSimple() {
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()));
Expand Down

0 comments on commit 6b38841

Please sign in to comment.