2121import static org .apache .hadoop .hbase .client .trace .hamcrest .SpanDataMatchers .hasParentSpanId ;
2222import static org .apache .hadoop .hbase .io .hfile .CacheConfig .CACHE_DATA_BLOCKS_COMPRESSED_KEY ;
2323import static org .apache .hadoop .hbase .io .hfile .PrefetchExecutor .PREFETCH_DELAY ;
24- import static org .apache .hadoop .hbase .io .hfile .PrefetchExecutor .getComputedPrefetchDelay ;
2524import static org .apache .hadoop .hbase .regionserver .CompactSplit .HBASE_REGION_SERVER_ENABLE_COMPACTION ;
2625import static org .hamcrest .MatcherAssert .assertThat ;
2726import static org .hamcrest .Matchers .allOf ;
@@ -101,7 +100,6 @@ public class TestPrefetch {
101100 private static final int NUM_KV = 1000 ;
102101
103102 private long startTime ;
104- private long endTime ;
105103 private boolean measureTiming ;
106104
107105
@@ -314,11 +312,14 @@ private void readStoreFile(Path storeFilePath,
314312 // if prefetchFutures contains entry (which means it's not cancelled or completed)
315313 // and wait time remaining is below delay expiry watermark, it can be deduced that
316314 // the prefetch is not started yet.
317- assertFalse ("Prefetch Should not start at this point" , reader .prefetchStarted ());
318- setComputeTiming (false );
315+ if (getElapsedTime () >= (conf .getLong (PREFETCH_DELAY , 1000 ))) {
316+ assertTrue ("Prefetch should be started at this point" , reader .prefetchStarted ());
317+ setComputeTiming (false );
318+ } else {
319+ assertFalse ("Prefetch Should not start at this point" , reader .prefetchStarted ());
320+ }
319321 }
320322 }
321- endTimer ();
322323 long offset = 0 ;
323324 while (offset < reader .getTrailer ().getLoadOnOpenDataOffset ()) {
324325 HFileBlock block = readFunction .apply (reader , offset );
@@ -374,7 +375,7 @@ public void testOnConfigurationChange() {
374375 @ Test
375376 public void testPrefetchWithDelay () throws Exception {
376377 PrefetchExecutorNotifier prefetchExecutorNotifier = new PrefetchExecutorNotifier (conf );
377- conf .setInt (PREFETCH_DELAY , 60000 );
378+ conf .setInt (PREFETCH_DELAY , 35000 );
378379 prefetchExecutorNotifier .onConfigurationChange (conf );
379380
380381 HFileContext context = new HFileContextBuilder ().withCompression (Compression .Algorithm .GZ )
@@ -385,10 +386,6 @@ public void testPrefetchWithDelay() throws Exception {
385386 setComputeTiming (true );
386387
387388 readStoreFile (storeFile );
388- //We apply delay variation to the provided delay and used the computed delay while scheduling
389- //Using the computed delay for the comparison
390- assertTrue ("Total execution time is not more than delay duration" ,
391- getElapsedTime () > PrefetchExecutor .getComputedPrefetchDelay ());
392389 resetTiming ();
393390
394391 conf .setInt (PREFETCH_DELAY , 1000 );
@@ -551,7 +548,6 @@ public static KeyValue.Type generateKeyType(Random rand) {
551548
552549 private void resetTiming () {
553550 startTime = 0 ;
554- endTime = 0 ;
555551 measureTiming = false ;
556552 }
557553
@@ -561,13 +557,8 @@ private void startTimer() {
561557 }
562558 }
563559
564- private void endTimer () {
565- if (startTime > 0 )
566- endTime = System .currentTimeMillis ();
567- }
568-
569560 private long getElapsedTime () {
570- return endTime - startTime ;
561+ return System . currentTimeMillis () - startTime ;
571562 }
572563
573564 private void setComputeTiming (boolean status ) {
0 commit comments