Search in sources :

Example 1 with Tag

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

the class GenerateContent method execute.

@Override
public void execute() throws BaseNessieClientServerException {
    if (runtimeDuration != null) {
        if (runtimeDuration.isZero() || runtimeDuration.isNegative()) {
            throw new ParameterException(spec.commandLine(), "Duration must be absent to greater than zero.");
        }
    }
    Duration perCommitDuration = Optional.ofNullable(runtimeDuration).orElse(Duration.ZERO).dividedBy(numCommits);
    ThreadLocalRandom random = ThreadLocalRandom.current();
    String runStartTime = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss").format(LocalDateTime.now());
    List<ContentKey> tableNames = IntStream.range(0, numTables).mapToObj(i -> ContentKey.of(String.format("create-contents-%s", runStartTime), "contents", Integer.toString(i))).collect(Collectors.toList());
    try (NessieApiV1 api = createNessieApiInstance()) {
        Branch defaultBranch;
        if (defaultBranchName == null) {
            // Use the server's default branch.
            defaultBranch = api.getDefaultBranch();
        } else {
            // Use the specified default branch.
            try {
                defaultBranch = (Branch) api.getReference().refName(defaultBranchName).get();
            } catch (NessieReferenceNotFoundException e) {
                // Create branch if it does not exist.
                defaultBranch = api.getDefaultBranch();
                defaultBranch = (Branch) api.createReference().reference(Branch.of(defaultBranchName, defaultBranch.getHash())).sourceRefName(defaultBranch.getName()).create();
            }
        }
        List<String> branches = new ArrayList<>();
        branches.add(defaultBranch.getName());
        while (branches.size() < branchCount) {
            // Create a new branch
            String newBranchName = "branch-" + runStartTime + "_" + (branches.size() - 1);
            Branch branch = Branch.of(newBranchName, defaultBranch.getHash());
            spec.commandLine().getOut().printf("Creating branch '%s' from '%s' at %s%n", branch.getName(), defaultBranch.getName(), branch.getHash());
            api.createReference().reference(branch).sourceRefName(defaultBranch.getName()).create();
            branches.add(newBranchName);
        }
        spec.commandLine().getOut().printf("Starting contents generation, %d commits...%n", numCommits);
        for (int i = 0; i < numCommits; i++) {
            // Choose a random branch to commit to
            String branchName = branches.get(random.nextInt(branches.size()));
            Branch commitToBranch = (Branch) api.getReference().refName(branchName).get();
            ContentKey tableName = tableNames.get(random.nextInt(tableNames.size()));
            Content tableContents = api.getContent().refName(branchName).key(tableName).get().get(tableName);
            Content newContents = createContents(tableContents, random);
            spec.commandLine().getOut().printf("Committing content-key '%s' to branch '%s' at %s%n", tableName, commitToBranch.getName(), commitToBranch.getHash());
            CommitMultipleOperationsBuilder commit = api.commitMultipleOperations().branch(commitToBranch).commitMeta(CommitMeta.builder().message(String.format("%s table %s on %s, commit #%d of %d", tableContents != null ? "Update" : "Create", tableName, branchName, i, numCommits)).author(System.getProperty("user.name")).authorTime(Instant.now()).build());
            if (newContents instanceof IcebergTable || newContents instanceof IcebergView) {
                commit.operation(Put.of(tableName, newContents, tableContents));
            } else {
                commit.operation(Put.of(tableName, newContents));
            }
            Branch newHead = commit.commit();
            if (random.nextDouble() < newTagProbability) {
                Tag tag = Tag.of("new-tag-" + random.nextLong(), newHead.getHash());
                spec.commandLine().getOut().printf("Creating tag '%s' from '%s' at %s%n", tag.getName(), branchName, tag.getHash());
                api.createReference().reference(tag).sourceRefName(branchName).create();
            }
            try {
                TimeUnit.NANOSECONDS.sleep(perCommitDuration.toNanos());
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                break;
            }
        }
    }
    spec.commandLine().getOut().printf("Done creating contents.%n");
}
Also used : IntStream(java.util.stream.IntStream) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) Put(org.projectnessie.model.Operation.Put) LocalDateTime(java.time.LocalDateTime) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ParameterException(picocli.CommandLine.ParameterException) Spec(picocli.CommandLine.Spec) ArrayList(java.util.ArrayList) Duration(java.time.Duration) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) Command(picocli.CommandLine.Command) Branch(org.projectnessie.model.Branch) ImmutableDeltaLakeTable(org.projectnessie.model.ImmutableDeltaLakeTable) Min(javax.validation.constraints.Min) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) NessieApiV1(org.projectnessie.client.api.NessieApiV1) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) Option(picocli.CommandLine.Option) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) Tag(org.projectnessie.model.Tag) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) CommandSpec(picocli.CommandLine.Model.CommandSpec) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) ArrayList(java.util.ArrayList) Duration(java.time.Duration) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) IcebergView(org.projectnessie.model.IcebergView) ContentKey(org.projectnessie.model.ContentKey) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) IcebergTable(org.projectnessie.model.IcebergTable) ParameterException(picocli.CommandLine.ParameterException) Tag(org.projectnessie.model.Tag) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Example 2 with Tag

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

