Search in sources :

Example 16 with CommitMeta

use of org.projectnessie.model.CommitMeta 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 17 with CommitMeta

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

the class AbstractRestReferences method verifyMetadataProperties.

void verifyMetadataProperties(int expectedCommitsAhead, int expectedCommitsBehind, Branch branch, Reference reference, long expectedCommits) throws NessieNotFoundException {
    List<LogEntry> commits = getApi().getCommitLog().refName(branch.getName()).maxRecords(1).get().getLogEntries();
    assertThat(commits).hasSize(1);
    CommitMeta commitMeta = commits.get(0).getCommitMeta();
    ReferenceMetadata referenceMetadata = branch.getMetadata();
    assertThat(referenceMetadata).isNotNull();
    assertThat(referenceMetadata.getNumCommitsAhead()).isEqualTo(expectedCommitsAhead);
    assertThat(referenceMetadata.getNumCommitsBehind()).isEqualTo(expectedCommitsBehind);
    assertThat(referenceMetadata.getCommitMetaOfHEAD()).isEqualTo(commitMeta);
    assertThat(referenceMetadata.getCommonAncestorHash()).isEqualTo(reference.getHash());
    assertThat(referenceMetadata.getNumTotalCommits()).isEqualTo(expectedCommits);
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata)

Example 18 with CommitMeta

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

the class BaseApiImpl method commitMetaUpdate.

protected Function<CommitMeta, CommitMeta> commitMetaUpdate() {
    // Used for setting contextual commit properties during new and merge/transplant commits.
    // WARNING: ONLY SET PROPERTIES, WHICH APPLY COMMONLY TO ALL COMMIT TYPES.
    Principal principal = getPrincipal();
    String committer = principal == null ? "" : principal.getName();
    Instant now = Instant.now();
    return commitMeta -> commitMeta.toBuilder().committer(committer).commitTime(now).author(commitMeta.getAuthor() == null ? committer : commitMeta.getAuthor()).authorTime(commitMeta.getAuthorTime() == null ? now : commitMeta.getAuthorTime()).build();
}
Also used : DetachedRef(org.projectnessie.versioned.DetachedRef) NamedRef(org.projectnessie.versioned.NamedRef) ServerConfig(org.projectnessie.services.config.ServerConfig) Hash(org.projectnessie.versioned.Hash) Authorizer(org.projectnessie.services.authz.Authorizer) BatchAccessChecker(org.projectnessie.services.authz.BatchAccessChecker) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) Function(java.util.function.Function) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) GetNamedRefsParams(org.projectnessie.versioned.GetNamedRefsParams) Objects(java.util.Objects) ServerAccessContext(org.projectnessie.services.authz.ServerAccessContext) Principal(java.security.Principal) VersionStore(org.projectnessie.versioned.VersionStore) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Optional(java.util.Optional) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Nullable(javax.annotation.Nullable) WithHash(org.projectnessie.versioned.WithHash) Instant(java.time.Instant) Principal(java.security.Principal)

Example 19 with CommitMeta

use of org.projectnessie.model.CommitMeta in project iceberg by apache.

the class NessieUtilTest method testSparkAppIdAndUserIsSetOnCommitMetadata.

@Test
public void testSparkAppIdAndUserIsSetOnCommitMetadata() {
    String commitMsg = "commit msg";
    String appId = "SPARK_ID_123";
    String user = "sparkUser";
    CommitMeta commitMeta = NessieUtil.buildCommitMetadata(commitMsg, ImmutableMap.of(CatalogProperties.APP_ID, appId, CatalogProperties.USER, user));
    Assertions.assertThat(commitMeta.getMessage()).isEqualTo(commitMsg);
    Assertions.assertThat(commitMeta.getAuthor()).isEqualTo(user);
    Assertions.assertThat(commitMeta.getProperties()).hasSize(2);
    Assertions.assertThat(commitMeta.getProperties().get(NessieUtil.APPLICATION_TYPE)).isEqualTo("iceberg");
    Assertions.assertThat(commitMeta.getProperties().get(CatalogProperties.APP_ID)).isEqualTo(appId);
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) Test(org.junit.jupiter.api.Test)

Example 20 with CommitMeta

use of org.projectnessie.model.CommitMeta in project iceberg by apache.

the class NessieUtilTest method testAuthorIsSetOnCommitMetadata.

@Test
public void testAuthorIsSetOnCommitMetadata() {
    String commitMsg = "commit msg";
    CommitMeta commitMeta = NessieUtil.buildCommitMetadata(commitMsg, ImmutableMap.of());
    Assertions.assertThat(commitMeta.getMessage()).isEqualTo(commitMsg);
    Assertions.assertThat(commitMeta.getAuthor()).isEqualTo(System.getProperty("user.name"));
    Assertions.assertThat(commitMeta.getProperties()).hasSize(1);
    Assertions.assertThat(commitMeta.getProperties().get(NessieUtil.APPLICATION_TYPE)).isEqualTo("iceberg");
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) Test(org.junit.jupiter.api.Test)

Aggregations

CommitMeta (org.projectnessie.model.CommitMeta)37 Branch (org.projectnessie.model.Branch)17 LogEntry (org.projectnessie.model.LogResponse.LogEntry)15 Test (org.junit.jupiter.api.Test)14 IcebergTable (org.projectnessie.model.IcebergTable)14 ContentKey (org.projectnessie.model.ContentKey)13 LogResponse (org.projectnessie.model.LogResponse)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Content (org.projectnessie.model.Content)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)8 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)8 Reference (org.projectnessie.model.Reference)7 ArrayList (java.util.ArrayList)6 Entry (org.projectnessie.model.EntriesResponse.Entry)6 Operation (org.projectnessie.model.Operation)6 Put (org.projectnessie.model.Operation.Put)6 Stream (java.util.stream.Stream)5