mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-26 06:46:10 +00:00
Add equals/hashCode to SeqNoStats (#35223)
This commit adds equals/hashCode to SeqNoStats so we can verify it wholly in tests.
This commit is contained in:
parent
44f08717ba
commit
855ab3fa1e
@ -26,6 +26,7 @@ import org.elasticsearch.common.xcontent.ToXContentFragment;
|
|||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class SeqNoStats implements ToXContentFragment, Writeable {
|
public class SeqNoStats implements ToXContentFragment, Writeable {
|
||||||
|
|
||||||
@ -83,6 +84,21 @@ public class SeqNoStats implements ToXContentFragment, Writeable {
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
final SeqNoStats that = (SeqNoStats) o;
|
||||||
|
return maxSeqNo == that.maxSeqNo &&
|
||||||
|
localCheckpoint == that.localCheckpoint &&
|
||||||
|
globalCheckpoint == that.globalCheckpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(maxSeqNo, localCheckpoint, globalCheckpoint);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SeqNoStats{" +
|
return "SeqNoStats{" +
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package org.elasticsearch.index.seqno;
|
package org.elasticsearch.index.seqno;
|
||||||
|
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
@ -57,4 +58,11 @@ public class SequenceNumbersTests extends ESTestCase {
|
|||||||
assertThat(e, hasToString(containsString("sequence number must be assigned")));
|
assertThat(e, hasToString(containsString("sequence number must be assigned")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSeqNoStatsEqualsAndHashCode() {
|
||||||
|
final long maxSeqNo = randomLongBetween(SequenceNumbers.UNASSIGNED_SEQ_NO, Long.MAX_VALUE);
|
||||||
|
final long localCheckpoint = randomLongBetween(SequenceNumbers.UNASSIGNED_SEQ_NO, maxSeqNo);
|
||||||
|
final long globalCheckpoint = randomLongBetween(SequenceNumbers.UNASSIGNED_SEQ_NO, localCheckpoint);
|
||||||
|
EqualsHashCodeTestUtils.checkEqualsAndHashCode(new SeqNoStats(maxSeqNo, localCheckpoint, globalCheckpoint),
|
||||||
|
stats -> new SeqNoStats(stats.getMaxSeqNo(), stats.getLocalCheckpoint(), stats.getGlobalCheckpoint()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1308,12 +1308,7 @@ public final class InternalTestCluster extends TestCluster {
|
|||||||
} catch (AlreadyClosedException e) {
|
} catch (AlreadyClosedException e) {
|
||||||
continue; // shard is closed - just ignore
|
continue; // shard is closed - just ignore
|
||||||
}
|
}
|
||||||
assertThat(replicaShardRouting + " local checkpoint mismatch",
|
assertThat(replicaShardRouting + " seq_no_stats mismatch", seqNoStats, equalTo(primarySeqNoStats));
|
||||||
seqNoStats.getLocalCheckpoint(), equalTo(primarySeqNoStats.getLocalCheckpoint()));
|
|
||||||
assertThat(replicaShardRouting + " global checkpoint mismatch",
|
|
||||||
seqNoStats.getGlobalCheckpoint(), equalTo(primarySeqNoStats.getGlobalCheckpoint()));
|
|
||||||
assertThat(replicaShardRouting + " max seq no mismatch",
|
|
||||||
seqNoStats.getMaxSeqNo(), equalTo(primarySeqNoStats.getMaxSeqNo()));
|
|
||||||
// the local knowledge on the primary of the global checkpoint equals the global checkpoint on the shard
|
// the local knowledge on the primary of the global checkpoint equals the global checkpoint on the shard
|
||||||
assertThat(replicaShardRouting + " global checkpoint syncs mismatch", seqNoStats.getGlobalCheckpoint(),
|
assertThat(replicaShardRouting + " global checkpoint syncs mismatch", seqNoStats.getGlobalCheckpoint(),
|
||||||
equalTo(syncGlobalCheckpoints.get(replicaShardRouting.allocationId().getId())));
|
equalTo(syncGlobalCheckpoints.get(replicaShardRouting.allocationId().getId())));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user