the class AbstractRestInvalidWithHttp method invalidBranchNames.

@ParameterizedTest
@CsvSource({ "x/" + COMMA_VALID_HASH_1, "abc'" + COMMA_VALID_HASH_1, ".foo" + COMMA_VALID_HASH_2, "abc'def'..'blah" + COMMA_VALID_HASH_2, "abc'de..blah" + COMMA_VALID_HASH_3, "abc'de@{blah" + COMMA_VALID_HASH_3 })
public void invalidBranchNames(String invalidBranchName, String validHash) {
    ContentKey key = ContentKey.of("x");
    Tag tag = Tag.of("valid", validHash);
    String opsCountMsg = ".operations.operations: size must be between 1 and 2147483647";
    assertAll(() -> assertThatThrownBy(() -> getApi().commitMultipleOperations().branchName(invalidBranchName).hash(validHash).commitMeta(CommitMeta.fromMessage("")).commit()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE).hasMessageContaining(opsCountMsg), () -> assertThatThrownBy(() -> getApi().deleteBranch().branchName(invalidBranchName).hash(validHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getCommitLog().refName(invalidBranchName).untilHash(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getEntries().refName(invalidBranchName).hashOnRef(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getReference().refName(invalidBranchName).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().assignTag().tagName(invalidBranchName).hash(validHash).assignTo(tag).assign()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> {
        if (null != getHttpClient()) {
            assertThatThrownBy(() -> getHttpClient().newRequest().path("trees/branch/{branchName}/merge").resolveTemplate("branchName", invalidBranchName).queryParam("expectedHash", validHash).post(null)).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE).hasMessageContaining(".merge: must not be null");
        }
    }, () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().branchName(invalidBranchName).hash(validHash).fromRef(getApi().getDefaultBranch()).merge()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().deleteTag().tagName(invalidBranchName).hash(validHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().branchName(invalidBranchName).hash(validHash).fromRefName("main").hashesToTransplant(singletonList(getApi().getReference().refName("main").get().getHash())).transplant()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().key(key).refName(invalidBranchName).hashOnRef(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().key(key).refName(invalidBranchName).hashOnRef(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getDiff().fromRefName(invalidBranchName).toRefName("main").get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) Tag(org.projectnessie.model.Tag) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Tag

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

the class AbstractRestRefLog method testReflog.

@Test
public void testReflog() throws BaseNessieClientServerException {
    String tagName = "tag1_test_reflog";
    String branch1 = "branch1_test_reflog";
    String branch2 = "branch2_test_reflog";
    String branch3 = "branch3_test_reflog";
    String root = "ref_name_test_reflog";
    List<Tuple> expectedEntries = new ArrayList<>(12);
    // reflog 1: creating the default branch0
    Branch branch0 = createBranch(root);
    expectedEntries.add(Tuple.tuple(root, "CREATE_REFERENCE"));
    // reflog 2: create tag1
    Reference createdTag = getApi().createReference().sourceRefName(branch0.getName()).reference(Tag.of(tagName, branch0.getHash())).create();
    expectedEntries.add(Tuple.tuple(tagName, "CREATE_REFERENCE"));
    // reflog 3: create branch1
    Reference createdBranch1 = getApi().createReference().sourceRefName(branch0.getName()).reference(Branch.of(branch1, branch0.getHash())).create();
    expectedEntries.add(Tuple.tuple(branch1, "CREATE_REFERENCE"));
    // reflog 4: create branch2
    Reference createdBranch2 = getApi().createReference().sourceRefName(branch0.getName()).reference(Branch.of(branch2, branch0.getHash())).create();
    expectedEntries.add(Tuple.tuple(branch2, "CREATE_REFERENCE"));
    // reflog 5: create branch2
    Branch createdBranch3 = (Branch) getApi().createReference().sourceRefName(branch0.getName()).reference(Branch.of(branch3, branch0.getHash())).create();
    expectedEntries.add(Tuple.tuple(branch3, "CREATE_REFERENCE"));
    // reflog 6: commit on default branch0
    IcebergTable meta = IcebergTable.of("meep", 42, 42, 42, 42);
    branch0 = getApi().commitMultipleOperations().branchName(branch0.getName()).hash(branch0.getHash()).commitMeta(CommitMeta.builder().message("dummy commit log").properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Operation.Put.of(ContentKey.of("meep"), meta)).commit();
    expectedEntries.add(Tuple.tuple(root, "COMMIT"));
    // reflog 7: assign tag
    getApi().assignTag().tagName(tagName).hash(createdTag.getHash()).assignTo(branch0).assign();
    expectedEntries.add(Tuple.tuple(tagName, "ASSIGN_REFERENCE"));
    // reflog 8: assign ref
    getApi().assignBranch().branchName(branch1).hash(createdBranch1.getHash()).assignTo(branch0).assign();
    expectedEntries.add(Tuple.tuple(branch1, "ASSIGN_REFERENCE"));
    // reflog 9: merge
    getApi().mergeRefIntoBranch().branchName(branch2).hash(createdBranch2.getHash()).fromRefName(branch1).fromHash(branch0.getHash()).merge();
    expectedEntries.add(Tuple.tuple(branch2, "MERGE"));
    // reflog 10: transplant
    getApi().transplantCommitsIntoBranch().hashesToTransplant(ImmutableList.of(Objects.requireNonNull(branch0.getHash()))).fromRefName(branch1).branch(createdBranch3).transplant();
    expectedEntries.add(Tuple.tuple(branch3, "TRANSPLANT"));
    // reflog 11: delete branch
    getApi().deleteBranch().branchName(branch1).hash(branch0.getHash()).delete();
    expectedEntries.add(Tuple.tuple(branch1, "DELETE_REFERENCE"));
    // reflog 12: delete tag
    getApi().deleteTag().tagName(tagName).hash(branch0.getHash()).delete();
    expectedEntries.add(Tuple.tuple(tagName, "DELETE_REFERENCE"));
    // In the reflog output new entry will be the head. Hence, reverse the expected list
    Collections.reverse(expectedEntries);
    RefLogResponse refLogResponse = getApi().getRefLog().get();
    // verify reflog entries
    assertThat(refLogResponse.getLogEntries().subList(0, 12)).extracting(RefLogResponse.RefLogResponseEntry::getRefName, RefLogResponse.RefLogResponseEntry::getOperation).isEqualTo(expectedEntries);
    // verify pagination (limit and token)
    RefLogResponse refLogResponse1 = getApi().getRefLog().maxRecords(2).get();
    assertThat(refLogResponse1.getLogEntries()).isEqualTo(refLogResponse.getLogEntries().subList(0, 2));
    assertThat(refLogResponse1.isHasMore()).isTrue();
    RefLogResponse refLogResponse2 = getApi().getRefLog().pageToken(refLogResponse1.getToken()).get();
    // should start from the token.
    assertThat(refLogResponse2.getLogEntries().get(0).getRefLogId()).isEqualTo(refLogResponse1.getToken());
    assertThat(refLogResponse2.getLogEntries().subList(0, 10)).isEqualTo(refLogResponse.getLogEntries().subList(2, 12));
    // verify startHash and endHash
    RefLogResponse refLogResponse3 = getApi().getRefLog().fromHash(refLogResponse.getLogEntries().get(10).getRefLogId()).get();
    assertThat(refLogResponse3.getLogEntries().subList(0, 2)).isEqualTo(refLogResponse.getLogEntries().subList(10, 12));
    RefLogResponse refLogResponse4 = getApi().getRefLog().fromHash(refLogResponse.getLogEntries().get(3).getRefLogId()).untilHash(refLogResponse.getLogEntries().get(5).getRefLogId()).get();
    assertThat(refLogResponse4.getLogEntries()).isEqualTo(refLogResponse.getLogEntries().subList(3, 6));
    // use invalid reflog id f1234d75178d892a133a410355a5a990cf75d2f33eba25d575943d4df632f3a4
    // computed using Hash.of(
    // UnsafeByteOperations.unsafeWrap(newHasher().putString("invalid",
    // StandardCharsets.UTF_8).hash().asBytes()));
    assertThatThrownBy(() -> getApi().getRefLog().fromHash("f1234d75178d892a133a410355a5a990cf75d2f33eba25d575943d4df632f3a4").get()).isInstanceOf(NessieRefLogNotFoundException.class).hasMessageContaining("RefLog entry for 'f1234d75178d892a133a410355a5a990cf75d2f33eba25d575943d4df632f3a4' does not exist");
    // verify source hashes for assign reference
    assertThat(refLogResponse.getLogEntries().get(4).getSourceHashes()).isEqualTo(Collections.singletonList(createdBranch1.getHash()));
    // verify source hashes for merge
    assertThat(refLogResponse.getLogEntries().get(3).getSourceHashes()).isEqualTo(Collections.singletonList(branch0.getHash()));
    // verify source hashes for transplant
    assertThat(refLogResponse.getLogEntries().get(2).getSourceHashes()).isEqualTo(Collections.singletonList(branch0.getHash()));
    // test filter with stream
    List<RefLogResponse.RefLogResponseEntry> filteredResult = StreamingUtil.getReflogStream(getApi(), builder -> builder.filter("reflog.operation == 'ASSIGN_REFERENCE' " + "&& reflog.refName == 'tag1_test_reflog'"), OptionalInt.empty()).collect(Collectors.toList());
    assertThat(filteredResult.size()).isEqualTo(1);
    assertThat(filteredResult.get(0)).extracting(RefLogResponse.RefLogResponseEntry::getRefName, RefLogResponse.RefLogResponseEntry::getOperation).isEqualTo(expectedEntries.get(5).toList());
}
Also used : Operation(org.projectnessie.model.Operation) Tuple(org.assertj.core.groups.Tuple) ImmutableMap(com.google.common.collect.ImmutableMap) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Branch(org.projectnessie.model.Branch) OptionalInt(java.util.OptionalInt) Collectors(java.util.stream.Collectors) Reference(org.projectnessie.model.Reference) NessieRefLogNotFoundException(org.projectnessie.error.NessieRefLogNotFoundException) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) StreamingUtil(org.projectnessie.client.StreamingUtil) IcebergTable(org.projectnessie.model.IcebergTable) Tag(org.projectnessie.model.Tag) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) CommitMeta(org.projectnessie.model.CommitMeta) Collections(java.util.Collections) RefLogResponse(org.projectnessie.model.RefLogResponse) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) ArrayList(java.util.ArrayList) IcebergTable(org.projectnessie.model.IcebergTable) RefLogResponse(org.projectnessie.model.RefLogResponse) NessieRefLogNotFoundException(org.projectnessie.error.NessieRefLogNotFoundException) Tuple(org.assertj.core.groups.Tuple) Test(org.junit.jupiter.api.Test)

Example 4 with Tag

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

the class AbstractRestReferences method filterReferences.

@Test
public void filterReferences() throws BaseNessieClientServerException {
    Branch b1 = getApi().commitMultipleOperations().branch(createBranch("refs.branch.1")).commitMeta(CommitMeta.fromMessage("some awkward message")).operation(Put.of(ContentKey.of("hello.world.BaseTable"), IcebergView.of("path1", 1, 1, "Spark", "SELECT ALL THE THINGS"))).commit();
    Branch b2 = getApi().commitMultipleOperations().branch(createBranch("other-development")).commitMeta(CommitMeta.fromMessage("invent awesome things")).operation(Put.of(ContentKey.of("cool.stuff.Caresian"), IcebergView.of("path2", 1, 1, "Spark", "CARTESIAN JOINS ARE AWESOME"))).commit();
    Branch b3 = getApi().commitMultipleOperations().branch(createBranch("archive")).commitMeta(CommitMeta.fromMessage("boring old stuff")).operation(Put.of(ContentKey.of("super.old.Numbers"), IcebergView.of("path3", 1, 1, "Spark", "AGGREGATE EVERYTHING"))).commit();
    Tag t1 = (Tag) getApi().createReference().reference(Tag.of("my-tag", b2.getHash())).sourceRefName(b2.getName()).create();
    assertThat(getApi().getAllReferences().filter("ref.name == 'other-development'").get().getReferences()).hasSize(1).allSatisfy(ref -> assertThat(ref).isInstanceOf(Branch.class).extracting(Reference::getName, Reference::getHash).containsExactly(b2.getName(), b2.getHash()));
    assertThat(getApi().getAllReferences().filter("refType == 'TAG'").get().getReferences()).allSatisfy(ref -> assertThat(ref).isInstanceOf(Tag.class));
    assertThat(getApi().getAllReferences().filter("refType == 'BRANCH'").get().getReferences()).allSatisfy(ref -> assertThat(ref).isInstanceOf(Branch.class));
    assertThat(getApi().getAllReferences().filter("has(refMeta.numTotalCommits) && refMeta.numTotalCommits < 0").get().getReferences()).isEmpty();
    assertThat(getApi().getAllReferences().fetch(FetchOption.ALL).filter("commit.message == 'invent awesome things'").get().getReferences()).hasSize(2).allSatisfy(ref -> assertThat(ref.getName()).isIn(b2.getName(), t1.getName()));
    assertThat(getApi().getAllReferences().fetch(FetchOption.ALL).filter("refType == 'TAG' && commit.message == 'invent awesome things'").get().getReferences()).hasSize(1).allSatisfy(ref -> assertThat(ref.getName()).isEqualTo(t1.getName()));
}
Also used : Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) Tag(org.projectnessie.model.Tag) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Tag

use of org.projectnessie.model.Tag 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)

Aggregations

Tag (org.projectnessie.model.Tag)12 Branch (org.projectnessie.model.Branch)10 Reference (org.projectnessie.model.Reference)8 ContentKey (org.projectnessie.model.ContentKey)7 Test (org.junit.jupiter.api.Test)6 IcebergTable (org.projectnessie.model.IcebergTable)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)4 NessieBadRequestException (org.projectnessie.error.NessieBadRequestException)4 CommitMeta (org.projectnessie.model.CommitMeta)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Optional (java.util.Optional)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)3 AfterEach (org.junit.jupiter.api.AfterEach)3 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)3 LogResponse (org.projectnessie.model.LogResponse)3 Put (org.projectnessie.model.Operation.Put)3