forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix local processed checkpoint update (opensearch-project#2576)
* fix local processed checkpoint update Signed-off-by: Poojita Raj <[email protected]> * separated tests + wrapper function Signed-off-by: Poojita Raj <[email protected]>
- Loading branch information
1 parent
a89b7e6
commit db57264
Showing
2 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...c/test/java/org/opensearch/index/seqno/SegmentReplicationLocalCheckpointTrackerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.seqno; | ||
|
||
import org.junit.Before; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class SegmentReplicationLocalCheckpointTrackerTests extends OpenSearchTestCase { | ||
|
||
private LocalCheckpointTracker tracker; | ||
|
||
public static LocalCheckpointTracker createEmptyTracker() { | ||
return new LocalCheckpointTracker(SequenceNumbers.NO_OPS_PERFORMED, SequenceNumbers.NO_OPS_PERFORMED); | ||
} | ||
|
||
@Override | ||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
tracker = createEmptyTracker(); | ||
} | ||
|
||
public void testSimpleSegrepProcessedNoPersistentUpdate() { | ||
// base case with no persistent checkpoint update | ||
long seqNo1; | ||
assertThat(tracker.getProcessedCheckpoint(), equalTo(SequenceNumbers.NO_OPS_PERFORMED)); | ||
seqNo1 = tracker.generateSeqNo(); | ||
assertThat(seqNo1, equalTo(0L)); | ||
tracker.fastForwardProcessedSeqNo(seqNo1); | ||
assertThat(tracker.getProcessedCheckpoint(), equalTo(-1L)); | ||
} | ||
|
||
public void testSimpleSegrepProcessedPersistentUpdate() { | ||
// base case with persistent checkpoint update | ||
long seqNo1; | ||
assertThat(tracker.getProcessedCheckpoint(), equalTo(SequenceNumbers.NO_OPS_PERFORMED)); | ||
seqNo1 = tracker.generateSeqNo(); | ||
assertThat(seqNo1, equalTo(0L)); | ||
|
||
tracker.markSeqNoAsPersisted(seqNo1); | ||
assertThat(tracker.getPersistedCheckpoint(), equalTo(0L)); | ||
tracker.fastForwardProcessedSeqNo(seqNo1); | ||
assertThat(tracker.getProcessedCheckpoint(), equalTo(0L)); | ||
assertThat(tracker.hasProcessed(0L), equalTo(true)); | ||
assertThat(tracker.hasProcessed(atLeast(1)), equalTo(false)); | ||
|
||
// idempotent case | ||
tracker.fastForwardProcessedSeqNo(seqNo1); | ||
assertThat(tracker.getProcessedCheckpoint(), equalTo(0L)); | ||
assertThat(tracker.hasProcessed(0L), equalTo(true)); | ||
assertThat(tracker.hasProcessed(atLeast(1)), equalTo(false)); | ||
|
||
} | ||
|
||
public void testSimpleSegrepProcessedPersistentUpdate2() { | ||
long seqNo1, seqNo2; | ||
assertThat(tracker.getProcessedCheckpoint(), equalTo(SequenceNumbers.NO_OPS_PERFORMED)); | ||
seqNo1 = tracker.generateSeqNo(); | ||
seqNo2 = tracker.generateSeqNo(); | ||
assertThat(seqNo1, equalTo(0L)); | ||
assertThat(seqNo2, equalTo(1L)); | ||
tracker.markSeqNoAsPersisted(seqNo1); | ||
tracker.markSeqNoAsPersisted(seqNo2); | ||
assertThat(tracker.getProcessedCheckpoint(), equalTo(-1L)); | ||
assertThat(tracker.getPersistedCheckpoint(), equalTo(1L)); | ||
|
||
tracker.fastForwardProcessedSeqNo(seqNo2); | ||
assertThat(tracker.getProcessedCheckpoint(), equalTo(1L)); | ||
assertThat(tracker.hasProcessed(seqNo1), equalTo(true)); | ||
assertThat(tracker.hasProcessed(seqNo2), equalTo(true)); | ||
|
||
tracker.fastForwardProcessedSeqNo(seqNo1); | ||
assertThat(tracker.getProcessedCheckpoint(), equalTo(1L)); | ||
assertThat(tracker.hasProcessed(between(0, 1)), equalTo(true)); | ||
assertThat(tracker.hasProcessed(atLeast(2)), equalTo(false)); | ||
assertThat(tracker.getMaxSeqNo(), equalTo(1L)); | ||
} | ||
} |