flyrain commented on code in PR #402:
URL: https://github.com/apache/polaris/pull/402#discussion_r1817904661


##########
polaris-service/src/test/java/org/apache/polaris/service/catalog/io/TestFileIO.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.polaris.service.catalog.io;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Supplier;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.ManifestFile;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.io.OutputFile;
+
+/**
+ * File IO wrapper used for tests. It measures the number of bytes read, files 
written, and files
+ * deleted. It can inject exceptions during InputFile and OutputFile creation.
+ */
+public class TestFileIO implements FileIO {
+  private final FileIO io;
+
+  // When present, the following will be used to throw exceptions at various 
parts of the IO
+  private final Optional<Supplier<RuntimeException>> 
newInputFileExceptionSupplier;
+  private final Optional<Supplier<RuntimeException>> 
newOutputFileExceptionSupplier;

Review Comment:
   `Optional` is designed for method return value, but not for a class field or 
method parameter. It adds overhead and confusing without much benefits. This 
double-wrapping(`Optional<Supplier<RuntimeException>>`) raises a bit more 
questions:
   1. Is the Supplier optional, or is the result of the supplier function (the 
RuntimeException) optional?
   2. Why does the exception need to be wrapped in a supplier rather than 
passed directly?
   
   Could we use a simpler form like this:
   ```
   RuntimeException newInputFileException;
   ```
   Then we can throw it by checking if it's null:
   ```
   if(newInputFileException != null) throw newInputFileException;
   ```
   Or if you really want to use optional, we can wrap it within a getter like 
this, and invoke it from callers:
   ```
   Optional<RuntimeException> getNewInputFileException(){
      return Optional.ofNullable(newInputFileException);
   } 
   ```
   I think using `null` is perfectly fine here. This simplifies all callers in 
the chain.



##########
polaris-service/src/test/java/org/apache/polaris/service/catalog/TestUtil.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.polaris.service.catalog;
+
+import static 
org.apache.polaris.service.context.DefaultContextResolver.REALM_PROPERTY_KEY;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.common.collect.ImmutableMap;
+import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.Response;
+import java.util.Map;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.catalog.SessionCatalog;
+import org.apache.iceberg.rest.HTTPClient;
+import org.apache.iceberg.rest.RESTCatalog;
+import org.apache.iceberg.rest.auth.OAuth2Properties;
+import org.apache.polaris.core.admin.model.Catalog;
+import org.apache.polaris.core.admin.model.CatalogGrant;
+import org.apache.polaris.core.admin.model.CatalogPrivilege;
+import org.apache.polaris.core.admin.model.CatalogRole;
+import org.apache.polaris.core.admin.model.GrantResource;
+import org.apache.polaris.service.auth.BasePolarisAuthenticator;
+import org.apache.polaris.service.config.PolarisApplicationConfig;
+import org.apache.polaris.service.test.PolarisConnectionExtension;
+import org.apache.polaris.service.test.SnowmanCredentialsExtension;
+
+/** Test utilities for catalog tests */
+public class TestUtil {
+  /**
+   * Performs {@link TestUtil#createSnowmanManagedCatalog(Client, String,
+   * PolarisConnectionExtension.PolarisToken, 
SnowmanCredentialsExtension.SnowmanCredentials,
+   * String, Catalog)} on a Dropwizard instance of Polaris
+   */

Review Comment:
   Minor: Invalid link format. We may just remove the method link. 



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