Skip to content

Commit

Permalink
Add prefix for const name
Browse files Browse the repository at this point in the history
  • Loading branch information
ajantha-bhat committed May 26, 2023
1 parent 21bcba6 commit 4b0b203
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public void initialize(String name, Map<String, String> options) {
options.get(NessieConfigConstants.CONF_NESSIE_CLIENT_BUILDER_IMPL))
.fromConfig(x -> options.get(removePrefix.apply(x)));
// default version is set to v1.
final String apiVersion = options.getOrDefault(NessieUtil.CLIENT_API_VERSION, "1");
final String apiVersion =
options.getOrDefault(removePrefix.apply(NessieUtil.CLIENT_API_VERSION), "1");
NessieApiV1 api;
switch (apiVersion) {
case "1":
Expand All @@ -108,7 +109,7 @@ public void initialize(String name, Map<String, String> options) {
throw new IllegalArgumentException(
String.format(
"Unsupported %s: %s. Can only be 1 or 2",
NessieUtil.CLIENT_API_VERSION, apiVersion));
removePrefix.apply(NessieUtil.CLIENT_API_VERSION), apiVersion));
}

initialize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public abstract class BaseTestIceberg {

protected NessieCatalog catalog;
protected NessieApiV1 api;
private NessieApiVersion apiVersion;
protected String apiVersion;
protected Configuration hadoopConfig;
protected final String branch;
private String initialHashOfDefaultBranch;
Expand Down Expand Up @@ -123,7 +123,7 @@ public void beforeEach(NessieClientFactory clientFactory, @NessieClientUri URI n
throws IOException {
this.uri = nessieUri.toASCIIString();
this.api = clientFactory.make();
this.apiVersion = clientFactory.apiVersion();
this.apiVersion = clientFactory.apiVersion() == NessieApiVersion.V2 ? "2" : "1";

Branch defaultBranch = api.getDefaultBranch();
initialHashOfDefaultBranch = defaultBranch.getHash();
Expand All @@ -147,10 +147,8 @@ NessieCatalog initCatalog(String ref, String hash) {
.put("ref", ref)
.put(CatalogProperties.URI, uri)
.put("auth-type", "NONE")
.put(CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString());
if (apiVersion == NessieApiVersion.V2) {
options.put(NessieUtil.CLIENT_API_VERSION, "2");
}
.put(CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString())
.put("client-api-version", apiVersion);
if (null != hash) {
options.put("ref.hash", hash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public void testNoCustomClient() {
CatalogProperties.WAREHOUSE_LOCATION,
temp.toUri().toString(),
CatalogProperties.URI,
uri));
uri,
"client-api-version",
apiVersion));
}

@Test
Expand All @@ -62,7 +64,9 @@ public void testUnnecessaryDefaultCustomClient() {
CatalogProperties.URI,
uri,
NessieConfigConstants.CONF_NESSIE_CLIENT_BUILDER_IMPL,
HttpClientBuilder.class.getName()));
HttpClientBuilder.class.getName(),
"client-api-version",
apiVersion));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private NessieCatalog initNessieCatalog(String ref) {
.put("auth-type", "NONE")
.put(CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString());
if (apiVersion == NessieApiVersion.V2) {
options.put(NessieUtil.CLIENT_API_VERSION, "2");
options.put("client-api-version", "2");
}
newCatalog.initialize("nessie", options.buildOrThrow());
return newCatalog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public void testInvalidClientApiVersion() throws IOException {
try (NessieCatalog newCatalog = new NessieCatalog()) {
newCatalog.setConf(hadoopConfig);
ImmutableMap.Builder<String, String> options =
ImmutableMap.<String, String>builder().put(NessieUtil.CLIENT_API_VERSION, "3");
ImmutableMap.<String, String>builder().put("client-api-version", "3");
Assertions.assertThatThrownBy(() -> newCatalog.initialize("nessie", options.buildOrThrow()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Unsupported nessie.client-api-version: 3. Can only be 1 or 2");
.hasMessage("Unsupported client-api-version: 3. Can only be 1 or 2");
}
}
}

0 comments on commit 4b0b203

Please sign in to comment.