|
@@ -30,6 +30,8 @@ import org.apache.hadoop.fs.common.BlockData;
|
|
|
import org.apache.hadoop.fs.common.BufferData;
|
|
|
import org.apache.hadoop.fs.common.ExceptionAsserts;
|
|
|
import org.apache.hadoop.fs.common.ExecutorServiceFuturePool;
|
|
|
+import org.apache.hadoop.fs.s3a.statistics.S3AInputStreamStatistics;
|
|
|
+import org.apache.hadoop.fs.s3a.statistics.impl.EmptyS3AStatisticsContext;
|
|
|
import org.apache.hadoop.test.AbstractHadoopTestBase;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
@@ -41,6 +43,8 @@ public class TestS3CachingBlockManager extends AbstractHadoopTestBase {
|
|
|
|
|
|
private final ExecutorService threadPool = Executors.newFixedThreadPool(4);
|
|
|
private final ExecutorServiceFuturePool futurePool = new ExecutorServiceFuturePool(threadPool);
|
|
|
+ private final S3AInputStreamStatistics streamStatistics =
|
|
|
+ new EmptyS3AStatisticsContext().newInputStreamStatistics();
|
|
|
|
|
|
private final BlockData blockData = new BlockData(FILE_SIZE, BLOCK_SIZE);
|
|
|
|
|
@@ -51,33 +55,35 @@ public class TestS3CachingBlockManager extends AbstractHadoopTestBase {
|
|
|
|
|
|
// Should not throw.
|
|
|
S3CachingBlockManager blockManager =
|
|
|
- new S3CachingBlockManager(futurePool, reader, blockData, POOL_SIZE);
|
|
|
+ new S3CachingBlockManager(futurePool, reader, blockData, POOL_SIZE, streamStatistics);
|
|
|
|
|
|
// Verify it throws correctly.
|
|
|
ExceptionAsserts.assertThrows(
|
|
|
- IllegalArgumentException.class,
|
|
|
- "'futurePool' must not be null",
|
|
|
- () -> new S3CachingBlockManager(null, reader, blockData, POOL_SIZE));
|
|
|
+ NullPointerException.class,
|
|
|
+ () -> new S3CachingBlockManager(null, reader, blockData, POOL_SIZE, streamStatistics));
|
|
|
|
|
|
ExceptionAsserts.assertThrows(
|
|
|
IllegalArgumentException.class,
|
|
|
"'reader' must not be null",
|
|
|
- () -> new S3CachingBlockManager(futurePool, null, blockData, POOL_SIZE));
|
|
|
+ () -> new S3CachingBlockManager(futurePool, null, blockData, POOL_SIZE, streamStatistics));
|
|
|
|
|
|
ExceptionAsserts.assertThrows(
|
|
|
IllegalArgumentException.class,
|
|
|
"'blockData' must not be null",
|
|
|
- () -> new S3CachingBlockManager(futurePool, reader, null, POOL_SIZE));
|
|
|
+ () -> new S3CachingBlockManager(futurePool, reader, null, POOL_SIZE, streamStatistics));
|
|
|
|
|
|
ExceptionAsserts.assertThrows(
|
|
|
IllegalArgumentException.class,
|
|
|
"'bufferPoolSize' must be a positive integer",
|
|
|
- () -> new S3CachingBlockManager(futurePool, reader, blockData, 0));
|
|
|
+ () -> new S3CachingBlockManager(futurePool, reader, blockData, 0, streamStatistics));
|
|
|
|
|
|
ExceptionAsserts.assertThrows(
|
|
|
IllegalArgumentException.class,
|
|
|
"'bufferPoolSize' must be a positive integer",
|
|
|
- () -> new S3CachingBlockManager(futurePool, reader, blockData, -1));
|
|
|
+ () -> new S3CachingBlockManager(futurePool, reader, blockData, -1, streamStatistics));
|
|
|
+
|
|
|
+ ExceptionAsserts.assertThrows(NullPointerException.class,
|
|
|
+ () -> new S3CachingBlockManager(futurePool, reader, blockData, POOL_SIZE, null));
|
|
|
|
|
|
ExceptionAsserts.assertThrows(
|
|
|
IllegalArgumentException.class,
|
|
@@ -108,8 +114,9 @@ public class TestS3CachingBlockManager extends AbstractHadoopTestBase {
|
|
|
ExecutorServiceFuturePool futurePool,
|
|
|
S3Reader reader,
|
|
|
BlockData blockData,
|
|
|
- int bufferPoolSize) {
|
|
|
- super(futurePool, reader, blockData, bufferPoolSize);
|
|
|
+ int bufferPoolSize,
|
|
|
+ S3AInputStreamStatistics streamStatistics) {
|
|
|
+ super(futurePool, reader, blockData, bufferPoolSize, streamStatistics);
|
|
|
}
|
|
|
|
|
|
// If true, forces the next read operation to fail.
|
|
@@ -157,7 +164,7 @@ public class TestS3CachingBlockManager extends AbstractHadoopTestBase {
|
|
|
MockS3File s3File = new MockS3File(FILE_SIZE, true);
|
|
|
S3Reader reader = new S3Reader(s3File);
|
|
|
TestBlockManager blockManager =
|
|
|
- new TestBlockManager(futurePool, reader, blockData, POOL_SIZE);
|
|
|
+ new TestBlockManager(futurePool, reader, blockData, POOL_SIZE, streamStatistics);
|
|
|
|
|
|
for (int b = 0; b < blockData.getNumBlocks(); b++) {
|
|
|
// We simulate caching failure for all even numbered blocks.
|
|
@@ -204,7 +211,7 @@ public class TestS3CachingBlockManager extends AbstractHadoopTestBase {
|
|
|
MockS3File s3File = new MockS3File(FILE_SIZE, false);
|
|
|
S3Reader reader = new S3Reader(s3File);
|
|
|
TestBlockManager blockManager =
|
|
|
- new TestBlockManager(futurePool, reader, blockData, POOL_SIZE);
|
|
|
+ new TestBlockManager(futurePool, reader, blockData, POOL_SIZE, streamStatistics);
|
|
|
assertInitialState(blockManager);
|
|
|
|
|
|
int expectedNumErrors = 0;
|
|
@@ -236,7 +243,7 @@ public class TestS3CachingBlockManager extends AbstractHadoopTestBase {
|
|
|
MockS3File s3File = new MockS3File(FILE_SIZE, false);
|
|
|
S3Reader reader = new S3Reader(s3File);
|
|
|
S3CachingBlockManager blockManager =
|
|
|
- new S3CachingBlockManager(futurePool, reader, blockData, POOL_SIZE);
|
|
|
+ new S3CachingBlockManager(futurePool, reader, blockData, POOL_SIZE, streamStatistics);
|
|
|
assertInitialState(blockManager);
|
|
|
|
|
|
for (int b = 0; b < blockData.getNumBlocks(); b++) {
|
|
@@ -267,7 +274,7 @@ public class TestS3CachingBlockManager extends AbstractHadoopTestBase {
|
|
|
MockS3File s3File = new MockS3File(FILE_SIZE, false);
|
|
|
S3Reader reader = new S3Reader(s3File);
|
|
|
TestBlockManager blockManager =
|
|
|
- new TestBlockManager(futurePool, reader, blockData, POOL_SIZE);
|
|
|
+ new TestBlockManager(futurePool, reader, blockData, POOL_SIZE, streamStatistics);
|
|
|
assertInitialState(blockManager);
|
|
|
|
|
|
int expectedNumErrors = 0;
|