mchades commented on code in PR #4108: URL: https://github.com/apache/gravitino/pull/4108#discussion_r1673554843
########## api/src/main/java/com/datastrato/gravitino/TestOperations.java: ########## @@ -0,0 +1,93 @@ +/* + * 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 com.datastrato.gravitino; + +import com.datastrato.gravitino.annotation.Evolving; +import com.google.common.base.Preconditions; +import java.util.Map; + +/** + * This interface defines the capability to simulate the operation of a catalog to check for any + * potential issues or validation errors without persisting any data. + */ +@Evolving +public interface TestOperations { + /** + * Test whether a catalog can be created with the specified parameters, without actually creating + * it. + * + * @param catalogName the name of the catalog. + * @param type the type of the catalog. + * @param provider the provider of the catalog. + * @param comment the comment of the catalog. + * @param properties the properties of the catalog. + * @return The test result. + */ + TestResult testCatalogCreation( + String catalogName, + Catalog.Type type, + String provider, + String comment, + Map<String, String> properties); + + /** The result of test operation. */ + interface TestResult { + /** Represent the valid result of the test operation */ + TestResult VALID = new TestResultImpl(true, null); + + /** + * Creates invalid result of the test operation. + * + * @param exception exception to the invalid result + * @return the invalid test result + */ + static TestResult invalid(Exception exception) { + return new TestResultImpl(false, exception); + } + + /** @return true if the operation is valid, false for invalid */ + boolean valid(); + + /** @return The exception encountered during the test operation: */ + Exception exception(); + } + + /** The implementation of TestResult */ + class TestResultImpl implements TestResult { + private boolean valid; + private Exception exception; + + private TestResultImpl(boolean valid, Exception exception) { + Preconditions.checkArgument( + valid || exception != null, "exception is required when valid is false"); + this.valid = valid; + this.exception = exception; + } + + /** @return true if the operation is valid, false for invalid */ + public boolean valid() { + return valid; + } + + /** @return The exception encountered during the test operation: */ + public Exception exception() { + return exception; + } + } +} Review Comment: okay, using `void testConnection(xxxx) throws Exception;` to refactor the API, please help to review when you have time, thanks -- 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]
