Skip to content

Commit 5ea2cae

Browse files
committed
fix test
1 parent 2c0b257 commit 5ea2cae

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
import java.util.concurrent.atomic.AtomicReference;
173173
import java.util.function.BiFunction;
174174
import java.util.function.Function;
175+
import java.util.function.IntSupplier;
175176
import java.util.function.LongSupplier;
176177
import java.util.function.Supplier;
177178
import java.util.function.ToLongBiFunction;
@@ -4695,6 +4696,10 @@ public void testShouldPeriodicallyFlush() throws Exception {
46954696
assertThat("Empty engine does not need flushing", engine.shouldPeriodicallyFlush(), equalTo(false));
46964697
// A new engine may have more than one empty translog files - the test should account this extra.
46974698
final Translog translog = engine.getTranslog();
4699+
final IntSupplier uncommittedTranslogOperationsSinceLastCommit = () -> {
4700+
long localCheckpoint = Long.parseLong(engine.getLastCommittedSegmentInfos().userData.get(SequenceNumbers.LOCAL_CHECKPOINT_KEY));
4701+
return translog.totalOperationsByMinGen(translog.getMinGenerationForSeqNo(localCheckpoint + 1).translogFileGeneration);
4702+
};
46984703
final long extraTranslogSizeInNewEngine =
46994704
engine.getTranslog().stats().getUncommittedSizeInBytes() - Translog.DEFAULT_HEADER_SIZE_IN_BYTES;
47004705
int numDocs = between(10, 100);
@@ -4712,10 +4717,10 @@ public void testShouldPeriodicallyFlush() throws Exception {
47124717
.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), flushThreshold + "b")).build();
47134718
indexSettings.updateIndexMetaData(indexMetaData);
47144719
engine.onSettingsChanged();
4715-
assertThat(engine.getTranslog().stats().getUncommittedOperations(), equalTo(numDocs));
4720+
assertThat(uncommittedTranslogOperationsSinceLastCommit.getAsInt(), equalTo(numDocs));
47164721
assertThat(engine.shouldPeriodicallyFlush(), equalTo(true));
47174722
engine.flush();
4718-
assertThat(engine.getTranslog().stats().getUncommittedOperations(), equalTo(0));
4723+
assertThat(uncommittedTranslogOperationsSinceLastCommit.getAsInt(), equalTo(0));
47194724
// Stale operations skipped by Lucene but added to translog - still able to flush
47204725
for (int id = 0; id < numDocs; id++) {
47214726
final ParsedDocument doc =
@@ -4724,11 +4729,11 @@ public void testShouldPeriodicallyFlush() throws Exception {
47244729
assertThat(result.isCreated(), equalTo(false));
47254730
}
47264731
SegmentInfos lastCommitInfo = engine.getLastCommittedSegmentInfos();
4727-
assertThat(engine.getTranslog().stats().getUncommittedOperations(), equalTo(numDocs));
4732+
assertThat(uncommittedTranslogOperationsSinceLastCommit.getAsInt(), equalTo(numDocs));
47284733
assertThat(engine.shouldPeriodicallyFlush(), equalTo(true));
47294734
engine.flush(false, false);
47304735
assertThat(engine.getLastCommittedSegmentInfos(), not(sameInstance(lastCommitInfo)));
4731-
assertThat(engine.getTranslog().stats().getUncommittedOperations(), equalTo(0));
4736+
assertThat(uncommittedTranslogOperationsSinceLastCommit.getAsInt(), equalTo(0));
47324737
// If the new index commit still points to the same translog generation as the current index commit,
47334738
// we should not enable the periodically flush condition; otherwise we can get into an infinite loop of flushes.
47344739
generateNewSeqNo(engine); // create a gap here

server/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ public void testRollbackOnPromotion() throws Exception {
734734
shards.assertAllEqual(initDocs + inFlightOpsOnNewPrimary + moreDocsAfterRollback);
735735
done.set(true);
736736
thread.join();
737-
737+
shards.syncGlobalCheckpoint();
738738
for (IndexShard shard : shards) {
739739
shard.flush(new FlushRequest().force(true).waitIfOngoing(true));
740740
assertThat(shard.translogStats().getUncommittedOperations(), equalTo(0));

0 commit comments

Comments
 (0)