@@ -446,17 +446,23 @@ public void testFindEarliestLastModifiedAge() throws IOException {
446
446
assertThat (Translog .findEarliestLastModifiedAge (fixedTime , readers , w ), equalTo (LongStream .of (periods ).max ().orElse (0L )));
447
447
}
448
448
449
- public void testStats () throws IOException {
449
+ private void waitForPositiveAge () throws Exception {
450
+ final var lastModifiedTime = translog .getCurrent ().getLastModifiedTime ();
451
+ assertBusy (() -> assertThat (System .currentTimeMillis (), greaterThan (lastModifiedTime )));
452
+ }
453
+
454
+ public void testStats () throws Exception {
450
455
// self control cleaning for test
451
456
final long firstOperationPosition = translog .getFirstOperationPosition ();
452
457
{
453
458
final TranslogStats stats = stats ();
454
459
assertThat (stats .estimatedNumberOfOperations (), equalTo (0 ));
455
460
}
456
461
assertThat ((int ) firstOperationPosition , greaterThan (CodecUtil .headerLength (TranslogHeader .TRANSLOG_CODEC )));
457
- translog .add (new Translog .Index ("1" , 0 , primaryTerm .get (), new byte [] { 1 }));
458
462
463
+ translog .add (new Translog .Index ("1" , 0 , primaryTerm .get (), new byte [] { 1 }));
459
464
{
465
+ waitForPositiveAge ();
460
466
final TranslogStats stats = stats ();
461
467
assertThat (stats .estimatedNumberOfOperations (), equalTo (1 ));
462
468
assertThat (stats .getTranslogSizeInBytes (), equalTo (157L ));
@@ -467,6 +473,7 @@ public void testStats() throws IOException {
467
473
468
474
translog .add (new Translog .Delete ("2" , 1 , primaryTerm .get ()));
469
475
{
476
+ waitForPositiveAge ();
470
477
final TranslogStats stats = stats ();
471
478
assertThat (stats .estimatedNumberOfOperations (), equalTo (2 ));
472
479
assertThat (stats .getTranslogSizeInBytes (), equalTo (193L ));
@@ -477,6 +484,7 @@ public void testStats() throws IOException {
477
484
478
485
translog .add (new Translog .Delete ("3" , 2 , primaryTerm .get ()));
479
486
{
487
+ waitForPositiveAge ();
480
488
final TranslogStats stats = stats ();
481
489
assertThat (stats .estimatedNumberOfOperations (), equalTo (3 ));
482
490
assertThat (stats .getTranslogSizeInBytes (), equalTo (229L ));
@@ -487,6 +495,7 @@ public void testStats() throws IOException {
487
495
488
496
translog .add (new Translog .NoOp (3 , 1 , randomAlphaOfLength (16 )));
489
497
{
498
+ waitForPositiveAge ();
490
499
final TranslogStats stats = stats ();
491
500
assertThat (stats .estimatedNumberOfOperations (), equalTo (4 ));
492
501
assertThat (stats .getTranslogSizeInBytes (), equalTo (271L ));
@@ -497,6 +506,7 @@ public void testStats() throws IOException {
497
506
498
507
translog .rollGeneration ();
499
508
{
509
+ waitForPositiveAge ();
500
510
final TranslogStats stats = stats ();
501
511
assertThat (stats .estimatedNumberOfOperations (), equalTo (4 ));
502
512
assertThat (stats .getTranslogSizeInBytes (), equalTo (326L ));
@@ -532,13 +542,13 @@ public void testStats() throws IOException {
532
542
translog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (randomLongBetween (3 , Long .MAX_VALUE ));
533
543
translog .trimUnreferencedReaders ();
534
544
{
535
- long lastModifiedAge = System . currentTimeMillis () - translog . getCurrent (). getLastModifiedTime ();
545
+ waitForPositiveAge ();
536
546
final TranslogStats stats = stats ();
537
547
assertThat (stats .estimatedNumberOfOperations (), equalTo (0 ));
538
548
assertThat (stats .getTranslogSizeInBytes (), equalTo (firstOperationPosition ));
539
549
assertThat (stats .getUncommittedOperations (), equalTo (0 ));
540
550
assertThat (stats .getUncommittedSizeInBytes (), equalTo (firstOperationPosition ));
541
- assertThat (stats .getEarliestLastModifiedAge (), greaterThanOrEqualTo ( lastModifiedAge ));
551
+ assertThat (stats .getEarliestLastModifiedAge (), greaterThan ( 0L ));
542
552
}
543
553
}
544
554
0 commit comments