Search in sources :

Example 31 with IcebergTable

use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.

the class AbstractRestMergeTransplant method mergeWithNamespaces.

@ParameterizedTest
@EnumSource(value = ReferenceMode.class, mode = Mode.EXCLUDE, // merge requires the hash
names = "NAME_ONLY")
public void mergeWithNamespaces(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch base = createBranch("merge-base");
    Branch branch = createBranch("merge-branch");
    Namespace ns = Namespace.parse("a.b.c");
    // create the same namespace on both branches
    getApi().createNamespace().namespace(ns).refName(branch.getName()).create();
    getApi().createNamespace().namespace(ns).refName(base.getName()).create();
    IcebergTable table1 = IcebergTable.of("merge-table1", 42, 42, 42, 42);
    IcebergTable table2 = IcebergTable.of("merge-table2", 43, 43, 43, 43);
    ContentKey key1 = ContentKey.of(ns, "key1");
    ContentKey key2 = ContentKey.of(ns, "key2");
    Branch committed1 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch1")).operation(Put.of(key1, table1)).commit();
    assertThat(committed1.getHash()).isNotNull();
    Branch committed2 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(committed1.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch2")).operation(Put.of(key1, table1, table1)).commit();
    assertThat(committed2.getHash()).isNotNull();
    getApi().commitMultipleOperations().branchName(base.getName()).hash(base.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-main")).operation(Put.of(key2, table2)).commit();
    getApi().mergeRefIntoBranch().branch(base).fromRef(refMode.transform(committed2)).merge();
    LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
    assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("test-merge-branch2", "test-merge-branch1", "create namespace a.b.c", "test-merge-main", "create namespace a.b.c");
    assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(Entry::getName)).containsExactlyInAnyOrder(key1, key2, ContentKey.of(ns.getElements()));
    assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
Also used : ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) CommitMeta(org.projectnessie.model.CommitMeta) Namespace(org.projectnessie.model.Namespace) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with IcebergTable

use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.

the class AbstractRestReferences method referenceNames.

@ParameterizedTest
@ValueSource(strings = { "normal", "with-no_space", "slash/thing" })
public void referenceNames(String refNamePart) throws BaseNessieClientServerException {
    String tagName = "tag" + refNamePart;
    String branchName = "branch" + refNamePart;
    String branchName2 = "branch2" + refNamePart;
    String root = "ref_name_" + refNamePart.replaceAll("[^a-z]", "");
    Branch main = createBranch(root);
    IcebergTable meta = IcebergTable.of("meep", 42, 42, 42, 42);
    main = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("common-merge-ancestor").properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Operation.Put.of(ContentKey.of("meep"), meta)).commit();
    String someHash = main.getHash();
    Reference createdTag = getApi().createReference().sourceRefName(main.getName()).reference(Tag.of(tagName, someHash)).create();
    assertEquals(Tag.of(tagName, someHash), createdTag);
    Reference createdBranch1 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName, someHash)).create();
    assertEquals(Branch.of(branchName, someHash), createdBranch1);
    Reference createdBranch2 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName2, someHash)).create();
    assertEquals(Branch.of(branchName2, someHash), createdBranch2);
    Map<String, Reference> references = getApi().getAllReferences().get().getReferences().stream().filter(r -> root.equals(r.getName()) || r.getName().endsWith(refNamePart)).collect(Collectors.toMap(Reference::getName, Function.identity()));
    assertThat(references).containsAllEntriesOf(ImmutableMap.of(main.getName(), main, createdTag.getName(), createdTag, createdBranch1.getName(), createdBranch1, createdBranch2.getName(), createdBranch2));
    assertThat(references.get(main.getName())).isInstanceOf(Branch.class);
    assertThat(references.get(createdTag.getName())).isInstanceOf(Tag.class);
    assertThat(references.get(createdBranch1.getName())).isInstanceOf(Branch.class);
    assertThat(references.get(createdBranch2.getName())).isInstanceOf(Branch.class);
    Reference tagRef = references.get(tagName);
    Reference branchRef = references.get(branchName);
    Reference branchRef2 = references.get(branchName2);
    String tagHash = tagRef.getHash();
    String branchHash = branchRef.getHash();
    String branchHash2 = branchRef2.getHash();
    assertThat(getApi().getReference().refName(tagName).get()).isEqualTo(tagRef);
    assertThat(getApi().getReference().refName(branchName).get()).isEqualTo(branchRef);
    EntriesResponse entries = getApi().getEntries().refName(tagName).get();
    assertThat(entries).isNotNull();
    entries = getApi().getEntries().refName(branchName).get();
    assertThat(entries).isNotNull();
    LogResponse log = getApi().getCommitLog().refName(tagName).get();
    assertThat(log).isNotNull();
    log = getApi().getCommitLog().refName(branchName).get();
    assertThat(log).isNotNull();
    // Need to have at least one op, otherwise all following operations (assignTag/Branch, merge,
    // delete) will fail
    meta = IcebergTable.of("foo", 42, 42, 42, 42);
    getApi().commitMultipleOperations().branchName(branchName).hash(branchHash).operation(Put.of(ContentKey.of("some-key"), meta)).commitMeta(CommitMeta.fromMessage("One dummy op")).commit();
    log = getApi().getCommitLog().refName(branchName).get();
    String newHash = log.getLogEntries().get(0).getCommitMeta().getHash();
    getApi().assignTag().tagName(tagName).hash(tagHash).assignTo(Branch.of(branchName, newHash)).assign();
    getApi().assignBranch().branchName(branchName).hash(newHash).assignTo(Branch.of(branchName, newHash)).assign();
    getApi().mergeRefIntoBranch().branchName(branchName2).hash(branchHash2).fromRefName(branchName).fromHash(newHash).merge();
}
Also used : ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Function(java.util.function.Function) Reference(org.projectnessie.model.Reference) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMeta(org.projectnessie.model.CommitMeta) ValueSource(org.junit.jupiter.params.provider.ValueSource) Operation(org.projectnessie.model.Operation) ImmutableMap(com.google.common.collect.ImmutableMap) Validation(org.projectnessie.model.Validation) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) EntriesResponse(org.projectnessie.model.EntriesResponse) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FetchOption(org.projectnessie.api.params.FetchOption) Stream(java.util.stream.Stream) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) Optional(java.util.Optional) Tag(org.projectnessie.model.Tag) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) EntriesResponse(org.projectnessie.model.EntriesResponse) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) IcebergTable(org.projectnessie.model.IcebergTable) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with IcebergTable

