|
17 | 17 |
|
18 | 18 | package org.apache.hadoop.ozone.freon; |
19 | 19 |
|
| 20 | +import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_SCHEME; |
| 21 | +import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY; |
20 | 22 | import static org.assertj.core.api.Assertions.assertThat; |
21 | 23 | import static org.junit.jupiter.api.Assertions.assertEquals; |
22 | 24 |
|
23 | | -import java.io.File; |
24 | | -import java.io.FileOutputStream; |
25 | 25 | import java.io.IOException; |
26 | 26 | import java.net.URI; |
27 | 27 | import java.util.ArrayList; |
28 | 28 | import java.util.Arrays; |
29 | 29 | import java.util.Collections; |
30 | 30 | import java.util.List; |
31 | | -import org.apache.commons.io.FileUtils; |
| 31 | +import java.util.UUID; |
32 | 32 | import org.apache.hadoop.fs.FileStatus; |
33 | 33 | import org.apache.hadoop.fs.FileSystem; |
34 | 34 | import org.apache.hadoop.fs.Path; |
| 35 | +import org.apache.hadoop.fs.ozone.OzoneFileSystemTests; |
35 | 36 | import org.apache.hadoop.hdds.conf.OzoneConfiguration; |
36 | 37 | import org.apache.hadoop.hdds.conf.StorageSize; |
37 | 38 | import org.apache.hadoop.hdds.conf.StorageUnit; |
38 | 39 | import org.apache.hadoop.hdds.utils.IOUtils; |
39 | | -import org.apache.hadoop.ozone.MiniOzoneCluster; |
| 40 | +import org.apache.hadoop.ozone.client.BucketArgs; |
40 | 41 | import org.apache.hadoop.ozone.client.ObjectStore; |
41 | 42 | import org.apache.hadoop.ozone.client.OzoneClient; |
42 | | -import org.apache.hadoop.ozone.client.OzoneClientFactory; |
43 | 43 | import org.apache.hadoop.ozone.client.OzoneVolume; |
44 | | -import org.apache.hadoop.ozone.om.OMConfigKeys; |
45 | 44 | import org.apache.hadoop.ozone.om.helpers.BucketLayout; |
46 | | -import org.apache.ozone.test.GenericTestUtils; |
47 | | -import org.apache.ratis.server.RaftServer; |
48 | | -import org.apache.ratis.server.raftlog.RaftLog; |
| 45 | +import org.apache.ozone.test.NonHATests; |
| 46 | +import org.junit.jupiter.api.AfterEach; |
49 | 47 | import org.junit.jupiter.api.BeforeEach; |
50 | | -import org.junit.jupiter.api.Test; |
51 | | -import org.junit.jupiter.api.io.TempDir; |
| 48 | +import org.junit.jupiter.params.ParameterizedTest; |
| 49 | +import org.junit.jupiter.params.provider.EnumSource; |
52 | 50 | import org.slf4j.Logger; |
53 | 51 | import org.slf4j.LoggerFactory; |
54 | | -import org.slf4j.event.Level; |
55 | 52 |
|
56 | 53 | /** |
57 | 54 | * Test for HadoopDirTreeGenerator. |
58 | 55 | */ |
59 | | -public class TestHadoopDirTreeGenerator { |
60 | | - @TempDir |
61 | | - private java.nio.file.Path path; |
62 | | - private OzoneConfiguration conf = null; |
63 | | - private MiniOzoneCluster cluster = null; |
| 56 | +public abstract class TestHadoopDirTreeGenerator implements NonHATests.TestCase { |
| 57 | + |
| 58 | + private static final int PAGE_SIZE = 10; |
| 59 | + |
64 | 60 | private ObjectStore store = null; |
65 | 61 | private static final Logger LOG = |
66 | 62 | LoggerFactory.getLogger(TestHadoopDirTreeGenerator.class); |
67 | 63 | private OzoneClient client; |
68 | 64 |
|
69 | 65 | @BeforeEach |
70 | | - public void setup() { |
71 | | - GenericTestUtils.setLogLevel(RaftLog.LOG, Level.DEBUG); |
72 | | - GenericTestUtils.setLogLevel(RaftServer.LOG, Level.DEBUG); |
73 | | - } |
74 | | - |
75 | | - /** |
76 | | - * Shutdown MiniDFSCluster. |
77 | | - */ |
78 | | - private void shutdown() throws IOException { |
79 | | - IOUtils.closeQuietly(client); |
80 | | - if (cluster != null) { |
81 | | - cluster.shutdown(); |
82 | | - } |
83 | | - } |
84 | | - |
85 | | - /** |
86 | | - * Create a MiniDFSCluster for testing. |
87 | | - * |
88 | | - * @throws IOException |
89 | | - */ |
90 | | - private void startCluster() throws Exception { |
91 | | - conf = getOzoneConfiguration(); |
92 | | - conf.set(OMConfigKeys.OZONE_DEFAULT_BUCKET_LAYOUT, |
93 | | - BucketLayout.LEGACY.name()); |
94 | | - cluster = MiniOzoneCluster.newBuilder(conf).setNumDatanodes(5).build(); |
95 | | - cluster.waitForClusterToBeReady(); |
96 | | - cluster.waitTobeOutOfSafeMode(); |
97 | | - |
98 | | - client = OzoneClientFactory.getRpcClient(conf); |
| 66 | + void setup() throws Exception { |
| 67 | + client = cluster().newClient(); |
99 | 68 | store = client.getObjectStore(); |
100 | 69 | } |
101 | 70 |
|
102 | | - protected OzoneConfiguration getOzoneConfiguration() { |
103 | | - return new OzoneConfiguration(); |
| 71 | + @AfterEach |
| 72 | + void cleanup() { |
| 73 | + IOUtils.closeQuietly(client); |
104 | 74 | } |
105 | 75 |
|
106 | | - @Test |
107 | | - public void testNestedDirTreeGeneration() throws Exception { |
108 | | - try { |
109 | | - startCluster(); |
110 | | - FileOutputStream out = FileUtils.openOutputStream(new File(path.toString(), |
111 | | - "conf")); |
112 | | - cluster.getConf().writeXml(out); |
113 | | - out.getFD().sync(); |
114 | | - out.close(); |
115 | | - |
116 | | - verifyDirTree("vol1", "bucket1", 1, |
117 | | - 1, 1, "0"); |
118 | | - verifyDirTree("vol2", "bucket1", 1, |
119 | | - 5, 1, "5B"); |
120 | | - verifyDirTree("vol3", "bucket1", 2, |
121 | | - 5, 3, "1B"); |
122 | | - verifyDirTree("vol4", "bucket1", 3, |
123 | | - 2, 4, "2B"); |
124 | | - verifyDirTree("vol5", "bucket1", 5, |
125 | | - 4, 1, "0"); |
126 | | - // default page size is Constants.LISTING_PAGE_SIZE = 1024 |
127 | | - verifyDirTree("vol6", "bucket1", 2, |
128 | | - 1, 1100, "0"); |
129 | | - } finally { |
130 | | - shutdown(); |
131 | | - } |
| 76 | + @ParameterizedTest |
| 77 | + @EnumSource(names = {"FILE_SYSTEM_OPTIMIZED", "LEGACY"}) |
| 78 | + public void testNestedDirTreeGeneration(BucketLayout layout) throws Exception { |
| 79 | + String uuid = UUID.randomUUID().toString(); |
| 80 | + verifyDirTree("vol1-" + uuid, "bucket1", 1, 1, 1, "0", layout); |
| 81 | + verifyDirTree("vol2-" + uuid, "bucket1", 1, 5, 1, "5B", layout); |
| 82 | + verifyDirTree("vol3-" + uuid, "bucket1", 2, 5, 3, "1B", layout); |
| 83 | + verifyDirTree("vol4-" + uuid, "bucket1", 3, 2, 4, "2B", layout); |
| 84 | + verifyDirTree("vol5-" + uuid, "bucket1", 5, 4, 1, "0", layout); |
| 85 | + verifyDirTree("vol6-" + uuid, "bucket1", 2, 1, PAGE_SIZE + PAGE_SIZE / 2, "0", layout); |
132 | 86 | } |
133 | 87 |
|
134 | 88 | private void verifyDirTree(String volumeName, String bucketName, int depth, |
135 | | - int span, int fileCount, String perFileSize) |
| 89 | + int span, int fileCount, String perFileSize, BucketLayout layout) |
136 | 90 | throws IOException { |
137 | 91 |
|
138 | 92 | store.createVolume(volumeName); |
139 | 93 | OzoneVolume volume = store.getVolume(volumeName); |
140 | | - volume.createBucket(bucketName); |
141 | | - String rootPath = "o3fs://" + bucketName + "." + volumeName; |
142 | | - String confPath = new File(path.toString(), "conf").getAbsolutePath(); |
143 | | - new Freon().execute( |
144 | | - new String[]{"-conf", confPath, "dtsg", "-d", depth + "", "-c", |
145 | | - fileCount + "", "-s", span + "", "-n", "1", "-r", rootPath, |
146 | | - "-g", perFileSize}); |
| 94 | + volume.createBucket(bucketName, BucketArgs.newBuilder().setBucketLayout(layout).build()); |
| 95 | + String rootPath = OZONE_URI_SCHEME + "://" + bucketName + "." + volumeName; |
| 96 | + String om = cluster().getConf().get(OZONE_OM_ADDRESS_KEY); |
| 97 | + new Freon().getCmd().execute( |
| 98 | + "-D", OZONE_OM_ADDRESS_KEY + "=" + om, |
| 99 | + "dtsg", |
| 100 | + "-c", String.valueOf(fileCount), |
| 101 | + "-d", String.valueOf(depth), |
| 102 | + "-g", perFileSize, |
| 103 | + "-n", "1", |
| 104 | + "-r", rootPath, |
| 105 | + "-s", String.valueOf(span) |
| 106 | + ); |
147 | 107 | // verify the directory structure |
148 | 108 | LOG.info("Started verifying the directory structure..."); |
149 | | - FileSystem fileSystem = FileSystem.get(URI.create(rootPath), |
150 | | - conf); |
151 | | - Path rootDir = new Path(rootPath.concat("/")); |
152 | | - // verify root path details |
153 | | - FileStatus[] fileStatuses = fileSystem.listStatus(rootDir); |
154 | | - // verify the num of peer directories, expected span count is 1 |
155 | | - // as it has only one dir at root. |
156 | | - verifyActualSpan(1, Arrays.asList(fileStatuses)); |
157 | | - for (FileStatus fileStatus : fileStatuses) { |
158 | | - int actualDepth = |
159 | | - traverseToLeaf(fileSystem, fileStatus.getPath(), 1, depth, span, |
160 | | - fileCount, StorageSize.parse(perFileSize, StorageUnit.BYTES)); |
161 | | - assertEquals(depth, actualDepth, "Mismatch depth in a path"); |
| 109 | + OzoneConfiguration conf = new OzoneConfiguration(cluster().getConf()); |
| 110 | + OzoneFileSystemTests.setPageSize(conf, PAGE_SIZE); |
| 111 | + try (FileSystem fileSystem = FileSystem.get(URI.create(rootPath), conf)) { |
| 112 | + Path rootDir = new Path(rootPath.concat("/")); |
| 113 | + // verify root path details |
| 114 | + FileStatus[] fileStatuses = fileSystem.listStatus(rootDir); |
| 115 | + // verify the num of peer directories, expected span count is 1 |
| 116 | + // as it has only one dir at root. |
| 117 | + verifyActualSpan(1, Arrays.asList(fileStatuses)); |
| 118 | + for (FileStatus fileStatus : fileStatuses) { |
| 119 | + int actualDepth = |
| 120 | + traverseToLeaf(fileSystem, fileStatus.getPath(), 1, depth, span, |
| 121 | + fileCount, StorageSize.parse(perFileSize, StorageUnit.BYTES)); |
| 122 | + assertEquals(depth, actualDepth, "Mismatch depth in a path"); |
| 123 | + } |
162 | 124 | } |
163 | 125 | } |
164 | 126 |
|
|
0 commit comments