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();
});
}
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);
}
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();
}
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);
}
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");
}
Aggregations