Skip to content

Commit

Permalink
Fix TranslogTests#testStats (#55085)
Browse files Browse the repository at this point in the history
This test failed because it was executed too fast :D. If creating the 
first translog generation and checking the translog stats happen within
the same second, then the earliestLastModifiedAge will be zero.

Closes #55064
  • Loading branch information
dnhatn committed Apr 11, 2020
1 parent af58f29 commit 521ba9b
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ public void testFindEarliestLastModifiedAge() throws IOException {
}

public void testStats() throws IOException {
assertThat(translog.getCurrent().getLastModifiedTime(), lessThanOrEqualTo(System.currentTimeMillis()));
long lastModifiedAge = System.currentTimeMillis() - translog.getCurrent().getLastModifiedTime();
// self control cleaning for test
translog.getDeletionPolicy().setRetentionSizeInBytes(1024 * 1024);
translog.getDeletionPolicy().setRetentionAgeInMillis(3600 * 1000);
Expand All @@ -436,7 +438,7 @@ public void testStats() throws IOException {
assertThat(stats.getTranslogSizeInBytes(), equalTo(164L));
assertThat(stats.getUncommittedOperations(), equalTo(1));
assertThat(stats.getUncommittedSizeInBytes(), equalTo(164L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThanOrEqualTo(lastModifiedAge));
}

translog.add(new Translog.Delete("test", "2", 1, primaryTerm.get(), newUid("2")));
Expand All @@ -446,7 +448,7 @@ public void testStats() throws IOException {
assertThat(stats.getTranslogSizeInBytes(), equalTo(213L));
assertThat(stats.getUncommittedOperations(), equalTo(2));
assertThat(stats.getUncommittedSizeInBytes(), equalTo(213L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThanOrEqualTo(lastModifiedAge));
}

translog.add(new Translog.Delete("test", "3", 2, primaryTerm.get(), newUid("3")));
Expand All @@ -456,7 +458,7 @@ public void testStats() throws IOException {
assertThat(stats.getTranslogSizeInBytes(), equalTo(262L));
assertThat(stats.getUncommittedOperations(), equalTo(3));
assertThat(stats.getUncommittedSizeInBytes(), equalTo(262L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThanOrEqualTo(lastModifiedAge));
}

translog.add(new Translog.NoOp(3, 1, randomAlphaOfLength(16)));
Expand All @@ -466,7 +468,7 @@ public void testStats() throws IOException {
assertThat(stats.getTranslogSizeInBytes(), equalTo(304L));
assertThat(stats.getUncommittedOperations(), equalTo(4));
assertThat(stats.getUncommittedSizeInBytes(), equalTo(304L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThanOrEqualTo(lastModifiedAge));
}

final long expectedSizeInBytes = 359L;
Expand All @@ -477,7 +479,7 @@ public void testStats() throws IOException {
assertThat(stats.getTranslogSizeInBytes(), equalTo(expectedSizeInBytes));
assertThat(stats.getUncommittedOperations(), equalTo(4));
assertThat(stats.getUncommittedSizeInBytes(), equalTo(expectedSizeInBytes));
assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThanOrEqualTo(lastModifiedAge));
}

{
Expand Down Expand Up @@ -507,7 +509,7 @@ public void testStats() throws IOException {
assertThat(stats.getTranslogSizeInBytes(), equalTo(expectedSizeInBytes));
assertThat(stats.getUncommittedOperations(), equalTo(0));
assertThat(stats.getUncommittedSizeInBytes(), equalTo(firstOperationPosition));
assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L));
assertThat(stats.getEarliestLastModifiedAge(), greaterThanOrEqualTo(lastModifiedAge));
}
}

Expand Down

0 comments on commit 521ba9b

Please sign in to comment.