|
@@ -20,7 +20,6 @@ package org.apache.hadoop.hdfs.server.datanode;
|
|
|
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
-import static org.junit.Assume.assumeTrue;
|
|
|
import static org.mockito.Matchers.any;
|
|
|
import static org.mockito.Matchers.anyInt;
|
|
|
import static org.mockito.Matchers.anyLong;
|
|
@@ -68,6 +67,7 @@ import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.StorageReport;
|
|
|
+import org.apache.hadoop.io.IOUtils;
|
|
|
import org.apache.hadoop.io.nativeio.NativeIO;
|
|
|
import org.apache.hadoop.io.nativeio.NativeIO.POSIX.CacheManipulator;
|
|
|
import org.apache.hadoop.io.nativeio.NativeIO.POSIX.NoMlockCacheManipulator;
|
|
@@ -114,7 +114,6 @@ public class TestFsDatasetCache {
|
|
|
|
|
|
@Before
|
|
|
public void setUp() throws Exception {
|
|
|
- assumeTrue(!Path.WINDOWS);
|
|
|
conf = new HdfsConfiguration();
|
|
|
conf.setLong(
|
|
|
DFSConfigKeys.DFS_NAMENODE_PATH_BASED_CACHE_REFRESH_INTERVAL_MS, 100);
|
|
@@ -143,6 +142,9 @@ public class TestFsDatasetCache {
|
|
|
|
|
|
@After
|
|
|
public void tearDown() throws Exception {
|
|
|
+ // Verify that each test uncached whatever it cached. This cleanup is
|
|
|
+ // required so that file descriptors are not leaked across tests.
|
|
|
+ DFSTestUtil.verifyExpectedCacheUsage(0, 0, fsd);
|
|
|
if (fs != null) {
|
|
|
fs.close();
|
|
|
}
|
|
@@ -205,9 +207,16 @@ public class TestFsDatasetCache {
|
|
|
String bpid = loc.getLocatedBlock().getBlock().getBlockPoolId();
|
|
|
Block block = loc.getLocatedBlock().getBlock().getLocalBlock();
|
|
|
ExtendedBlock extBlock = new ExtendedBlock(bpid, block);
|
|
|
- FileChannel blockChannel =
|
|
|
- ((FileInputStream)fsd.getBlockInputStream(extBlock, 0)).getChannel();
|
|
|
- sizes[i] = blockChannel.size();
|
|
|
+ FileInputStream blockInputStream = null;
|
|
|
+ FileChannel blockChannel = null;
|
|
|
+ try {
|
|
|
+ blockInputStream =
|
|
|
+ (FileInputStream)fsd.getBlockInputStream(extBlock, 0);
|
|
|
+ blockChannel = blockInputStream.getChannel();
|
|
|
+ sizes[i] = blockChannel.size();
|
|
|
+ } finally {
|
|
|
+ IOUtils.cleanup(LOG, blockChannel, blockInputStream);
|
|
|
+ }
|
|
|
}
|
|
|
return sizes;
|
|
|
}
|
|
@@ -571,5 +580,7 @@ public class TestFsDatasetCache {
|
|
|
return true;
|
|
|
}
|
|
|
}, 1000, 30000);
|
|
|
+
|
|
|
+ dfs.removeCacheDirective(shortCacheDirectiveId);
|
|
|
}
|
|
|
}
|