Davis-Zhang-Onehouse commented on code in PR #12781: URL: https://github.com/apache/hudi/pull/12781#discussion_r1980418339
########## hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/TestConcurrentSchemaEvolutionTableSchemaGetter.java: ########## @@ -0,0 +1,630 @@ +/* + * 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.client.transaction; + +import org.apache.hudi.avro.model.HoodieActionInstant; +import org.apache.hudi.avro.model.HoodieCleanMetadata; +import org.apache.hudi.avro.model.HoodieCleanerPlan; +import org.apache.hudi.avro.model.HoodieClusteringGroup; +import org.apache.hudi.avro.model.HoodieClusteringPlan; +import org.apache.hudi.avro.model.HoodieClusteringStrategy; +import org.apache.hudi.avro.model.HoodieRequestedReplaceMetadata; +import org.apache.hudi.avro.model.HoodieRollbackMetadata; +import org.apache.hudi.avro.model.HoodieRollbackPlan; +import org.apache.hudi.avro.model.HoodieSavepointMetadata; +import org.apache.hudi.common.model.HoodieCommitMetadata; +import org.apache.hudi.common.model.HoodieReplaceCommitMetadata; +import org.apache.hudi.common.model.HoodieTableType; +import org.apache.hudi.common.model.WriteOperationType; +import org.apache.hudi.common.table.HoodieTableConfig; +import org.apache.hudi.common.table.timeline.HoodieInstant; +import org.apache.hudi.common.table.timeline.versioning.clean.CleanPlanV2MigrationHandler; +import org.apache.hudi.common.testutils.HoodieCommonTestHarness; +import org.apache.hudi.common.testutils.HoodieTestDataGenerator; +import org.apache.hudi.common.testutils.HoodieTestTable; +import org.apache.hudi.common.testutils.HoodieTestUtils; +import org.apache.hudi.common.util.Option; + +import org.apache.avro.Schema; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +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 org.mockito.Mockito; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Properties; +import java.util.stream.Stream; + +import static org.apache.hudi.avro.HoodieAvroUtils.addMetadataFields; +import static org.apache.hudi.common.table.HoodieTableConfig.PARTITION_FIELDS; +import static org.apache.hudi.common.table.timeline.HoodieTimeline.CLUSTERING_ACTION; +import static org.apache.hudi.common.table.timeline.HoodieTimeline.COMMIT_ACTION; +import static org.apache.hudi.common.table.timeline.HoodieTimeline.COMPACTION_ACTION; +import static org.apache.hudi.common.table.timeline.HoodieTimeline.DELTA_COMMIT_ACTION; +import static org.apache.hudi.common.table.timeline.HoodieTimeline.REPLACE_COMMIT_ACTION; +import static org.apache.hudi.common.testutils.FileCreateUtils.createDeltaCommit; +import static org.apache.hudi.common.testutils.FileCreateUtils.createInflightDeltaCommit; +import static org.apache.hudi.common.testutils.FileCreateUtils.createRequestedDeltaCommit; +import static org.apache.hudi.common.testutils.HoodieTestDataGenerator.TRIP_SCHEMA; +import static org.apache.hudi.common.testutils.HoodieTestUtils.getDefaultStorageConf; +import static org.apache.hudi.common.util.CommitUtils.buildMetadata; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * Tests {@link ConcurrentSchemaEvolutionTableSchemaGetter}. + */ +public class TestConcurrentSchemaEvolutionTableSchemaGetter extends HoodieCommonTestHarness { + + public static final int REQUEST_TIME_LENGTH = 4; + HoodieTestTable testTable; + + private static final String SCHEMA_WITHOUT_METADATA_STR = "{\n" + + " \"namespace\": \"example.avro\",\n" + + " \"type\": \"record\",\n" + + " \"name\": \"User\",\n" + + " \"fields\": [\n" + + " {\"name\": \"timestamp\", \"type\": \"long\"},\n" + + " {\"name\": \"_row_key\", \"type\": \"string\"},\n" + + " {\"name\": \"rider\", \"type\": \"string\"},\n" + + " {\"name\": \"driver\", \"type\": \"string\"}\n" + + " ]\n" + + "}"; + + private static final String SCHEMA_WITHOUT_METADATA_STR2 = "{\n" + + " \"namespace\": \"example.avro\",\n" + + " \"type\": \"record\",\n" + + " \"name\": \"User\",\n" + + " \"fields\": [\n" + + " {\"name\": \"timestamp\", \"type\": \"long\"},\n" + + " {\"name\": \"_row_key\", \"type\": \"string\"},\n" + + " {\"name\": \"rider\", \"type\": \"string\"},\n" + + " {\"name\": \"rider2\", \"type\": \"string\"},\n" + + " {\"name\": \"driver\", \"type\": \"string\"}\n" + + " ]\n" + + "}"; + + private static final String SCHEMA_WITH_PARTITION_COLUMN_STR = "{\n" + + " \"namespace\": \"example.avro\",\n" + + " \"type\": \"record\",\n" + + " \"name\": \"User\",\n" + + " \"fields\": [\n" + + " {\"name\": \"timestamp\", \"type\": \"long\"},\n" + + " {\"name\": \"_row_key\", \"type\": \"string\"},\n" + + " {\"name\": \"rider\", \"type\": \"string\"},\n" + + " {\"name\": \"driver\", \"type\": \"string\"},\n" + + " {\"name\":\"partitionColumn\",\"type\":[\"null\",\"string\"],\"doc\":\"\",\"default\":null}" + + " ]\n" + + "}"; + private static Schema SCHEMA_WITHOUT_METADATA2 = new Schema.Parser().parse(SCHEMA_WITHOUT_METADATA_STR2); + private static Schema SCHEMA_WITHOUT_METADATA = new Schema.Parser().parse(SCHEMA_WITHOUT_METADATA_STR); + private static Schema SCHEMA_WITH_METADATA = addMetadataFields(SCHEMA_WITHOUT_METADATA, false); + private static Schema SCHEMA_WITH_PARTITION_COLUMN = new Schema.Parser().parse(SCHEMA_WITH_PARTITION_COLUMN_STR); + + /** + * Pads a string number with leading zeros until it reaches the specified length. + * + * @param number The string number to pad + * @param length The desired total length after padding + * @return The padded string number + * @throws IllegalArgumentException if the input number is longer than the desired length + */ + public static String padWithLeadingZeros(String number, int length) { Review Comment: moved to upper class, and mark protected ########## hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/TestSimpleSchemaConflictResolutionStrategy.java: ########## @@ -67,303 +65,209 @@ import static org.junit.jupiter.api.Assertions.assertThrows; public class TestSimpleSchemaConflictResolutionStrategy { - + + @Mock + public static FileSystemViewManager viewManager; + @Mock + public static HoodieEngineContext engineContext; + @Mock + public static TaskContextSupplier taskContextSupplier; public Option<HoodieInstant> lastCompletedTxnOwnerInstant; public Option<HoodieInstant> tableCompactionOwnerInstant; + public Option<HoodieInstant> tableClusteringOwnerInstant; + public Option<HoodieInstant> tableReplacementOwnerInstant; public Option<HoodieInstant> nonTableCompactionInstant; @TempDir private java.nio.file.Path basePath; @Mock private HoodieWriteConfig config; private HoodieTableMetaClient metaClient; private HoodieTestTable dummyInstantGenerator; - private TestTable table; + private TestBaseHoodieTable table; private SimpleSchemaConflictResolutionStrategy strategy; - + private static final String SCHEMA1 = "{\"type\":\"record\",\"name\":\"MyRecord\",\"fields\":[{\"name\":\"field1\",\"type\":\"string\"}]}"; private static final String SCHEMA2 = "{\"type\":\"record\",\"name\":\"MyRecord\",\"fields\":[{\"name\":\"field1\",\"type\":\"string\"},{\"name\":\"field2\",\"type\":\"int\"}]}"; private static final String SCHEMA3 = "{\"type\":\"record\",\"name\":\"MyRecord\",\"fields\":[{\"name\":\"field1\",\"type\":\"string\"},{\"name\":\"field3\",\"type\":\"boolean\"}]}"; private static final String NULL_SCHEMA = "{\"type\":\"null\"}"; - private void setupMocks(String tableSchemaAtTxnStart, String tableSchemaAtTxnValidation, - String writerSchemaOfTxn, Boolean enableResolution) throws Exception { - metaClient = HoodieTestUtils.getMetaClientBuilder(HoodieTableType.COPY_ON_WRITE, new Properties(),"") + private void setupInstants(String tableSchemaAtTxnStart, String tableSchemaAtTxnValidation, + String writerSchemaOfTxn, Boolean enableResolution, boolean setupLegacyClustering) throws Exception { + metaClient = HoodieTestUtils.getMetaClientBuilder(HoodieTableType.COPY_ON_WRITE, new Properties(), "") .setTableCreateSchema(SCHEMA1) .initTable(getDefaultStorageConf(), basePath.toString()); dummyInstantGenerator = HoodieTestTable.of(metaClient); - lastCompletedTxnOwnerInstant = Option.of(metaClient.createNewInstant(HoodieInstant.State.COMPLETED, COMMIT_ACTION, "001")); - tableCompactionOwnerInstant = Option.of(metaClient.createNewInstant(HoodieInstant.State.INFLIGHT, COMPACTION_ACTION, "003")); - nonTableCompactionInstant = Option.of(metaClient.createNewInstant(HoodieInstant.State.INFLIGHT, COMMIT_ACTION, "003")); + lastCompletedTxnOwnerInstant = Option.of(metaClient.createNewInstant(HoodieInstant.State.COMPLETED, COMMIT_ACTION, "001", "001")); + tableCompactionOwnerInstant = Option.of(metaClient.createNewInstant(HoodieInstant.State.INFLIGHT, COMPACTION_ACTION, "003", "003")); + tableClusteringOwnerInstant = Option.of(metaClient.createNewInstant(HoodieInstant.State.INFLIGHT, CLUSTERING_ACTION, "003", "003")); + tableReplacementOwnerInstant = Option.of(metaClient.createNewInstant(HoodieInstant.State.INFLIGHT, REPLACE_COMMIT_ACTION, "003", "003")); + nonTableCompactionInstant = Option.of(metaClient.createNewInstant(HoodieInstant.State.INFLIGHT, COMMIT_ACTION, "004", "004")); Review Comment: done -- 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]
