Skip to content

Commit

Permalink
Address new comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ajantha-bhat committed May 20, 2023
1 parent 66fffef commit 8e046ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,15 @@ public void initialize(String name, Map<String, String> options) {
.fromConfig(x -> options.get(removePrefix.apply(x)));
final String apiVersion = options.get(NessieUtil.CLIENT_API_VERSION);
NessieApiV1 api;
if (apiVersion == null || apiVersion.equalsIgnoreCase("v1")) {
if (apiVersion == null || apiVersion.equalsIgnoreCase("1")) {
// default version is set to v1.
api = nessieClientBuilder.build(NessieApiV1.class);
} else if (apiVersion.equalsIgnoreCase("v2")) {
} else if (apiVersion.equalsIgnoreCase("2")) {
api = nessieClientBuilder.build(NessieApiV2.class);
} else {
throw new IllegalArgumentException(
String.format(
"Unsupported %s: %s. Can only be v1 or v2",
NessieUtil.CLIENT_API_VERSION, apiVersion));
"Unsupported %s: %s. Can only be 1 or 2", NessieUtil.CLIENT_API_VERSION, apiVersion));
}

initialize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
import org.projectnessie.client.api.NessieApiV1;
import org.projectnessie.client.api.NessieApiV2;
import org.projectnessie.client.ext.NessieApiVersion;
import org.projectnessie.client.ext.NessieApiVersions;
import org.projectnessie.client.ext.NessieClientFactory;
import org.projectnessie.client.ext.NessieClientUri;
Expand Down Expand Up @@ -88,6 +88,7 @@ public abstract class BaseTestIceberg {

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

Branch defaultBranch = api.getDefaultBranch();
initialHashOfDefaultBranch = defaultBranch.getHash();
Expand All @@ -146,8 +148,8 @@ NessieCatalog initCatalog(String ref, String hash) {
.put(CatalogProperties.URI, uri)
.put("auth-type", "NONE")
.put(CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString());
if (api instanceof NessieApiV2) {
options.put(NessieUtil.CLIENT_API_VERSION, "v2");
if (apiVersion == NessieApiVersion.V2) {
options.put(NessieUtil.CLIENT_API_VERSION, "2");
}
if (null != hash) {
options.put("ref.hash", hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
import org.projectnessie.client.api.NessieApiV1;
import org.projectnessie.client.api.NessieApiV2;
import org.projectnessie.client.ext.NessieApiVersion;
import org.projectnessie.client.ext.NessieApiVersions;
import org.projectnessie.client.ext.NessieClientFactory;
import org.projectnessie.client.ext.NessieClientUri;
Expand Down Expand Up @@ -67,6 +67,7 @@ public class TestNessieCatalog extends CatalogTests<NessieCatalog> {

private NessieCatalog catalog;
private NessieApiV1 api;
private NessieApiVersion apiVersion;
private Configuration hadoopConfig;
private String initialHashOfDefaultBranch;
private String uri;
Expand All @@ -75,6 +76,7 @@ public class TestNessieCatalog extends CatalogTests<NessieCatalog> {
public void setUp(NessieClientFactory clientFactory, @NessieClientUri URI nessieUri)
throws NessieNotFoundException {
api = clientFactory.make();
apiVersion = clientFactory.apiVersion();
initialHashOfDefaultBranch = api.getDefaultBranch().getHash();
uri = nessieUri.toASCIIString();
hadoopConfig = new Configuration();
Expand Down Expand Up @@ -121,8 +123,8 @@ private NessieCatalog initNessieCatalog(String ref) {
.put(CatalogProperties.URI, uri)
.put("auth-type", "NONE")
.put(CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString());
if (api instanceof NessieApiV2) {
options.put(NessieUtil.CLIENT_API_VERSION, "v2");
if (apiVersion == NessieApiVersion.V2) {
options.put(NessieUtil.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, "v3");
ImmutableMap.<String, String>builder().put(NessieUtil.CLIENT_API_VERSION, "3");
Assertions.assertThatThrownBy(() -> newCatalog.initialize("nessie", options.buildOrThrow()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Unsupported client-api-version: v3. Can only be v1 or v2");
.hasMessage("Unsupported client-api-version: 3. Can only be 1 or 2");
}
}
}

0 comments on commit 8e046ae

Please sign in to comment.