nsivabalan commented on code in PR #11343:
URL: https://github.com/apache/hudi/pull/11343#discussion_r1619309145


##########
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/table/functional/TestCleanActionExecutor.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.table.functional;
+
+import org.apache.hudi.avro.model.HoodieActionInstant;
+import org.apache.hudi.avro.model.HoodieCleanFileInfo;
+import org.apache.hudi.avro.model.HoodieCleanMetadata;
+import org.apache.hudi.avro.model.HoodieCleanPartitionMetadata;
+import org.apache.hudi.avro.model.HoodieCleanerPlan;
+import org.apache.hudi.common.config.HoodieMetadataConfig;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.engine.HoodieLocalEngineContext;
+import org.apache.hudi.common.model.HoodieBaseFile;
+import org.apache.hudi.common.model.HoodieCleaningPolicy;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.table.timeline.TimelineMetadataUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StorageConfiguration;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.action.clean.CleanActionExecutor;
+import org.apache.hudi.table.action.clean.CleanPlanner;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static 
org.apache.hudi.common.testutils.HoodieTestUtils.getDefaultStorageConf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests Clean action executor.
+ */
+public class TestCleanActionExecutor {
+
+  private static final StorageConfiguration<Configuration> CONF = 
getDefaultStorageConf();
+  private final HoodieEngineContext context = new 
HoodieLocalEngineContext(CONF);
+  private final HoodieTable<?, ?, ?, ?> mockHoodieTable = 
mock(HoodieTable.class);
+  private HoodieTableMetaClient metaClient;
+  private FileSystem fs;
+
+  private static String PARTITION1 = "partition1";
+
+  String earliestInstant = "20231204194919610";
+  String earliestInstantMinusThreeDays = "20231201194919610";
+
+  @BeforeEach
+  void setUp() {
+    metaClient = mock(HoodieTableMetaClient.class);
+    when(mockHoodieTable.getMetaClient()).thenReturn(metaClient);
+    HoodieTableConfig tableConfig = new HoodieTableConfig();
+    when(metaClient.getTableConfig()).thenReturn(tableConfig);
+    HoodieStorage storage = mock(HoodieStorage.class);
+    when(metaClient.getStorage()).thenReturn(storage);
+    when(mockHoodieTable.getStorage()).thenReturn(storage);
+    fs = mock(FileSystem.class);
+    when(storage.getFileSystem()).thenReturn(fs);
+    when(fs.getConf()).thenReturn(CONF.unwrap());
+  }
+
+  @ParameterizedTest
+  @ValueSource(booleans = {true, false})
+  void testPartialCleanFailure(boolean simulateFailedDeletion) throws 
IOException {
+    HoodieWriteConfig config = getCleanByCommitsConfig();
+    String fileGroup = UUID.randomUUID() + "-0";
+    HoodieBaseFile baseFile = new 
HoodieBaseFile(String.format("/tmp/base/%s_1-0-1_%s.parquet", fileGroup, 
"001"));
+    FileSystem localFs = new 
Path(baseFile.getPath()).getFileSystem(CONF.unwrap());
+    Path filePath = new Path(baseFile.getPath());
+    localFs.create(filePath);
+    String exceptionMsg = "throwing run time exception";
+    if (simulateFailedDeletion) {
+      when(fs.delete(filePath, false)).thenThrow(new 
RuntimeException(exceptionMsg));

Review Comment:
   added more tests to cover all diff scenarios 



-- 
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]

Reply via email to