diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTests.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTests.java new file mode 100644 index 000000000000..64ce7c148c51 --- /dev/null +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTests.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.fs.ozone; + +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; + +import java.io.IOException; +import java.net.URI; +import java.util.Objects; +import java.util.Set; +import java.util.TreeSet; + +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_LISTING_PAGE_SIZE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Common test cases for Ozone file systems. + */ +final class OzoneFileSystemTests { + + private OzoneFileSystemTests() { + // no instances + } + + /** + * Tests listStatusIterator operation on directory with different + * numbers of child directories. + */ + public static void listStatusIteratorOnPageSize(OzoneConfiguration conf, + String rootPath) throws IOException { + final int pageSize = 32; + int[] dirCounts = { + 1, + pageSize - 1, + pageSize, + pageSize + 1, + pageSize + pageSize / 2, + pageSize + pageSize + }; + OzoneConfiguration config = new OzoneConfiguration(conf); + config.setInt(OZONE_FS_LISTING_PAGE_SIZE, pageSize); + URI uri = FileSystem.getDefaultUri(config); + config.setBoolean( + String.format("fs.%s.impl.disable.cache", uri.getScheme()), true); + FileSystem subject = FileSystem.get(uri, config); + Path dir = new Path(Objects.requireNonNull(rootPath), "listStatusIterator"); + try { + Set paths = new TreeSet<>(); + for (int dirCount : dirCounts) { + listStatusIterator(subject, dir, paths, dirCount); + } + } finally { + subject.delete(dir, true); + } + } + + private static void listStatusIterator(FileSystem subject, + Path dir, Set paths, int total) throws IOException { + for (int i = paths.size(); i < total; i++) { + Path p = new Path(dir, String.valueOf(i)); + subject.mkdirs(p); + paths.add(p.getName()); + } + + RemoteIterator iterator = subject.listStatusIterator(dir); + int iCount = 0; + if (iterator != null) { + while (iterator.hasNext()) { + FileStatus fileStatus = iterator.next(); + iCount++; + String filename = fileStatus.getPath().getName(); + assertTrue(filename + " not found", paths.contains(filename)); + } + } + + assertEquals( + "Total directories listed do not match the existing directories", + total, iCount); + } +} diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java index 3cab11714ebb..76a12204a630 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java @@ -962,65 +962,10 @@ public void testListStatusIteratorOnRoot() throws Exception { } } - /** - * Tests listStatusIterator operation on root directory with different - * numbers of numDir. - */ @Test public void testListStatusIteratorOnPageSize() throws Exception { - int[] pageSize = { - 1, LISTING_PAGE_SIZE, LISTING_PAGE_SIZE + 1, - LISTING_PAGE_SIZE - 1, LISTING_PAGE_SIZE + LISTING_PAGE_SIZE / 2, - LISTING_PAGE_SIZE + LISTING_PAGE_SIZE - }; - for (int numDir : pageSize) { - int range = numDir / LISTING_PAGE_SIZE; - switch (range) { - case 0: - listStatusIterator(numDir); - break; - case 1: - listStatusIterator(numDir); - break; - case 2: - listStatusIterator(numDir); - break; - default: - listStatusIterator(numDir); - } - } - } - - private void listStatusIterator(int numDirs) throws IOException { - Path root = new Path("/" + volumeName + "/" + bucketName); - Set paths = new TreeSet<>(); - try { - for (int i = 0; i < numDirs; i++) { - Path p = new Path(root, String.valueOf(i)); - fs.mkdirs(p); - paths.add(p.getName()); - } - - RemoteIterator iterator = o3fs.listStatusIterator(root); - int iCount = 0; - if (iterator != null) { - while (iterator.hasNext()) { - FileStatus fileStatus = iterator.next(); - iCount++; - Assert.assertTrue(paths.contains(fileStatus.getPath().getName())); - } - } - Assert.assertEquals( - "Total directories listed do not match the existing directories", - numDirs, iCount); - - } finally { - // Cleanup - for (int i = 0; i < numDirs; i++) { - Path p = new Path(root, String.valueOf(i)); - fs.delete(p, true); - } - } + OzoneFileSystemTests.listStatusIteratorOnPageSize(cluster.getConf(), + "/" + volumeName + "/" + bucketName); } /** diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java index 07c9680aa461..65b8ebcc937d 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java @@ -88,7 +88,6 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.net.URI; import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.security.PrivilegedExceptionAction; @@ -119,7 +118,6 @@ import static org.apache.hadoop.hdds.client.ECReplicationConfig.EcCodec.RS; import static org.apache.hadoop.ozone.OzoneAcl.AclScope.ACCESS; import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE; -import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_LISTING_PAGE_SIZE; import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER; import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY; import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ENABLE_OFS_SHARED_TMP_DIR; @@ -588,55 +586,8 @@ public void testListStatusIteratorWithPathNotFound() throws Exception { */ @Test public void testListStatusIteratorOnPageSize() throws Exception { - final int pageSize = 32; - int[] dirCounts = { - 1, - pageSize - 1, - pageSize, - pageSize + 1, - pageSize + pageSize / 2, - pageSize + pageSize - }; - OzoneConfiguration config = new OzoneConfiguration(conf); - config.setInt(OZONE_FS_LISTING_PAGE_SIZE, pageSize); - URI uri = FileSystem.getDefaultUri(config); - config.setBoolean( - String.format("fs.%s.impl.disable.cache", uri.getScheme()), true); - FileSystem subject = FileSystem.get(uri, config); - Path root = new Path("/" + volumeName + "/" + bucketName); - Path dir = new Path(root, "listStatusIterator"); - try { - Set paths = new TreeSet<>(); - for (int dirCount : dirCounts) { - listStatusIterator(subject, dir, paths, dirCount); - } - } finally { - subject.delete(dir, true); - } - } - - private static void listStatusIterator(FileSystem subject, - Path dir, Set paths, int total) throws IOException { - for (int i = paths.size(); i < total; i++) { - Path p = new Path(dir, String.valueOf(i)); - subject.mkdirs(p); - paths.add(p.getName()); - } - - RemoteIterator iterator = subject.listStatusIterator(dir); - int iCount = 0; - if (iterator != null) { - while (iterator.hasNext()) { - FileStatus fileStatus = iterator.next(); - iCount++; - String filename = fileStatus.getPath().getName(); - assertTrue(filename + " not found", paths.contains(filename)); - } - } - - assertEquals( - "Total directories listed do not match the existing directories", - total, iCount); + OzoneFileSystemTests.listStatusIteratorOnPageSize(conf, + "/" + volumeName + "/" + bucketName); } /**