Search in sources :

Example 1 with DiffEntry

use of org.projectnessie.model.DiffResponse.DiffEntry 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 2 with DiffEntry

use of org.projectnessie.model.DiffResponse.DiffEntry 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)

Aggregations

Branch (org.projectnessie.model.Branch)2 ContentKey (org.projectnessie.model.ContentKey)2 DiffEntry (org.projectnessie.model.DiffResponse.DiffEntry)2 IcebergTable (org.projectnessie.model.IcebergTable)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)1 CommitMeta (org.projectnessie.model.CommitMeta)1 Content (org.projectnessie.model.Content)1 DiffResponse (org.projectnessie.model.DiffResponse)1 ImmutableBranch (org.projectnessie.model.ImmutableBranch)1