use of org.projectnessie.model.LogResponse.LogEntry 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.LogResponse.LogEntry in project nessie by projectnessie.
the class AbstractRestSecurityContext method committerAndAuthor.
@Test
public void committerAndAuthor(@NessieSecurityContext Consumer<SecurityContext> securityContextConsumer) throws Exception {
Branch main = createBranch("committerAndAuthor");
Branch merge = createBranch("committerAndAuthorMerge");
Branch transplant = createBranch("committerAndAuthorTransplant");
IcebergTable meta1 = IcebergTable.of("meep", 42, 42, 42, 42);
IcebergTable meta2 = IcebergTable.of("meep_meep", 42, 42, 42, 42);
Branch noSecurityContext = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("no security context").build()).operation(Put.of(ContentKey.of("meep"), meta1)).commit();
assertThat(getApi().getCommitLog().reference(noSecurityContext).maxRecords(1).get().getLogEntries()).extracting(LogEntry::getCommitMeta).extracting(CommitMeta::getCommitter, CommitMeta::getAuthor, CommitMeta::getMessage).containsExactly(tuple("", "", "no security context"));
securityContextConsumer.accept(PrincipalSecurityContext.forName("ThatNessieGuy"));
Branch withSecurityContext = getApi().commitMultipleOperations().branchName(noSecurityContext.getName()).hash(noSecurityContext.getHash()).commitMeta(CommitMeta.builder().message("with security").build()).operation(Put.of(ContentKey.of("meep_meep"), meta2)).commit();
assertThat(getApi().getCommitLog().reference(withSecurityContext).maxRecords(2).get().getLogEntries()).extracting(LogEntry::getCommitMeta).extracting(CommitMeta::getCommitter, CommitMeta::getAuthor, CommitMeta::getMessage).containsExactly(tuple("ThatNessieGuy", "ThatNessieGuy", "with security"), tuple("", "", "no security context"));
securityContextConsumer.accept(PrincipalSecurityContext.forName("NessieHerself"));
// Merge
getApi().mergeRefIntoBranch().fromRef(withSecurityContext).branch(merge).merge();
merge = (Branch) getApi().getReference().refName(merge.getName()).get();
assertThat(getApi().getCommitLog().reference(merge).maxRecords(2).get().getLogEntries()).extracting(LogEntry::getCommitMeta).extracting(CommitMeta::getCommitter, CommitMeta::getAuthor, CommitMeta::getMessage).containsExactly(tuple("NessieHerself", "ThatNessieGuy", "with security"), tuple("NessieHerself", "", "no security context"));
// Transplant
getApi().transplantCommitsIntoBranch().fromRefName(withSecurityContext.getName()).hashesToTransplant(Arrays.asList(noSecurityContext.getHash(), withSecurityContext.getHash())).branch(transplant).transplant();
transplant = (Branch) getApi().getReference().refName(transplant.getName()).get();
assertThat(getApi().getCommitLog().reference(transplant).maxRecords(2).get().getLogEntries()).extracting(LogEntry::getCommitMeta).extracting(CommitMeta::getCommitter, CommitMeta::getAuthor, CommitMeta::getMessage).containsExactly(tuple("NessieHerself", "ThatNessieGuy", "with security"), tuple("NessieHerself", "", "no security context"));
}
use of org.projectnessie.model.LogResponse.LogEntry in project iceberg by apache.
the class TestNessieTable method verifyCommitMetadata.
private void verifyCommitMetadata() throws NessieNotFoundException {
// check that the author is properly set
List<LogEntry> log = api.getCommitLog().refName(BRANCH).get().getLogEntries();
Assertions.assertThat(log).isNotNull().isNotEmpty().allSatisfy(logEntry -> {
CommitMeta commit = logEntry.getCommitMeta();
Assertions.assertThat(commit.getAuthor()).isNotNull().isNotEmpty();
Assertions.assertThat(commit.getAuthor()).isEqualTo(System.getProperty("user.name"));
Assertions.assertThat(commit.getProperties().get(NessieUtil.APPLICATION_TYPE)).isEqualTo("iceberg");
Assertions.assertThat(commit.getMessage()).startsWith("Iceberg");
});
}
use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class AbstractCompatibilityTests method commit.
@Test
void commit() throws Exception {
Branch defaultBranch = api.getDefaultBranch();
Branch branch = Branch.of("commitToBranch", defaultBranch.getHash());
Reference created = api.createReference().sourceRefName(defaultBranch.getName()).reference(branch).create();
assertThat(created).isEqualTo(branch);
ContentKey key = ContentKey.of("my", "tables", "table_name");
IcebergTable content = IcebergTable.of("metadata-location", 42L, 43, 44, 45, "content-id");
String commitMessage = "hello world";
Put operation = Put.of(key, content);
Branch branchNew = api.commitMultipleOperations().commitMeta(CommitMeta.fromMessage(commitMessage)).operation(operation).branch(branch).commit();
assertThat(branchNew).isNotEqualTo(branch).extracting(Branch::getName).isEqualTo(branch.getName());
LogResponse commitLog = api.getCommitLog().refName(branch.getName()).get();
assertThat(commitLog.getLogEntries()).hasSize(1).map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).containsExactly(commitMessage);
}
use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class AbstractRestGC method fillExpectedContents.
void fillExpectedContents(Branch branch, int numCommits, IdentifiedResult expected) throws NessieNotFoundException {
fetchLogEntries(branch, numCommits).stream().map(LogEntry::getOperations).filter(Objects::nonNull).flatMap(Collection::stream).filter(op -> op instanceof Put).forEach(op -> {
Content content = ((Put) op).getContent();
expected.addContent(branch.getName(), content);
});
}
Aggregations