Search in sources :

Example 16 with IcebergTable

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

the class AbstractRestCommitLog method commitLogPaging.

@Test
public void commitLogPaging() throws BaseNessieClientServerException {
    Branch branch = createBranch("commitLogPaging");
    int commits = 95;
    int pageSizeHint = 10;
    String currentHash = branch.getHash();
    List<String> allMessages = new ArrayList<>();
    for (int i = 0; i < commits; i++) {
        String msg = "message-for-" + i;
        allMessages.add(msg);
        IcebergTable tableMeta = IcebergTable.of("some-file-" + i, 42, 42, 42, 42);
        String nextHash = getApi().commitMultipleOperations().branchName(branch.getName()).hash(currentHash).commitMeta(CommitMeta.fromMessage(msg)).operation(Put.of(ContentKey.of("table"), tableMeta)).commit().getHash();
        assertNotEquals(currentHash, nextHash);
        currentHash = nextHash;
    }
    Collections.reverse(allMessages);
    verifyPaging(branch.getName(), commits, pageSizeHint, allMessages, null);
    List<CommitMeta> completeLog = StreamingUtil.getCommitLogStream(getApi(), c -> c.refName(branch.getName()).fetch(FetchOption.MINIMAL), OptionalInt.of(pageSizeHint)).map(LogEntry::getCommitMeta).collect(Collectors.toList());
    assertEquals(completeLog.stream().map(CommitMeta::getMessage).collect(Collectors.toList()), allMessages);
}
Also used : Branch(org.projectnessie.model.Branch) ArrayList(java.util.ArrayList) IcebergTable(org.projectnessie.model.IcebergTable) CommitMeta(org.projectnessie.model.CommitMeta) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with IcebergTable

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

the class AbstractRestContents method multiget.

@Test
public void multiget() throws BaseNessieClientServerException {
    Branch branch = createBranch("foo");
    ContentKey a = ContentKey.of("a");
    ContentKey b = ContentKey.of("b");
    IcebergTable ta = IcebergTable.of("path1", 42, 42, 42, 42);
    IcebergTable tb = IcebergTable.of("path2", 42, 42, 42, 42);
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(a, ta)).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(b, tb)).commitMeta(CommitMeta.fromMessage("commit 2")).commit();
    Map<ContentKey, Content> response = getApi().getContent().key(a).key(b).key(ContentKey.of("noexist")).refName("foo").get();
    assertThat(response).containsEntry(a, ta).containsEntry(b, tb).doesNotContainKey(ContentKey.of("noexist"));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with IcebergTable

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

the class AbstractRestDiff method testDiff.

