@@ -420,7 +420,12 @@ public void testFindEarliestLastModifiedAge() throws IOException {
420
420
assertThat (Translog .findEarliestLastModifiedAge (fixedTime , readers , w ), equalTo (LongStream .of (periods ).max ().orElse (0L )));
421
421
}
422
422
423
- public void testStats () throws IOException {
423
+ private void waitForPositiveAge () throws Exception {
424
+ final long lastModifiedTime = translog .getCurrent ().getLastModifiedTime ();
425
+ assertBusy (() -> assertThat (System .currentTimeMillis (), greaterThan (lastModifiedTime )));
426
+ }
427
+
428
+ public void testStats () throws Exception {
424
429
// self control cleaning for test
425
430
translog .getDeletionPolicy ().setRetentionSizeInBytes (1024 * 1024 );
426
431
translog .getDeletionPolicy ().setRetentionAgeInMillis (3600 * 1000 );
@@ -433,6 +438,7 @@ public void testStats() throws IOException {
433
438
translog .add (new Translog .Index ("test" , "1" , 0 , primaryTerm .get (), new byte [] { 1 }));
434
439
435
440
{
441
+ waitForPositiveAge ();
436
442
final TranslogStats stats = stats ();
437
443
assertThat (stats .estimatedNumberOfOperations (), equalTo (1 ));
438
444
assertThat (stats .getTranslogSizeInBytes (), equalTo (162L ));
@@ -443,6 +449,7 @@ public void testStats() throws IOException {
443
449
444
450
translog .add (new Translog .Delete ("test" , "2" , 1 , primaryTerm .get (), newUid ("2" )));
445
451
{
452
+ waitForPositiveAge ();
446
453
final TranslogStats stats = stats ();
447
454
assertThat (stats .estimatedNumberOfOperations (), equalTo (2 ));
448
455
assertThat (stats .getTranslogSizeInBytes (), equalTo (210L ));
@@ -453,6 +460,7 @@ public void testStats() throws IOException {
453
460
454
461
translog .add (new Translog .Delete ("test" , "3" , 2 , primaryTerm .get (), newUid ("3" )));
455
462
{
463
+ waitForPositiveAge ();
456
464
final TranslogStats stats = stats ();
457
465
assertThat (stats .estimatedNumberOfOperations (), equalTo (3 ));
458
466
assertThat (stats .getTranslogSizeInBytes (), equalTo (258L ));
@@ -463,6 +471,7 @@ public void testStats() throws IOException {
463
471
464
472
translog .add (new Translog .NoOp (3 , 1 , randomAlphaOfLength (16 )));
465
473
{
474
+ waitForPositiveAge ();
466
475
final TranslogStats stats = stats ();
467
476
assertThat (stats .estimatedNumberOfOperations (), equalTo (4 ));
468
477
assertThat (stats .getTranslogSizeInBytes (), equalTo (300L ));
@@ -473,6 +482,7 @@ public void testStats() throws IOException {
473
482
474
483
translog .rollGeneration ();
475
484
{
485
+ waitForPositiveAge ();
476
486
final TranslogStats stats = stats ();
477
487
assertThat (stats .estimatedNumberOfOperations (), equalTo (4 ));
478
488
assertThat (stats .getTranslogSizeInBytes (), equalTo (355L ));
@@ -510,13 +520,13 @@ public void testStats() throws IOException {
510
520
translog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (randomLongBetween (3 , Long .MAX_VALUE ));
511
521
translog .trimUnreferencedReaders ();
512
522
{
513
- long lastModifiedAge = System . currentTimeMillis () - translog . getCurrent (). getLastModifiedTime ();
523
+ waitForPositiveAge ();
514
524
final TranslogStats stats = stats ();
515
525
assertThat (stats .estimatedNumberOfOperations (), equalTo (4 ));
516
526
assertThat (stats .getTranslogSizeInBytes (), equalTo (355L ));
517
527
assertThat (stats .getUncommittedOperations (), equalTo (0 ));
518
528
assertThat (stats .getUncommittedSizeInBytes (), equalTo (firstOperationPosition ));
519
- assertThat (stats .getEarliestLastModifiedAge (), greaterThanOrEqualTo ( lastModifiedAge ));
529
+ assertThat (stats .getEarliestLastModifiedAge (), greaterThan ( 0L ));
520
530
}
521
531
}
522
532
0 commit comments