Search in sources :

Example 6 with LogEntry

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);
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata)

Example 7 with LogEntry

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"));
}
Also used : Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Test(org.junit.jupiter.api.Test)

Example 8 with LogEntry

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");
    });
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry)

Example 9 with LogEntry

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);
}
Also used : ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) IcebergTable(org.projectnessie.model.IcebergTable) Put(org.projectnessie.model.Operation.Put) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Test(org.junit.jupiter.api.Test)

Example 10 with LogEntry

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);
    });
}
Also used : Put(org.projectnessie.model.Operation.Put) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Reference(org.projectnessie.model.Reference) NessieConflictException(org.projectnessie.error.NessieConflictException) ArrayList(java.util.ArrayList) Duration(java.time.Duration) Map(java.util.Map) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) SparkSession(org.apache.spark.sql.SparkSession) Operation(org.projectnessie.model.Operation) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Instant(java.time.Instant) NotNull(javax.validation.constraints.NotNull) Objects(java.util.Objects) List(java.util.List) FetchOption(org.projectnessie.api.params.FetchOption) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) CONF_NESSIE_URI(org.projectnessie.client.NessieConfigConstants.CONF_NESSIE_URI) AbstractRest(org.projectnessie.jaxrs.AbstractRest) ContentKey(org.projectnessie.model.ContentKey) Comparator(java.util.Comparator) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Content(org.projectnessie.model.Content) Collection(java.util.Collection) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Put(org.projectnessie.model.Operation.Put)

Aggregations

LogEntry (org.projectnessie.model.LogResponse.LogEntry)17 CommitMeta (org.projectnessie.model.CommitMeta)14 Branch (org.projectnessie.model.Branch)11 IcebergTable (org.projectnessie.model.IcebergTable)9 LogResponse (org.projectnessie.model.LogResponse)9 Test (org.junit.jupiter.api.Test)8 ContentKey (org.projectnessie.model.ContentKey)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Put (org.projectnessie.model.Operation.Put)4 Reference (org.projectnessie.model.Reference)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)3 Content (org.projectnessie.model.Content)3 Instant (java.time.Instant)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2