@ParameterizedTest
@MethodSource("diffRefModes")
public void testDiff(ReferenceMode refModeFrom, ReferenceMode refModeTo) throws BaseNessieClientServerException {
    int commitsPerBranch = 10;
    Reference fromRef = getApi().createReference().reference(Branch.of("testDiffFromRef", null)).create();
    Reference toRef = getApi().createReference().reference(Branch.of("testDiffToRef", null)).create();
    String toRefHash = createCommits(toRef, 1, commitsPerBranch, toRef.getHash());
    toRef = Branch.of(toRef.getName(), toRefHash);
    List<DiffEntry> diffOnRefHeadResponse = getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRef)).get().getDiffs();
    // we only committed to toRef, the "from" diff should be null
    assertThat(diffOnRefHeadResponse).hasSize(commitsPerBranch).allSatisfy(diff -> {
        assertThat(diff.getKey()).isNotNull();
        assertThat(diff.getFrom()).isNull();
        assertThat(diff.getTo()).isNotNull();
    });
    // Some combinations with explicit fromHashOnRef/toHashOnRef
    assertThat(getApi().getDiff().fromRefName(fromRef.getName()).fromHashOnRef(fromRef.getHash()).toRefName(toRef.getName()).toHashOnRef(toRef.getHash()).get().getDiffs()).isEqualTo(diffOnRefHeadResponse);
    // result
    if (refModeTo != ReferenceMode.NAME_ONLY) {
        Branch toRefAtFrom = Branch.of(toRef.getName(), fromRef.getHash());
        assertThat(getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRefAtFrom)).get().getDiffs()).isEmpty();
    }
    // after committing to fromRef, "from/to" diffs should both have data
    fromRef = Branch.of(fromRef.getName(), createCommits(fromRef, 1, commitsPerBranch, fromRef.getHash()));
    assertThat(getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRef)).get().getDiffs()).hasSize(commitsPerBranch).allSatisfy(diff -> {
        assertThat(diff.getKey()).isNotNull();
        assertThat(diff.getFrom()).isNotNull();
        assertThat(diff.getTo()).isNotNull();
        // we only have a diff on the ID
        assertThat(diff.getFrom().getId()).isNotEqualTo(diff.getTo().getId());
        Optional<IcebergTable> fromTable = diff.getFrom().unwrap(IcebergTable.class);
        assertThat(fromTable).isPresent();
        Optional<IcebergTable> toTable = diff.getTo().unwrap(IcebergTable.class);
        assertThat(toTable).isPresent();
        assertThat(fromTable.get().getMetadataLocation()).isEqualTo(toTable.get().getMetadataLocation());
        assertThat(fromTable.get().getSchemaId()).isEqualTo(toTable.get().getSchemaId());
        assertThat(fromTable.get().getSnapshotId()).isEqualTo(toTable.get().getSnapshotId());
        assertThat(fromTable.get().getSortOrderId()).isEqualTo(toTable.get().getSortOrderId());
        assertThat(fromTable.get().getSpecId()).isEqualTo(toTable.get().getSpecId());
    });
    List<ContentKey> keys = IntStream.rangeClosed(0, commitsPerBranch).mapToObj(i -> ContentKey.of("table" + i)).collect(Collectors.toList());
    // request all keys and delete the tables for them on toRef
    Map<ContentKey, Content> map = getApi().getContent().refName(toRef.getName()).keys(keys).get();
    for (Map.Entry<ContentKey, Content> entry : map.entrySet()) {
        toRef = getApi().commitMultipleOperations().branchName(toRef.getName()).hash(toRefHash).commitMeta(CommitMeta.fromMessage("delete")).operation(Delete.of(entry.getKey())).commit();
    }
    // now that we deleted all tables on toRef, the diff for "to" should be null
    assertThat(getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRef)).get().getDiffs()).hasSize(commitsPerBranch).allSatisfy(diff -> {
        assertThat(diff.getKey()).isNotNull();
        assertThat(diff.getFrom()).isNotNull();
        assertThat(diff.getTo()).isNull();
    });
}
Also used : IntStream(java.util.stream.IntStream) DiffEntry(org.projectnessie.model.DiffResponse.DiffEntry) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Branch(org.projectnessie.model.Branch) Collectors(java.util.stream.Collectors) Reference(org.projectnessie.model.Reference) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) Delete(org.projectnessie.model.Operation.Delete) IcebergTable(org.projectnessie.model.IcebergTable) Map(java.util.Map) Optional(java.util.Optional) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) CommitMeta(org.projectnessie.model.CommitMeta) MethodSource(org.junit.jupiter.params.provider.MethodSource) Reference(org.projectnessie.model.Reference) ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) Map(java.util.Map) DiffEntry(org.projectnessie.model.DiffResponse.DiffEntry) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 19 with IcebergTable

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

the class AbstractRestGC method commitSingleOp.

CommitOutput commitSingleOp(String prefix, Reference branch, String currentHash, long snapshotId, String contentId, String contentKey, String metadataFile, IcebergTable previous, String beforeRename) throws NessieNotFoundException, NessieConflictException {
    IcebergTable meta = IcebergTable.of(prefix + "_" + metadataFile, snapshotId, 42, 42, 42, prefix + "_" + contentId);
    CommitMultipleOperationsBuilder multiOp = getApi().commitMultipleOperations().branchName(branch.getName()).hash(currentHash).commitMeta(CommitMeta.builder().author("someone").message("some commit").properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Put.of(ContentKey.of(prefix + "_" + contentKey), meta, previous));
    if (beforeRename != null) {
        multiOp.operation(Operation.Delete.of(ContentKey.of(prefix + "_" + beforeRename)));
    }
    String nextHash = multiOp.commit().getHash();
    assertThat(currentHash).isNotEqualTo(nextHash);
    return new CommitOutput(nextHash, meta);
}
Also used : CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) IcebergTable(org.projectnessie.model.IcebergTable)

Example 20 with IcebergTable

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

the class AbstractResteasyTest method testGetContent.

@Test
public void testGetContent() {
    Branch branch = makeBranch("content-test");
    IcebergTable table = IcebergTable.of("content-table1", 42, 42, 42, 42);
    branch = commit(table.getId(), branch, "key1", table.getMetadataLocation());
    Content content = rest().queryParam("ref", branch.getName()).queryParam("hashOnRef", branch.getHash()).get(String.format("contents/%s", "key1")).then().statusCode(200).extract().as(Content.class);
    assertThat(content).isEqualTo(table);
}
Also used : ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) 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