xushiyan commented on a change in pull request #5153: URL: https://github.com/apache/hudi/pull/5153#discussion_r839554172
########## File path: hudi-sync/hudi-sync-common/src/test/java/org/apache/hudi/sync/common/util/TestManifestFileUtil.java ########## @@ -0,0 +1,81 @@ +/* + * 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.hudi.sync.common.util; + +import org.apache.hudi.common.fs.FSUtils; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.IntStream; + +import org.apache.hudi.common.testutils.HoodieCommonTestHarness; +import org.apache.hudi.common.testutils.HoodieTestTable; + +public class TestManifestFileUtil extends HoodieCommonTestHarness { + + private static final List<String> MULTI_LEVEL_PARTITIONS = Arrays.asList("2019/01", "2020/01", "2021/01"); + private static HoodieTestTable hoodieTestTable; + + @BeforeEach + public void setUp() throws IOException { + initMetaClient(); + hoodieTestTable = HoodieTestTable.of(metaClient); + } + + @Test + public void testMultiLevelPartitionedTable() throws Exception { + // Generate 10 files under each partition + createTestDataForPartitionedTable(10); + ManifestFileUtil manifestFileUtil = ManifestFileUtil.builder().setConf(metaClient.getHadoopConf()).setBasePath(basePath).build(); + Assertions.assertEquals(30, manifestFileUtil.fetchLatestBaseFilesForAllPartitions().count()); + } + + @Test + public void testCreateManifestFile() throws Exception { + // Generate 10 files under each partition + createTestDataForPartitionedTable(10); + ManifestFileUtil mainfestFileUtil = ManifestFileUtil.builder().setConf(metaClient.getHadoopConf()).setBasePath(basePath).build(); + try { + mainfestFileUtil.writeManifestFile(); + Assertions.assertTrue(FSUtils.getFileSize(metaClient.getFs(), mainfestFileUtil.getManifestFilePath()) > 0); + } catch (IOException e) { + e.printStackTrace(); + } Review comment: can you remove try-catch so any failure not silenced? ########## File path: hudi-sync/hudi-sync-common/src/test/java/org/apache/hudi/sync/common/util/TestManifestFileUtil.java ########## @@ -0,0 +1,81 @@ +/* + * 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.hudi.sync.common.util; + +import org.apache.hudi.common.fs.FSUtils; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.IntStream; + +import org.apache.hudi.common.testutils.HoodieCommonTestHarness; +import org.apache.hudi.common.testutils.HoodieTestTable; + +public class TestManifestFileUtil extends HoodieCommonTestHarness { + + private static final List<String> MULTI_LEVEL_PARTITIONS = Arrays.asList("2019/01", "2020/01", "2021/01"); + private static HoodieTestTable hoodieTestTable; + + @BeforeEach + public void setUp() throws IOException { + initMetaClient(); + hoodieTestTable = HoodieTestTable.of(metaClient); + } + + @Test + public void testMultiLevelPartitionedTable() throws Exception { + // Generate 10 files under each partition + createTestDataForPartitionedTable(10); + ManifestFileUtil manifestFileUtil = ManifestFileUtil.builder().setConf(metaClient.getHadoopConf()).setBasePath(basePath).build(); + Assertions.assertEquals(30, manifestFileUtil.fetchLatestBaseFilesForAllPartitions().count()); + } + + @Test + public void testCreateManifestFile() throws Exception { + // Generate 10 files under each partition + createTestDataForPartitionedTable(10); + ManifestFileUtil mainfestFileUtil = ManifestFileUtil.builder().setConf(metaClient.getHadoopConf()).setBasePath(basePath).build(); + try { + mainfestFileUtil.writeManifestFile(); + Assertions.assertTrue(FSUtils.getFileSize(metaClient.getFs(), mainfestFileUtil.getManifestFilePath()) > 0); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void createTestDataForPartitionedTable(int numOfFiles) throws Exception { + String instant = "100"; + hoodieTestTable = hoodieTestTable.addCommit(instant); + // Generate 10 files under each partition + MULTI_LEVEL_PARTITIONS.forEach(p -> { + try { Review comment: /nit prefer for-loop over foreach so you don't have to try-catch. just throw out looks cleaner ########## File path: hudi-sync/hudi-sync-common/pom.xml ########## @@ -104,6 +104,14 @@ <artifactId>junit-platform-commons</artifactId> <scope>test</scope> </dependency> + + <dependency> + <groupId>org.apache.hudi</groupId> + <artifactId>hudi-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> Review comment: can you remove this ? hudi-common is added at the top already right? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
