rdblue commented on code in PR #4495:
URL: https://github.com/apache/iceberg/pull/4495#discussion_r842232889
##########
core/src/main/java/org/apache/iceberg/rest/RESTCatalog.java:
##########
@@ -69,18 +75,66 @@
private Object conf = null;
private FileIO io = null;
+ public RESTCatalog() {
+ this(new HTTPClientFactory());
+ }
+
RESTCatalog(Function<Map<String, String>, RESTClient> clientBuilder) {
this.clientBuilder = clientBuilder;
}
@Override
public void initialize(String name, Map<String, String> props) {
+ Map<String, String> mergedProps = fetchAndMergeWithServerConfig(props);
+ initializeInternal(name, mergedProps);
+ }
+
+ /**
+ * Performs the normal initialization steps after calling the config route
and merging the initial
+ * configuration with any configuration provided by the server.
+ * <p>
+ * See {@link RESTCatalogConfigResponse} for details on merging the initial
client and server configuration.
+ *
+ * @param name Name of this RESTCatalog
+ * @param props Properties to use, merged with any server-provided
configuration.
+ */
+ @VisibleForTesting
+ void initializeInternal(String name, Map<String, String> props) {
Review Comment:
I think we can avoid adding both of these `@VisibleForTesting` methods. To
test, I think you can either update `RESTCatalogAdaptor` to accept a config map
to return, or just pass in a different `RESTClient` when creating a test
catalog. It could be something roughly like this:
```java
@Test
public void testConfigRoute() {
RESTClient testClient = new RESTClient() {
@Override
public void head(String path, Consumer<ErrorResponse> errorHandler) {
throw new UnsupportedOperationException("Should not be called for
testConfigRoute");
}
@Override
public <T extends RESTResponse> T delete(String path, Class<T>
responseType, Consumer<ErrorResponse> errorHandler) {
throw new UnsupportedOperationException("Should not be called for
testConfigRoute");
}
@Override
public <T extends RESTResponse> T get(String path, Class<T>
responseType, Consumer<ErrorResponse> errorHandler) {
}
@Override
public <T extends RESTResponse> T post(String path, RESTRequest body,
Class<T> responseType, Consumer<ErrorResponse> errorHandler) {
throw new UnsupportedOperationException("Should not be called for
testConfigRoute");
}
@Override
public void close() {
}
};
RESTCatalog restCatalog = new RESTCatalog((config) -> testClient);
restCatalog.setConf(new Configuration());
restCatalog.initialize("prod", ImmutableMap.of());
Assert.assertNotNull("Should have config key foo",
restCatalog.properties().get("foo"));
}
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]