Fix constructors of NoOpResult (#66269)

This commit is contained in:
asce0705 2020-12-17 02:12:14 +08:00 committed by Nhat Nguyen
parent 5e5eb7bc08
commit 5000ec87ca
2 changed files with 12 additions and 5 deletions

View File

@ -553,11 +553,11 @@ public abstract class Engine implements Closeable {
public static class NoOpResult extends Result { public static class NoOpResult extends Result {
NoOpResult(long term, long seqNo) { NoOpResult(long term, long seqNo) {
super(Operation.TYPE.NO_OP, term, 0, seqNo); super(Operation.TYPE.NO_OP, 0, term, seqNo);
} }
NoOpResult(long term, long seqNo, Exception failure) { NoOpResult(long term, long seqNo, Exception failure) {
super(Operation.TYPE.NO_OP, failure, term, 0, seqNo); super(Operation.TYPE.NO_OP, failure, 0, term, seqNo);
} }
} }

View File

@ -4437,11 +4437,15 @@ public class InternalEngineTests extends EngineTestCase {
* Verifies that a segment containing only no-ops can be used to look up _version and _seqno. * Verifies that a segment containing only no-ops can be used to look up _version and _seqno.
*/ */
public void testSegmentContainsOnlyNoOps() throws Exception { public void testSegmentContainsOnlyNoOps() throws Exception {
Engine.NoOpResult noOpResult = engine.noOp(new Engine.NoOp(1, primaryTerm.get(), final long seqNo = randomLongBetween(0, 1000);
final long term = this.primaryTerm.get();
Engine.NoOpResult noOpResult = engine.noOp(new Engine.NoOp(seqNo, term,
randomFrom(Engine.Operation.Origin.values()), randomNonNegativeLong(), "test")); randomFrom(Engine.Operation.Origin.values()), randomNonNegativeLong(), "test"));
assertThat(noOpResult.getFailure(), nullValue()); assertThat(noOpResult.getFailure(), nullValue());
assertThat(noOpResult.getSeqNo(), equalTo(seqNo));
assertThat(noOpResult.getTerm(), equalTo(term));
engine.refresh("test"); engine.refresh("test");
Engine.DeleteResult deleteResult = engine.delete(replicaDeleteForDoc("id", 1, 2, randomNonNegativeLong())); Engine.DeleteResult deleteResult = engine.delete(replicaDeleteForDoc("id", 1, seqNo + between(1, 1000), randomNonNegativeLong()));
assertThat(deleteResult.getFailure(), nullValue()); assertThat(deleteResult.getFailure(), nullValue());
engine.refresh("test"); engine.refresh("test");
} }
@ -4467,8 +4471,11 @@ public class InternalEngineTests extends EngineTestCase {
assertThat(delete.getFailure(), nullValue()); assertThat(delete.getFailure(), nullValue());
break; break;
case NO_OP: case NO_OP:
Engine.NoOpResult noOp = engine.noOp(new Engine.NoOp(i, primaryTerm.get(), long seqNo = i;
Engine.NoOpResult noOp = engine.noOp(new Engine.NoOp(seqNo, primaryTerm.get(),
randomFrom(Engine.Operation.Origin.values()), randomNonNegativeLong(), "")); randomFrom(Engine.Operation.Origin.values()), randomNonNegativeLong(), ""));
assertThat(noOp.getTerm(), equalTo(primaryTerm.get()));
assertThat(noOp.getSeqNo(), equalTo(seqNo));
assertThat(noOp.getFailure(), nullValue()); assertThat(noOp.getFailure(), nullValue());
break; break;
default: default: