Skip to content

Commit 22ad52a

Browse files
committed
TEST: Adjust translog size assumption in new engine
A new engine now can have more than one empty translog since #28676. This cause #testShouldPeriodicallyFlush failed because in the test we asssume an engine should have one empty translog. This commit takes into account the extra translog size of a new engine.
1 parent 2f21dc7 commit 22ad52a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -4251,13 +4251,16 @@ public void testCleanupCommitsWhenReleaseSnapshot() throws Exception {
42514251

42524252
public void testShouldPeriodicallyFlush() throws Exception {
42534253
assertThat("Empty engine does not need flushing", engine.shouldPeriodicallyFlush(), equalTo(false));
4254+
// A new engine may have more than one empty translog files - the test should account this extra.
4255+
final long extraTranslogSizeInNewEngine = engine.getTranslog().uncommittedSizeInBytes() - Translog.DEFAULT_HEADER_SIZE_IN_BYTES;
42544256
int numDocs = between(10, 100);
42554257
for (int id = 0; id < numDocs; id++) {
42564258
final ParsedDocument doc = testParsedDocument(Integer.toString(id), null, testDocumentWithTextField(), SOURCE, null);
42574259
engine.index(indexForDoc(doc));
42584260
}
42594261
assertThat("Not exceeded translog flush threshold yet", engine.shouldPeriodicallyFlush(), equalTo(false));
4260-
long flushThreshold = RandomNumbers.randomLongBetween(random(), 100, engine.getTranslog().uncommittedSizeInBytes());
4262+
long flushThreshold = RandomNumbers.randomLongBetween(random(), 100,
4263+
engine.getTranslog().uncommittedSizeInBytes() - extraTranslogSizeInNewEngine);
42614264
final IndexSettings indexSettings = engine.config().getIndexSettings();
42624265
final IndexMetaData indexMetaData = IndexMetaData.builder(indexSettings.getIndexMetaData())
42634266
.settings(Settings.builder().put(indexSettings.getSettings())

0 commit comments

Comments
 (0)