use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.

the class AbstractResteasyTest method testGetRefLog.

@Test
public void testGetRefLog() {
    Branch branch = makeBranch("branch-temp");
    IcebergTable table = IcebergTable.of("content-table", 42, 42, 42, 42);
    ContentKey contentKey = ContentKey.of("key1");
    commit(contentKey, table, branch, "code");
    RefLogResponse refLogResponse = rest().get("reflogs").then().statusCode(200).extract().as(RefLogResponse.class);
    assertThat(refLogResponse.getLogEntries().get(0).getOperation()).isEqualTo("COMMIT");
    assertThat(refLogResponse.getLogEntries().get(0).getRefName()).isEqualTo("branch-temp");
    assertThat(refLogResponse.getLogEntries().get(1).getOperation()).isEqualTo("CREATE_REFERENCE");
    assertThat(refLogResponse.getLogEntries().get(1).getRefName()).isEqualTo("branch-temp");
    RefLogResponse refLogResponse1 = rest().queryParam("endHash", refLogResponse.getLogEntries().get(1).getRefLogId()).get("reflogs").then().statusCode(200).extract().as(RefLogResponse.class);
    assertThat(refLogResponse1.getLogEntries().get(0).getRefLogId()).isEqualTo(refLogResponse.getLogEntries().get(1).getRefLogId());
}
Also used : ContentKey(org.projectnessie.model.ContentKey) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) RefLogResponse(org.projectnessie.model.RefLogResponse) Test(org.junit.jupiter.api.Test)

Example 34 with IcebergTable

use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.

the class AbstractResteasyTest method testGetDiff.

@Test
public void testGetDiff() {
    Branch fromBranch = makeBranch("getdiff-test-from");
    Branch toBranch = makeBranch("getdiff-test-to");
    IcebergTable fromTable = IcebergTable.of("content-table", 42, 42, 42, 42);
    IcebergTable toTable = IcebergTable.of("content-table", 43, 43, 43, 43);
    ContentKey contentKey = ContentKey.of("key1");
    commit(contentKey, fromTable, fromBranch, "diffAuthor");
    commit(contentKey, toTable, toBranch, "diffAuthor2");
    DiffResponse diffResponse = rest().get(String.format("diffs/%s...%s", fromBranch.getName(), toBranch.getName())).then().statusCode(200).extract().as(DiffResponse.class);
    assertThat(diffResponse).isNotNull();
    assertThat(diffResponse.getDiffs()).hasSize(1);
    DiffEntry diff = diffResponse.getDiffs().get(0);
    assertThat(diff.getKey()).isEqualTo(contentKey);
    assertThat(diff.getFrom()).isEqualTo(fromTable);
    assertThat(diff.getTo()).isEqualTo(toTable);
}
Also used : ContentKey(org.projectnessie.model.ContentKey) DiffResponse(org.projectnessie.model.DiffResponse) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) DiffEntry(org.projectnessie.model.DiffResponse.DiffEntry) Test(org.junit.jupiter.api.Test)

Example 35 with IcebergTable

use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.

the class AbstractResteasyTest method testBasic.

