|
@@ -82,6 +82,12 @@ public class TestAbfsInputStream extends
|
|
|
REDUCED_READ_BUFFER_AGE_THRESHOLD * 10; // 30 sec
|
|
|
private static final int ALWAYS_READ_BUFFER_SIZE_TEST_FILE_SIZE = 16 * ONE_MB;
|
|
|
|
|
|
+ @Override
|
|
|
+ public void teardown() throws Exception {
|
|
|
+ super.teardown();
|
|
|
+ ReadBufferManager.getBufferManager().testResetReadBufferManager();
|
|
|
+ }
|
|
|
+
|
|
|
private AbfsRestOperation getMockRestOp() {
|
|
|
AbfsRestOperation op = mock(AbfsRestOperation.class);
|
|
|
AbfsHttpOperation httpOp = mock(AbfsHttpOperation.class);
|
|
@@ -106,7 +112,6 @@ public class TestAbfsInputStream extends
|
|
|
private AbfsInputStream getAbfsInputStream(AbfsClient mockAbfsClient,
|
|
|
String fileName) throws IOException {
|
|
|
AbfsInputStreamContext inputStreamContext = new AbfsInputStreamContext(-1);
|
|
|
- inputStreamContext.isReadAheadEnabled(true);
|
|
|
// Create AbfsInputStream with the client instance
|
|
|
AbfsInputStream inputStream = new AbfsInputStream(
|
|
|
mockAbfsClient,
|
|
@@ -132,7 +137,6 @@ public class TestAbfsInputStream extends
|
|
|
boolean alwaysReadBufferSize,
|
|
|
int readAheadBlockSize) throws IOException {
|
|
|
AbfsInputStreamContext inputStreamContext = new AbfsInputStreamContext(-1);
|
|
|
- inputStreamContext.isReadAheadEnabled(true);
|
|
|
// Create AbfsInputStream with the client instance
|
|
|
AbfsInputStream inputStream = new AbfsInputStream(
|
|
|
abfsClient,
|
|
@@ -495,6 +499,69 @@ public class TestAbfsInputStream extends
|
|
|
checkEvictedStatus(inputStream, 0, true);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * This test expects InProgressList is not purged by the inputStream close.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testStreamPurgeDuringReadAheadCallExecuting() throws Exception {
|
|
|
+ AbfsClient client = getMockAbfsClient();
|
|
|
+ AbfsRestOperation successOp = getMockRestOp();
|
|
|
+ final Long serverCommunicationMockLatency = 3_000L;
|
|
|
+ final Long readBufferTransferToInProgressProbableTime = 1_000L;
|
|
|
+ final Integer readBufferQueuedCount = 3;
|
|
|
+
|
|
|
+ Mockito.doAnswer(invocationOnMock -> {
|
|
|
+ //sleeping thread to mock the network latency from client to backend.
|
|
|
+ Thread.sleep(serverCommunicationMockLatency);
|
|
|
+ return successOp;
|
|
|
+ })
|
|
|
+ .when(client)
|
|
|
+ .read(any(String.class), any(Long.class), any(byte[].class),
|
|
|
+ any(Integer.class), any(Integer.class), any(String.class),
|
|
|
+ any(String.class), any(TracingContext.class));
|
|
|
+
|
|
|
+ final ReadBufferManager readBufferManager
|
|
|
+ = ReadBufferManager.getBufferManager();
|
|
|
+
|
|
|
+ final int readBufferTotal = readBufferManager.getNumBuffers();
|
|
|
+ final int expectedFreeListBufferCount = readBufferTotal
|
|
|
+ - readBufferQueuedCount;
|
|
|
+
|
|
|
+ try (AbfsInputStream inputStream = getAbfsInputStream(client,
|
|
|
+ "testSuccessfulReadAhead.txt")) {
|
|
|
+ // As this is try-with-resources block, the close() method of the created
|
|
|
+ // abfsInputStream object shall be called on the end of the block.
|
|
|
+ queueReadAheads(inputStream);
|
|
|
+
|
|
|
+ //Sleeping to give ReadBufferWorker to pick the readBuffers for processing.
|
|
|
+ Thread.sleep(readBufferTransferToInProgressProbableTime);
|
|
|
+
|
|
|
+ Assertions.assertThat(readBufferManager.getInProgressCopiedList())
|
|
|
+ .describedAs(String.format("InProgressList should have %d elements",
|
|
|
+ readBufferQueuedCount))
|
|
|
+ .hasSize(readBufferQueuedCount);
|
|
|
+ Assertions.assertThat(readBufferManager.getFreeListCopy())
|
|
|
+ .describedAs(String.format("FreeList should have %d elements",
|
|
|
+ expectedFreeListBufferCount))
|
|
|
+ .hasSize(expectedFreeListBufferCount);
|
|
|
+ Assertions.assertThat(readBufferManager.getCompletedReadListCopy())
|
|
|
+ .describedAs("CompletedList should have 0 elements")
|
|
|
+ .hasSize(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ Assertions.assertThat(readBufferManager.getInProgressCopiedList())
|
|
|
+ .describedAs(String.format("InProgressList should have %d elements",
|
|
|
+ readBufferQueuedCount))
|
|
|
+ .hasSize(readBufferQueuedCount);
|
|
|
+ Assertions.assertThat(readBufferManager.getFreeListCopy())
|
|
|
+ .describedAs(String.format("FreeList should have %d elements",
|
|
|
+ expectedFreeListBufferCount))
|
|
|
+ .hasSize(expectedFreeListBufferCount);
|
|
|
+ Assertions.assertThat(readBufferManager.getCompletedReadListCopy())
|
|
|
+ .describedAs("CompletedList should have 0 elements")
|
|
|
+ .hasSize(0);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* This test expects ReadAheadManager to throw exception if the read ahead
|
|
|
* thread had failed within the last thresholdAgeMilliseconds.
|