@@ -41,9 +41,6 @@ public class ITestAbfsInputStreamStatistics
4141 private static final int ONE_MB = 1024 * 1024 ;
4242 private static final int ONE_KB = 1024 ;
4343 private static final int CUSTOM_BLOCK_BUFFER_SIZE = 4 * 1024 ;
44- private static final int CUSTOM_READ_AHEAD_BUFFER_SIZE = 8 * CUSTOM_BLOCK_BUFFER_SIZE ;
45- private static final int THREAD_SLEEP_10_SECONDS = 10 ;
46- private static final int TIMEOUT_30_SECONDS = 30000 ;
4744 private byte [] defBuffer = new byte [ONE_MB ];
4845
4946 public ITestAbfsInputStreamStatistics () throws Exception {
@@ -295,8 +292,8 @@ public void testWithNullStreamStatistics() throws IOException {
295292 /**
296293 * Testing readAhead counters in AbfsInputStream with 30 seconds timeout.
297294 */
298- @ Test ( timeout = TIMEOUT_30_SECONDS )
299- public void testReadAheadCounters () throws IOException , InterruptedException {
295+ @ Test
296+ public void testReadAheadCounters () throws IOException {
300297 describe ("Test to check correct values for readAhead counters in "
301298 + "AbfsInputStream" );
302299
@@ -334,46 +331,35 @@ public void testReadAheadCounters() throws IOException, InterruptedException {
334331 AbfsInputStreamStatisticsImpl stats =
335332 (AbfsInputStreamStatisticsImpl ) in .getStreamStatistics ();
336333
337- /*
338- * Since, readAhead is done in background threads. Sometimes, the
339- * threads aren't finished in the background and could result in
340- * inaccurate results. So, we wait till we have the accurate values
341- * with a limit of 30 seconds as that's when the test times out.
342- *
343- */
344- while (stats .getRemoteBytesRead () < CUSTOM_READ_AHEAD_BUFFER_SIZE
345- || stats .getReadAheadBytesRead () < CUSTOM_BLOCK_BUFFER_SIZE ) {
346- Thread .sleep (THREAD_SLEEP_10_SECONDS );
347- }
348-
349334 /*
350335 * Verifying the counter values of readAheadBytesRead and remoteBytesRead.
351336 *
352337 * readAheadBytesRead : Since, we read 1KBs 5 times, that means we go
353338 * from 0 to 5KB in the file. The bufferSize is set to 4KB, and since
354339 * we have 8 blocks of readAhead buffer. We would have 8 blocks of 4KB
355340 * buffer. Our read is till 5KB, hence readAhead would ideally read 2
356- * blocks of 4KB which is equal to 8KB. But, sometimes to get more than
357- * one block from readAhead buffer we might have to wait for background
341+ * blocks of 4KB which is equal to 8KB. But, sometimes to get blocks
342+ * from readAhead buffer we might have to wait for background
358343 * threads to fill the buffer and hence we might do remote read which
359- * would be faster. Therefore, readAheadBytesRead would be equal to or
360- * greater than 4KB .
344+ * would be faster. Therefore, readAheadBytesRead would be greater than
345+ * or equal to the value of bytesFromReadAhead at the point we measure it .
361346 *
362347 * remoteBytesRead : Since, the bufferSize is set to 4KB and the number
363348 * of blocks or readAheadQueueDepth is equal to 8. We would read 8 * 4
364349 * KB buffer on the first read, which is equal to 32KB. But, if we are not
365350 * able to read some bytes that were in the buffer after doing
366351 * readAhead, we might use remote read again. Thus, the bytes read
367- * remotely could also be greater than 32Kb.
352+ * remotely would be greater than or equal to the bytesFromRemoteRead
353+ * value that we measure at some point of the operation.
368354 *
369355 */
370356 Assertions .assertThat (stats .getReadAheadBytesRead ()).describedAs (
371357 "Mismatch in readAheadBytesRead counter value" )
372- .isGreaterThanOrEqualTo (CUSTOM_BLOCK_BUFFER_SIZE );
358+ .isGreaterThanOrEqualTo (in . getBytesFromReadAhead () );
373359
374360 Assertions .assertThat (stats .getRemoteBytesRead ()).describedAs (
375361 "Mismatch in remoteBytesRead counter value" )
376- .isGreaterThanOrEqualTo (CUSTOM_READ_AHEAD_BUFFER_SIZE );
362+ .isGreaterThanOrEqualTo (in . getBytesFromRemoteRead () );
377363
378364 } finally {
379365 IOUtils .cleanupWithLogger (LOG , out , in );
0 commit comments