@Test
public void testBasic() {
    int preSize = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class).getReferences().size();
    rest().get("trees/tree/mainx").then().statusCode(404);
    rest().body(Branch.of("mainx", null)).post("trees/tree").then().statusCode(200);
    ReferencesResponse references = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class);
    Assertions.assertEquals(preSize + 1, references.getReferences().size());
    Reference reference = rest().get("trees/tree/mainx").then().statusCode(200).extract().as(Reference.class);
    assertEquals("mainx", reference.getName());
    Branch newReference = ImmutableBranch.builder().hash(reference.getHash()).name("test").build();
    rest().queryParam("expectedHash", reference.getHash()).body(Branch.of("test", null)).post("trees/tree").then().statusCode(200);
    assertEquals(newReference, rest().get("trees/tree/test").then().statusCode(200).extract().as(Branch.class));
    IcebergTable table = IcebergTable.of("/the/directory/over/there", 42, 42, 42, 42);
    Branch commitResponse = rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", newReference.getHash()).post("trees/branch/{branch}/commit", newReference.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(newReference.getHash(), commitResponse.getHash());
    Put[] updates = new Put[11];
    for (int i = 0; i < 10; i++) {
        updates[i] = ImmutablePut.builder().key(ContentKey.of("item", Integer.toString(i))).content(IcebergTable.of("/the/directory/over/there/" + i, 42, 42, 42, 42)).build();
    }
    updates[10] = ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(IcebergTable.of("/the/directory/over/there/has/been/moved", 42, 42, 42, 42)).build();
    Reference branch = rest().get("trees/tree/test").as(Reference.class);
    Operations contents = ImmutableOperations.builder().addOperations(updates).commitMeta(CommitMeta.fromMessage("")).build();
    commitResponse = rest().body(contents).queryParam("expectedHash", branch.getHash()).post("trees/branch/{branch}/commit", branch.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(branch.getHash(), commitResponse.getHash());
    Response res = rest().queryParam("ref", "test").get("contents/xxx.test").then().extract().response();
    Assertions.assertEquals(updates[10].getContent(), res.body().as(Content.class));
    IcebergTable currentTable = table;
    table = IcebergTable.of("/the/directory/over/there/has/been/moved/again", 42, 42, 42, 42, table.getId());
    Branch b2 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).expectedContent(currentTable).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", b2.getHash()).post("trees/branch/{branch}/commit", b2.getName()).then().statusCode(200).extract().as(Branch.class);
    Content returned = rest().queryParam("ref", "test").get("contents/xxx.test").then().statusCode(200).extract().as(Content.class);
    Assertions.assertEquals(table, returned);
    Branch b3 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(Tag.of("tagtest", b3.getHash())).queryParam("sourceRefName", b3.getName()).post("trees/tree").then().statusCode(200);
    assertThat(rest().get("trees/tree/tagtest").then().statusCode(200).extract().body().as(Tag.class).getHash()).isEqualTo(b3.getHash());
    rest().queryParam("expectedHash", "0011223344556677889900112233445566778899001122334455667788990011".substring(0, b2.getHash().length())).delete("trees/tag/tagtest").then().statusCode(409);
    rest().queryParam("expectedHash", b3.getHash()).delete("trees/tag/tagtest").then().statusCode(204);
    LogResponse log = rest().get("trees/tree/test/log").then().statusCode(200).extract().as(LogResponse.class);
    Assertions.assertEquals(3, log.getLogEntries().size());
    Branch b1 = rest().get("trees/tree/test").as(Branch.class);
    rest().queryParam("expectedHash", b1.getHash()).delete("trees/branch/test").then().statusCode(204);
    Branch bx = rest().get("trees/tree/mainx").as(Branch.class);
    rest().queryParam("expectedHash", bx.getHash()).delete("trees/branch/mainx").then().statusCode(204);
}
Also used : LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Response(io.restassured.response.Response) DiffResponse(org.projectnessie.model.DiffResponse) LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) Reference(org.projectnessie.model.Reference) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Tag(org.projectnessie.model.Tag) ImmutableOperations(org.projectnessie.model.ImmutableOperations) Operations(org.projectnessie.model.Operations) Put(org.projectnessie.model.Operation.Put) ImmutablePut(org.projectnessie.model.ImmutablePut) Test(org.junit.jupiter.api.Test)

Aggregations

IcebergTable (org.projectnessie.model.IcebergTable)36 Branch (org.projectnessie.model.Branch)25 Test (org.junit.jupiter.api.Test)22 ContentKey (org.projectnessie.model.ContentKey)18 Content (org.projectnessie.model.Content)12 CommitMeta (org.projectnessie.model.CommitMeta)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 LogEntry (org.projectnessie.model.LogResponse.LogEntry)8 Reference (org.projectnessie.model.Reference)8 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Tag (org.projectnessie.model.Tag)7 LogResponse (org.projectnessie.model.LogResponse)6 Map (java.util.Map)5 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)5 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)5 Put (org.projectnessie.model.Operation.Put)5 ArrayList (java.util.ArrayList)4 Stream (java.util.stream.Stream)4 CommitFailedException (org.apache.iceberg.exceptions.CommitFailedException)4