HBASE-18990 ServerLoad doesn't override #equals which leads to #equals in ClusterStatus always false

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Reid Chan 2017-10-13 15:14:45 +08:00 committed by Chia-Ping Tsai
parent 6db1ce1e91
commit 9f61f8b281
3 changed files with 31 additions and 4 deletions

View File

@ -25,11 +25,10 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.hbase.shaded.com.google.common.base.Objects;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.master.RegionState;
import com.google.common.base.Objects;
/**
* Status information on the HBase cluster.
* <p>
@ -198,7 +197,6 @@ public class ClusterStatus {
return false;
}
ClusterStatus other = (ClusterStatus) o;
//TODO Override the equals() methods in ServerLoad.
return Objects.equal(getHBaseVersion(), other.getHBaseVersion()) &&
Objects.equal(this.liveServers, other.liveServers) &&
getDeadServerNames().containsAll(other.getDeadServerNames()) &&

View File

@ -26,6 +26,7 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.hadoop.hbase.shaded.com.google.common.base.Objects;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos;
@ -364,4 +365,31 @@ public class ServerLoad {
public long getReportTime() {
return reportTime;
}
@Override
public int hashCode() {
return Objects.hashCode(stores, storefiles, storeUncompressedSizeMB,
storefileSizeMB, memstoreSizeMB, storefileIndexSizeKB, readRequestsCount,
filteredReadRequestsCount, writeRequestsCount, rootIndexSizeKB, totalStaticIndexSizeKB,
totalStaticBloomSizeKB, totalCompactingKVs, currentCompactedKVs);
}
@Override
public boolean equals(Object other) {
if (other == this) return true;
if (other instanceof ServerLoad) {
ServerLoad sl = ((ServerLoad) other);
return stores == sl.stores && storefiles == sl.storefiles &&
storeUncompressedSizeMB == sl.storeUncompressedSizeMB &&
storefileSizeMB == sl.storefileSizeMB && memstoreSizeMB == sl.memstoreSizeMB &&
storefileIndexSizeKB == sl.storefileIndexSizeKB && readRequestsCount == sl.readRequestsCount &&
filteredReadRequestsCount == sl.filteredReadRequestsCount &&
writeRequestsCount == sl.writeRequestsCount && rootIndexSizeKB == sl.rootIndexSizeKB &&
totalStaticIndexSizeKB == sl.totalStaticIndexSizeKB &&
totalStaticBloomSizeKB == sl.totalStaticBloomSizeKB &&
totalCompactingKVs == sl.totalCompactingKVs &&
currentCompactedKVs == sl.currentCompactedKVs;
}
return false;
}
}

View File

@ -81,6 +81,7 @@ public class TestClientClusterStatus {
Assert.assertTrue(origin.getDeadServersSize() == defaults.getDeadServersSize());
Assert.assertTrue(origin.getRegionsCount() == defaults.getRegionsCount());
Assert.assertTrue(origin.getServersSize() == defaults.getServersSize());
Assert.assertTrue(origin.equals(defaults));
}
@Test
@ -100,7 +101,7 @@ public class TestClientClusterStatus {
Assert.assertNotNull(status.hashCode());
ClusterStatus nullEqualsCheck =
ADMIN.getClusterStatus(EnumSet.noneOf(Option.class));
Assert.assertNotNull(status.equals(nullEqualsCheck));
Assert.assertTrue(status.equals(nullEqualsCheck));
}
@Test