|
@@ -27,6 +27,7 @@ import java.util.List;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
import java.util.Map.Entry;
|
|
|
|
+import java.util.Random;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.BlockLocation;
|
|
import org.apache.hadoop.fs.BlockLocation;
|
|
@@ -36,9 +37,11 @@ import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystemTestHelper;
|
|
import org.apache.hadoop.fs.FileSystemTestHelper;
|
|
import org.apache.hadoop.fs.FsConstants;
|
|
import org.apache.hadoop.fs.FsConstants;
|
|
import org.apache.hadoop.fs.FsStatus;
|
|
import org.apache.hadoop.fs.FsStatus;
|
|
|
|
+import org.apache.hadoop.fs.LocalFileSystem;
|
|
import org.apache.hadoop.fs.LocatedFileStatus;
|
|
import org.apache.hadoop.fs.LocatedFileStatus;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.RemoteIterator;
|
|
import org.apache.hadoop.fs.RemoteIterator;
|
|
|
|
+import org.apache.hadoop.fs.TestFileUtil;
|
|
import org.apache.hadoop.fs.Trash;
|
|
import org.apache.hadoop.fs.Trash;
|
|
import org.apache.hadoop.fs.UnsupportedFileSystemException;
|
|
import org.apache.hadoop.fs.UnsupportedFileSystemException;
|
|
import org.apache.hadoop.fs.contract.ContractTestUtils;
|
|
import org.apache.hadoop.fs.contract.ContractTestUtils;
|
|
@@ -64,6 +67,7 @@ import org.junit.Assert;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
+import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains;
|
|
import static org.hamcrest.CoreMatchers.containsString;
|
|
import static org.hamcrest.CoreMatchers.containsString;
|
|
import static org.junit.Assert.*;
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
@@ -1267,4 +1271,96 @@ abstract public class ViewFileSystemBaseTest {
|
|
containsString("File does not exist:"));
|
|
containsString("File does not exist:"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testViewFileSystemInnerCache() throws Exception {
|
|
|
|
+ ViewFileSystem.InnerCache cache = new ViewFileSystem.InnerCache();
|
|
|
|
+ FileSystem fs = cache.get(fsTarget.getUri(), conf);
|
|
|
|
+
|
|
|
|
+ // InnerCache caches filesystem.
|
|
|
|
+ assertSame(fs, cache.get(fsTarget.getUri(), conf));
|
|
|
|
+
|
|
|
|
+ // InnerCache and FileSystem.CACHE are independent.
|
|
|
|
+ assertNotSame(fs, FileSystem.get(fsTarget.getUri(), conf));
|
|
|
|
+
|
|
|
|
+ // close InnerCache.
|
|
|
|
+ cache.closeAll();
|
|
|
|
+ try {
|
|
|
|
+ fs.exists(new Path("/"));
|
|
|
|
+ if (!(fs instanceof LocalFileSystem)) {
|
|
|
|
+ // Ignore LocalFileSystem because it can still be used after close.
|
|
|
|
+ fail("Expect Filesystem closed exception");
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ assertExceptionContains("Filesystem closed", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testCloseChildrenFileSystem() throws Exception {
|
|
|
|
+ final String clusterName = "cluster" + new Random().nextInt();
|
|
|
|
+ Configuration config = new Configuration(conf);
|
|
|
|
+ ConfigUtil.addLink(config, clusterName, "/user",
|
|
|
|
+ new Path(targetTestRoot, "user").toUri());
|
|
|
|
+ config.setBoolean("fs.viewfs.impl.disable.cache", false);
|
|
|
|
+ URI uri = new URI("viewfs://" + clusterName + "/");
|
|
|
|
+
|
|
|
|
+ ViewFileSystem viewFs = (ViewFileSystem) FileSystem.get(uri, config);
|
|
|
|
+ assertTrue("viewfs should have at least one child fs.",
|
|
|
|
+ viewFs.getChildFileSystems().length > 0);
|
|
|
|
+ // viewFs is cached in FileSystem.CACHE
|
|
|
|
+ assertSame(viewFs, FileSystem.get(uri, config));
|
|
|
|
+
|
|
|
|
+ // child fs is not cached in FileSystem.CACHE
|
|
|
|
+ FileSystem child = viewFs.getChildFileSystems()[0];
|
|
|
|
+ assertNotSame(child, FileSystem.get(child.getUri(), config));
|
|
|
|
+
|
|
|
|
+ viewFs.close();
|
|
|
|
+ for (FileSystem childfs : viewFs.getChildFileSystems()) {
|
|
|
|
+ try {
|
|
|
|
+ childfs.exists(new Path("/"));
|
|
|
|
+ if (!(childfs instanceof LocalFileSystem)) {
|
|
|
|
+ // Ignore LocalFileSystem because it can still be used after close.
|
|
|
|
+ fail("Expect Filesystem closed exception");
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ assertExceptionContains("Filesystem closed", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testChildrenFileSystemLeak() throws Exception {
|
|
|
|
+ final String clusterName = "cluster" + new Random().nextInt();
|
|
|
|
+ Configuration config = new Configuration(conf);
|
|
|
|
+ ConfigUtil.addLink(config, clusterName, "/user",
|
|
|
|
+ new Path(targetTestRoot, "user").toUri());
|
|
|
|
+
|
|
|
|
+ final int cacheSize = TestFileUtil.getCacheSize();
|
|
|
|
+ ViewFileSystem viewFs = (ViewFileSystem) FileSystem
|
|
|
|
+ .get(new URI("viewfs://" + clusterName + "/"), config);
|
|
|
|
+ assertEquals(cacheSize + 1, TestFileUtil.getCacheSize());
|
|
|
|
+ viewFs.close();
|
|
|
|
+ assertEquals(cacheSize, TestFileUtil.getCacheSize());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testDeleteOnExit() throws Exception {
|
|
|
|
+ final String clusterName = "cluster" + new Random().nextInt();
|
|
|
|
+ Configuration config = new Configuration(conf);
|
|
|
|
+ ConfigUtil.addLink(config, clusterName, "/user",
|
|
|
|
+ new Path(targetTestRoot, "user").toUri());
|
|
|
|
+
|
|
|
|
+ Path testDir = new Path("/user/testDeleteOnExit");
|
|
|
|
+ Path realTestPath = new Path(targetTestRoot, "user/testDeleteOnExit");
|
|
|
|
+ ViewFileSystem viewFs = (ViewFileSystem) FileSystem
|
|
|
|
+ .get(new URI("viewfs://" + clusterName + "/"), config);
|
|
|
|
+ viewFs.mkdirs(testDir);
|
|
|
|
+ assertTrue(viewFs.exists(testDir));
|
|
|
|
+ assertTrue(fsTarget.exists(realTestPath));
|
|
|
|
+
|
|
|
|
+ viewFs.deleteOnExit(testDir);
|
|
|
|
+ viewFs.close();
|
|
|
|
+ assertFalse(fsTarget.exists(realTestPath));
|
|
|
|
+ }
|
|
}
|
|
}
|