nsivabalan commented on a change in pull request #1858:
URL: https://github.com/apache/hudi/pull/1858#discussion_r467588637



##########
File path: 
hudi-client/src/test/java/org/apache/hudi/table/upgrade/TestUpgradeDowngrade.java
##########
@@ -0,0 +1,405 @@
+/*
+ * 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.upgrade;
+
+import org.apache.hudi.client.HoodieWriteClient;
+import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.common.model.FileSlice;
+import org.apache.hudi.common.model.HoodieFileGroup;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.HoodieTableVersion;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.view.SyncableFileSystemView;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.testutils.HoodieTestUtils;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.MarkerFiles;
+import org.apache.hudi.testutils.Assertions;
+import org.apache.hudi.testutils.HoodieClientTestBase;
+import org.apache.hudi.testutils.HoodieClientTestUtils;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileUtil;
+import org.apache.hadoop.fs.Path;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static 
org.apache.hudi.common.table.HoodieTableConfig.HOODIE_TABLE_TYPE_PROP_NAME;
+import static 
org.apache.hudi.common.testutils.HoodieTestDataGenerator.DEFAULT_FIRST_PARTITION_PATH;
+import static 
org.apache.hudi.common.testutils.HoodieTestDataGenerator.DEFAULT_SECOND_PARTITION_PATH;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Unit tests {@link UpgradeDowngrade}.
+ */
+public class TestUpgradeDowngrade extends HoodieClientTestBase {
+
+  private static final String TEST_NAME_WITH_PARAMS = "[{index}] Test with 
induceResiduesFromPrevUpgrade={0}, deletePartialMarkerFiles={1} and TableType = 
{2}";
+
+  public static Stream<Arguments> configParams() {
+    Object[][] data = new Object[][] {
+            {true, HoodieTableType.COPY_ON_WRITE}, {false, 
HoodieTableType.COPY_ON_WRITE},
+            {true, HoodieTableType.MERGE_ON_READ}, {false, 
HoodieTableType.MERGE_ON_READ}
+    };
+    return Stream.of(data).map(Arguments::of);
+  }
+
+  @Test
+  public void testLeftOverUpdatedPropFileCleanup() throws IOException {
+    testUpgradeInternal(true, true, HoodieTableType.MERGE_ON_READ);
+  }
+
+  @ParameterizedTest(name = TEST_NAME_WITH_PARAMS)
+  @MethodSource("configParams")
+  public void testUpgrade(boolean deletePartialMarkerFiles, HoodieTableType 
tableType) throws IOException {
+    testUpgradeInternal(false, deletePartialMarkerFiles, tableType);
+  }
+
+  public void testUpgradeInternal(boolean induceResiduesFromPrevUpgrade, 
boolean deletePartialMarkerFiles, HoodieTableType tableType) throws IOException 
{
+    // init config, table and client.
+    Map<String, String> params = new HashMap<>();
+    if (tableType == HoodieTableType.MERGE_ON_READ) {
+      params.put(HOODIE_TABLE_TYPE_PROP_NAME, 
HoodieTableType.MERGE_ON_READ.name());
+      metaClient = HoodieTestUtils.init(hadoopConf, basePath, 
HoodieTableType.MERGE_ON_READ);
+    }
+    HoodieWriteConfig cfg = 
getConfigBuilder().withAutoCommit(false).withRollbackUsingMarkers(false).withProps(params).build();
+    HoodieWriteClient client = getHoodieWriteClient(cfg);
+
+    // prepare data. Make 2 commits, in which 2nd is not committed.
+    List<FileSlice> firstPartitionCommit2FileSlices = new ArrayList<>();
+    List<FileSlice> secondPartitionCommit2FileSlices = new ArrayList<>();
+    Pair<List<HoodieRecord>, List<HoodieRecord>> inputRecords = 
twoUpsertCommitDataWithTwoPartitions(firstPartitionCommit2FileSlices, 
secondPartitionCommit2FileSlices, cfg, client, false);

Review comment:
       this needs fixing. This will issue commit via client and since you have 
removed the guard to execute upgrade (even if marker based is disabled), 
upgrade would have already been executed. if I am not wrong, below command of 
   ```
   UpgradeDowngrade.run(metaClient, HoodieTableVersion.ONE, cfg, jsc, null); 
   ```
   is a no op since already the table version is upgraded.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to