@@ -5121,7 +5121,15 @@ public void testShardExposesWriteLoadStats() throws Exception {
51215121 NOOP_GCP_SYNCER ,
51225122 RetentionLeaseSyncer .EMPTY ,
51235123 EMPTY_EVENT_LISTENER ,
5124- fakeClock
5124+ fakeClock ,
5125+ // Use a listener to advance the fake clock once per indexing operation:
5126+ new IndexingOperationListener () {
5127+ @ Override
5128+ public Engine .Index preIndex (ShardId shardId , Engine .Index operation ) {
5129+ fakeClock .advance ();
5130+ return IndexingOperationListener .super .preIndex (shardId , operation );
5131+ }
5132+ }
51255133 );
51265134
51275135 // Now simulate that each operation takes 1 minute to complete.
@@ -5229,24 +5237,19 @@ public void indexTranslogOperations(
52295237
52305238 static class FakeClock implements LongSupplier {
52315239 private final AtomicLong currentRelativeTime = new AtomicLong ();
5232- private final AtomicInteger tick = new AtomicInteger ();
5233- private volatile TimeValue elapsedTimePerPairOfQueries = TimeValue .ZERO ;
5240+ private volatile TimeValue simulatedElapsedRelativeTime = TimeValue .ZERO ;
52345241
52355242 @ Override
52365243 public long getAsLong () {
5237- // Since the clock is checked at the beginning and at the end of
5238- // the indexing op, just increase the current relative time at the
5239- // end.
5240- if (tick .getAndIncrement () % 2 == 0 ) {
5241- return currentRelativeTime .get ();
5242- } else {
5243- return currentRelativeTime .addAndGet (elapsedTimePerPairOfQueries .nanos ());
5244- }
5244+ return currentRelativeTime .get ();
5245+ }
5246+
5247+ void setSimulatedElapsedRelativeTime (TimeValue simulatedElapsedRelativeTime ) {
5248+ this .simulatedElapsedRelativeTime = simulatedElapsedRelativeTime ;
52455249 }
52465250
5247- void setSimulatedElapsedRelativeTime (TimeValue elapsedTimePerPairOfQueries ) {
5248- tick .set (0 );
5249- this .elapsedTimePerPairOfQueries = elapsedTimePerPairOfQueries ;
5251+ public void advance () {
5252+ currentRelativeTime .addAndGet (simulatedElapsedRelativeTime .nanos ());
52505253 }
52515254 }
52525255
0 commit comments