Search in sources :

Example 21 with IcebergTable

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

the class AbstractRestAccessCheckDetached method detachedRefAccessChecks.

@Test
public void detachedRefAccessChecks(@NessieAccessChecker Consumer<Function<AccessContext, BatchAccessChecker>> accessCheckerConsumer) throws Exception {
    accessCheckerConsumer.accept(x -> newAccessChecker());
    Branch main = createBranch("committerAndAuthor");
    Branch merge = createBranch("committerAndAuthorMerge");
    Branch transplant = createBranch("committerAndAuthorTransplant");
    IcebergTable meta1 = IcebergTable.of("meep", 42, 42, 42, 42);
    ContentKey key = ContentKey.of("meep");
    Branch mainCommit = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("no security context").build()).operation(Put.of(key, meta1)).commit();
    Branch detachedAsBranch = Branch.of(Detached.REF_NAME, mainCommit.getHash());
    Tag detachedAsTag = Tag.of(Detached.REF_NAME, mainCommit.getHash());
    Detached detached = Detached.of(mainCommit.getHash());
    assertThat(Stream.of(detached, detachedAsBranch, detachedAsTag)).allSatisfy(ref -> assertAll(() -> assertThatThrownBy(() -> getApi().getCommitLog().reference(ref).get()).describedAs("ref='%s', getCommitLog", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(COMMITS_MSG), () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().fromRef(ref).branch(merge).merge()).describedAs("ref='%s', mergeRefIntoBranch", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().fromRefName(ref.getName()).hashesToTransplant(singletonList(ref.getHash())).branch(transplant).transplant()).describedAs("ref='%s', transplantCommitsIntoBranch", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().getEntries().reference(ref).get()).describedAs("ref='%s', getEntries", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(READ_MSG), () -> assertThatThrownBy(() -> getApi().getContent().reference(ref).key(key).get()).describedAs("ref='%s', getContent", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(ENTITIES_MSG), () -> assertThatThrownBy(() -> getApi().getDiff().fromRef(ref).toRef(main).get()).describedAs("ref='%s', getDiff1", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().getDiff().fromRef(main).toRef(ref).get()).describedAs("ref='%s', getDiff2", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG)));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) Tag(org.projectnessie.model.Tag) NessieForbiddenException(org.projectnessie.error.NessieForbiddenException) Detached(org.projectnessie.model.Detached) Test(org.junit.jupiter.api.Test)

Example 22 with IcebergTable

use of org.projectnessie.model.IcebergTable 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 23 with IcebergTable

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

the class AbstractRest method createCommits.

protected String createCommits(Reference branch, int numAuthors, int commitsPerAuthor, String currentHash) throws BaseNessieClientServerException {
    for (int j = 0; j < numAuthors; j++) {
        String author = "author-" + j;
        for (int i = 0; i < commitsPerAuthor; i++) {
            IcebergTable meta = IcebergTable.of("some-file-" + i, 42, 42, 42, 42);
            String nextHash = getApi().commitMultipleOperations().branchName(branch.getName()).hash(currentHash).commitMeta(CommitMeta.builder().author(author).message("committed-by-" + author).properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Put.of(ContentKey.of("table" + i), meta)).commit().getHash();
            assertThat(currentHash).isNotEqualTo(nextHash);
            currentHash = nextHash;
        }
    }
    return currentHash;
}
Also used : IcebergTable(org.projectnessie.model.IcebergTable)

Example 24 with IcebergTable

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

the class ITNativeNessieError method testNullParamViolation.

@Test
void testNullParamViolation() {
    ContentKey k = ContentKey.of("a");
    IcebergTable t = IcebergTable.of("path1", 42, 42, 42, 42);
    assertEquals("Bad Request (HTTP/400): commitMultipleOperations.hash: must not be null", assertThrows(NessieBadRequestException.class, () -> api.commitMultipleOperations().branchName("branchName").operation(Put.of(k, t)).commitMeta(CommitMeta.fromMessage("message")).commit()).getMessage());
}
Also used : ContentKey(org.projectnessie.model.ContentKey) IcebergTable(org.projectnessie.model.IcebergTable) Test(org.junit.jupiter.api.Test) NativeImageTest(io.quarkus.test.junit.NativeImageTest)

Example 25 with IcebergTable

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

the class TestNessieTable method testExistingTableUpdate.

@Test
public void testExistingTableUpdate() {
    Table icebergTable = catalog.loadTable(TABLE_IDENTIFIER);
    // add a column
    icebergTable.updateSchema().addColumn("data", Types.LongType.get()).commit();
    icebergTable = catalog.loadTable(TABLE_IDENTIFIER);
    // Only 2 snapshotFile Should exist and no manifests should exist
    Assertions.assertThat(metadataVersionFiles(TABLE_NAME)).isNotNull().hasSize(2);
    Assertions.assertThat(manifestFiles(TABLE_NAME)).isNotNull().isEmpty();
    Assertions.assertThat(altered.asStruct()).isEqualTo(icebergTable.schema().asStruct());
}
Also used : Table(org.apache.iceberg.Table) IcebergTable(org.projectnessie.model.IcebergTable) Test(org.junit.jupiter.api.Test)

Aggregations

IcebergTable (org.projectnessie.model.IcebergTable)36 Branch (org.projectnessie.model.Branch)25 Test (org.junit.jupiter.api.Test)22 ContentKey (org.projectnessie.model.ContentKey)18 Content (org.projectnessie.model.Content)12 CommitMeta (org.projectnessie.model.CommitMeta)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 LogEntry (org.projectnessie.model.LogResponse.LogEntry)8 Reference (org.projectnessie.model.Reference)8 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Tag (org.projectnessie.model.Tag)7 LogResponse (org.projectnessie.model.LogResponse)6 Map (java.util.Map)5 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)5 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)5 Put (org.projectnessie.model.Operation.Put)5 ArrayList (java.util.ArrayList)4 Stream (java.util.stream.Stream)4 CommitFailedException (org.apache.iceberg.exceptions.CommitFailedException)4