From cc674e7d74d7db37a8915575017f9151580e300c Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Sun, 13 Dec 2020 09:23:07 -0500 Subject: [PATCH] Fix TranslogTests#testStats (#66227) If creating the latest translog file and retrieving a translog stats happen within the same millisecond, then the earliestLastModifiedAge will be zero. Closes #66092 --- .../java/org/elasticsearch/index/translog/TranslogTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index ee381a428b3c..cb88771dfb04 100644 --- a/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java @@ -493,12 +493,13 @@ public void testStats() throws IOException { translog.getDeletionPolicy().setLocalCheckpointOfSafeCommit(randomLongBetween(3, Long.MAX_VALUE)); translog.trimUnreferencedReaders(); { + long lastModifiedAge = System.currentTimeMillis() - translog.getCurrent().getLastModifiedTime(); final TranslogStats stats = stats(); assertThat(stats.estimatedNumberOfOperations(), equalTo(4)); assertThat(stats.getTranslogSizeInBytes(), equalTo(355L)); assertThat(stats.getUncommittedOperations(), equalTo(0)); assertThat(stats.getUncommittedSizeInBytes(), equalTo(firstOperationPosition)); - assertThat(stats.getEarliestLastModifiedAge(), greaterThan(0L)); + assertThat(stats.getEarliestLastModifiedAge(), greaterThanOrEqualTo(lastModifiedAge)); } }