|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.fs.viewfs; |
| 19 | + |
| 20 | +import java.io.IOException; |
| 21 | + |
| 22 | +import org.apache.hadoop.conf.Configuration; |
| 23 | +import org.apache.hadoop.fs.FileSystem; |
| 24 | +import org.apache.hadoop.fs.FsConstants; |
| 25 | +import org.apache.hadoop.fs.Path; |
| 26 | +import org.apache.hadoop.test.AbstractHadoopTestBase; |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +import static org.apache.hadoop.test.LambdaTestUtils.intercept; |
| 30 | + |
| 31 | +public class TestViewFileSystemClose extends AbstractHadoopTestBase { |
| 32 | + |
| 33 | + /** |
| 34 | + * Verify that all child file systems of a ViewFileSystem will be shut down |
| 35 | + * when the cache is disabled. |
| 36 | + * @throws IOException |
| 37 | + */ |
| 38 | + @Test |
| 39 | + public void testFileSystemLeak() throws Exception { |
| 40 | + |
| 41 | + Configuration conf = new Configuration(); |
| 42 | + conf.set("fs.viewfs.impl", ViewFileSystem.class.getName()); |
| 43 | + conf.setBoolean("fs.viewfs.enable.inner.cache", false); |
| 44 | + conf.setBoolean("fs.viewfs.impl.disable.cache", true); |
| 45 | + conf.setBoolean("fs.hdfs.impl.disable.cache", true); |
| 46 | + |
| 47 | + String rootPath = "hdfs://localhost/tmp"; |
| 48 | + ConfigUtil.addLink(conf, "/data", new Path(rootPath, "data").toUri()); |
| 49 | + ViewFileSystem viewFs = |
| 50 | + (ViewFileSystem) FileSystem.get(FsConstants.VIEWFS_URI, conf); |
| 51 | + |
| 52 | + FileSystem[] children = viewFs.getChildFileSystems(); |
| 53 | + viewFs.close(); |
| 54 | + FileSystem.closeAll(); |
| 55 | + for (FileSystem fs : children) { |
| 56 | + intercept(IOException.class, "Filesystem closed", |
| 57 | + "Expect Filesystem closed IOException", |
| 58 | + () -> fs.create(new Path(rootPath, "neverSuccess"))); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments