yihua commented on code in PR #12696: URL: https://github.com/apache/hudi/pull/12696#discussion_r1968225030
########## hudi-timeline-service/src/test/java/org/apache/hudi/timeline/service/MockHoodieHadoopStorage.java: ########## @@ -0,0 +1,92 @@ +/* + * 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.timeline.service; + +import org.apache.hudi.storage.StorageConfiguration; +import org.apache.hudi.storage.StoragePath; +import org.apache.hudi.storage.StoragePathInfo; +import org.apache.hudi.storage.hadoop.HoodieHadoopStorage; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; + +/** + * A mock implementation of {@link HoodieHadoopStorage} that validates the storage scheme and authority + * before delegating operations to the superclass. + * <p> + * This class is primarily used for testing and ensures that all storage operations conform + * to the expected scheme and authority. + * </p> + */ +public class MockHoodieHadoopStorage extends HoodieHadoopStorage { + + private final String scheme; + private final String authority; + + public MockHoodieHadoopStorage(StoragePath path, StorageConfiguration<?> conf) { + super(convertToHadoopPath(path), conf); + this.scheme = path.toUri().getScheme(); + this.authority = path.toUri().getAuthority(); + } + + private static StoragePath convertToHadoopPath(StoragePath storagePath) { + return new StoragePath(storagePath.toUri().getPath()); + } + + @Override + public String getScheme() { + return super.getScheme(); + } + + @Override + public boolean exists(StoragePath path) throws IOException { + return super.exists(validateAndConvertPath(path)); + } + + @Override + public boolean createDirectory(StoragePath path) throws IOException { + return super.createDirectory(validateAndConvertPath(path)); + } + + @Override + public OutputStream create(StoragePath path, boolean overwrite) throws IOException { + return super.create(validateAndConvertPath(path), overwrite); + } + + @Override + public OutputStream create(StoragePath path) throws IOException { + return super.create(validateAndConvertPath(path)); + } + + @Override + public List<StoragePathInfo> listDirectEntries(StoragePath path) throws IOException { + return super.listDirectEntries(validateAndConvertPath(path)); + } + + private StoragePath validateAndConvertPath(StoragePath path) { + assert scheme == null || scheme.equals(path.toUri().getScheme()) : + String.format("Invalid scheme, expected %s, found %s", scheme, path.toUri().getScheme()); Review Comment: nit: use `ValidationUtils#checkArgument` here ########## hudi-timeline-service/src/test/java/org/apache/hudi/timeline/service/TestRequestHandler.java: ########## @@ -0,0 +1,147 @@ +/* + * 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.timeline.service; + +import org.apache.hudi.common.config.HoodieCommonConfig; +import org.apache.hudi.common.config.HoodieMetadataConfig; +import org.apache.hudi.common.engine.HoodieLocalEngineContext; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.view.FileSystemViewManager; +import org.apache.hudi.common.table.view.FileSystemViewStorageConfig; +import org.apache.hudi.common.table.view.FileSystemViewStorageType; +import org.apache.hudi.common.testutils.HoodieCommonTestHarness; +import org.apache.hudi.common.testutils.HoodieTestUtils; +import org.apache.hudi.storage.hadoop.HadoopStorageConfiguration; +import org.apache.hudi.timeline.TimelineServiceClient; + +import com.fasterxml.jackson.core.type.TypeReference; +import org.apache.hadoop.conf.Configuration; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static org.apache.hudi.common.config.HoodieStorageConfig.HOODIE_STORAGE_CLASS; +import static org.apache.hudi.common.table.marker.MarkerOperation.CREATE_MARKER_URL; +import static org.apache.hudi.common.table.marker.MarkerOperation.MARKER_DIR_PATH_PARAM; +import static org.apache.hudi.common.table.marker.MarkerOperation.MARKER_NAME_PARAM; +import static org.apache.hudi.common.table.view.RemoteHoodieTableFileSystemView.BASEPATH_PARAM; +import static org.apache.hudi.common.table.view.RemoteHoodieTableFileSystemView.LAST_INSTANT_TS; +import static org.apache.hudi.common.table.view.RemoteHoodieTableFileSystemView.REFRESH_TABLE_URL; +import static org.apache.hudi.common.table.view.RemoteHoodieTableFileSystemView.TIMELINE_HASH; +import static org.apache.hudi.timeline.TimelineServiceClientBase.RequestMethod.POST; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class TestRequestHandler extends HoodieCommonTestHarness { + + public static final char SEPARATOR_CHAR = '/'; Review Comment: nit: use `StoragePath.SEPARATOR_CHAR` -- 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]
