Skip to content

Commit

Permalink
Nessie: avoid creating branches without explicit hashes (apache#8372)
Browse files Browse the repository at this point in the history
This commit modifies a few Nessie tests that were
creating branches without explicitly specifying a
target hash.

Nessie will soon forbid such situations, so we are
proactively fixing all their occurrences.
  • Loading branch information
adutra authored Aug 23, 2023
1 parent 6e239bc commit 9df8ddb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void beforeEach(NessieClientFactory clientFactory, @NessieClientUri URI n
Branch defaultBranch = api.getDefaultBranch();
initialHashOfDefaultBranch = defaultBranch.getHash();
if (!branch.equals(defaultBranch.getName())) {
api.createReference().reference(Branch.of(branch, null)).create();
createBranch(branch, initialHashOfDefaultBranch);
}

hadoopConfig = new Configuration();
Expand Down Expand Up @@ -202,6 +202,10 @@ protected static Schema schema(int count) {
return new Schema(Types.StructType.of(fields).fields());
}

void createBranch(String name) throws NessieNotFoundException, NessieConflictException {
createBranch(name, catalog.currentHash());
}

void createBranch(String name, String hash)
throws NessieNotFoundException, NessieConflictException {
createBranch(name, hash, "main");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public TestBranchVisibility() {
public void before() throws NessieNotFoundException, NessieConflictException {
createTable(tableIdentifier1, 1); // table 1
createTable(tableIdentifier2, 1); // table 2
createBranch("test", catalog.currentHash());
createBranch("test");
testCatalog = initCatalog("test");
}

Expand Down Expand Up @@ -447,7 +447,7 @@ private void testCatalogEquality(
@Test
public void testWithRefAndHash() throws NessieConflictException, NessieNotFoundException {
String testBranch = "testBranch";
createBranch(testBranch, null);
createBranch(testBranch);
Schema schema =
new Schema(Types.StructType.of(required(1, "id", Types.LongType.get())).fields());

Expand Down Expand Up @@ -495,8 +495,8 @@ public void testWithRefAndHash() throws NessieConflictException, NessieNotFoundE
public void testDifferentTableSameName() throws NessieConflictException, NessieNotFoundException {
String branch1 = "branch1";
String branch2 = "branch2";
createBranch(branch1, null);
createBranch(branch2, null);
createBranch(branch1);
createBranch(branch2);
Schema schema1 =
new Schema(Types.StructType.of(required(1, "id", Types.LongType.get())).fields());
Schema schema2 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testWithReference() throws NessieNotFoundException {
public void testWithReferenceAfterRecreatingBranch()
throws NessieConflictException, NessieNotFoundException {
String branch = "branchToBeDropped";
createBranch(branch, null);
createBranch(branch);
NessieIcebergClient client = new NessieIcebergClient(api, branch, null, ImmutableMap.of());

// just create a new commit on the branch and then delete & re-create it
Expand All @@ -82,7 +82,7 @@ public void testWithReferenceAfterRecreatingBranch()
.deleteBranch()
.branch((Branch) client.getApi().getReference().refName(branch).get())
.delete();
createBranch(branch, null);
createBranch(branch);

// make sure the client uses the re-created branch
Reference ref = client.getApi().getReference().refName(branch).get();
Expand Down

0 comments on commit 9df8ddb

Please sign in to comment.