Search in sources :

Example 31 with Branch

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

the class AbstractRestGCTest method testMultiRefMultipleSharedTables.

@Test
public void testMultiRefMultipleSharedTables() throws BaseNessieClientServerException {
    // ------  Time ---- | --- branch1 -----| ---- branch2 -----| --- branch3 ------------- |
    // t0        | create branch    |                   |                           |
    // t1        | TABLE_ONE : 42   | {TABLE_ONE : 42}  | {TABLE_ONE : 42}          |
    // t2        |                  |  create branch    |                           |
    // t3        | TABLE_TWO : 42   |                   | {TABLE_TWO : 42}          |
    // t4        |                  |                   | create branch             |
    // t5        |                  |                   | TABLE_THREE : 42 (expired)|
    // t6        |                  |  TABLE_ONE : 43   |                           |
    // t7        | DROP TABLE_ONE   |                   |                           |
    // t8        |                  |                   | DROP TABLE_TWO            |
    // t9        |                  |                   | DROP TABLE_THREE          |
    // t10       |-- cut off time --|-- cut off time -- |-- cut off time -- --------|
    // t11       |  TABLE_TWO : 44  |                   |                           |
    // t12       |                  |                   | TABLE_ONE : 44            |
    String prefix = "multiRefMultipleSharedTables";
    IdentifiedResult expectedResult = new IdentifiedResult();
    Branch branch1 = createBranch(prefix + "_1");
    // commit on branch1
    CommitOutput b1table1 = commitSingleOp(prefix, branch1, branch1.getHash(), 42, CID_ONE, TABLE_ONE, METADATA_ONE, null, null);
    Branch branch2 = createBranch(prefix + "_2", Branch.of(branch1.getName(), b1table1.hash));
    // commit on branch1
    CommitOutput b1table2 = commitSingleOp(prefix, branch1, b1table1.hash, 42, CID_TWO, TABLE_TWO, METADATA_ONE, null, null);
    Branch branch3 = createBranch(prefix + "_3", Branch.of(branch1.getName(), b1table2.hash));
    // commit on branch3
    CommitOutput b3table3 = commitSingleOp(prefix, branch3, branch3.getHash(), 42, CID_THREE, TABLE_THREE, METADATA_ONE, null, null);
    // expect to be expired as this table is dropped before cutoff time.
    fillExpectedContents(Branch.of(branch3.getName(), b3table3.hash), 1, expectedResult);
    // commit on branch2
    CommitOutput b2table1 = commitSingleOp(prefix, branch2, branch2.getHash(), 43, CID_ONE, TABLE_ONE, METADATA_TWO, b1table1.content, null);
    CommitOutput b1 = dropTableCommit(prefix, branch1, b1table2.hash, TABLE_ONE);
    CommitOutput b3 = dropTableCommit(prefix, branch3, b3table3.hash, TABLE_TWO);
    b3 = dropTableCommit(prefix, branch3, b3.hash, TABLE_THREE);
    final Instant cutoffTime = Instant.now();
    // commit for TABLE_TWO on branch1
    b1table1 = commitSingleOp(prefix, branch1, b1.hash, 44, CID_TWO, TABLE_TWO, METADATA_THREE, b1table2.content, null);
    // commit for TABLE_ONE on branch3
    CommitOutput b3table1 = commitSingleOp(prefix, branch3, b3.hash, 44, CID_ONE, TABLE_ONE, METADATA_FIVE, b2table1.content, null);
    performGc(cutoffTime, null, expectedResult, Arrays.asList(branch1.getName(), branch2.getName(), branch3.getName()), true, null);
}
Also used : Branch(org.projectnessie.model.Branch) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 32 with Branch

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

the class AbstractResteasyTest method testGetContent.

@Test
public void testGetContent() {
    Branch branch = makeBranch("content-test");
    IcebergTable table = IcebergTable.of("content-table1", 42, 42, 42, 42);
    branch = commit(table.getId(), branch, "key1", table.getMetadataLocation());
    Content content = rest().queryParam("ref", branch.getName()).queryParam("hashOnRef", branch.getHash()).get(String.format("contents/%s", "key1")).then().statusCode(200).extract().as(Content.class);
    assertThat(content).isEqualTo(table);
}
Also used : ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) Test(org.junit.jupiter.api.Test)

Example 33 with Branch

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

the class AbstractResteasyTest method testLogFiltering.

@Test
public void testLogFiltering() {
    String branchName = "logFiltering";
    makeBranch(branchName);
    Branch branch = getBranch(branchName);
    int numCommits = 3;
    String contentId = "cid-test-log-filtering";
    for (int i = 0; i < numCommits; i++) {
        String newHash = commit(contentId, branch, "xxx.test", "/the/directory/over/there", "author-" + i, i > 0 ? "/the/directory/over/there" : null).getHash();
        assertThat(newHash).isNotEqualTo(branch.getHash());
        branch = getBranch(branchName);
    }
    LogResponse log = rest().get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
    assertThat(log.getLogEntries()).hasSize(numCommits);
    Instant firstCommitTime = log.getLogEntries().get(log.getLogEntries().size() - 1).getCommitMeta().getCommitTime();
    Instant lastCommitTime = log.getLogEntries().get(0).getCommitMeta().getCommitTime();
    assertThat(firstCommitTime).isNotNull();
    assertThat(lastCommitTime).isNotNull();
    String author = "author-1";
    log = rest().queryParam("filter", String.format("commit.author=='%s'", author)).get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
    assertThat(log.getLogEntries()).hasSize(1);
    assertThat(log.getLogEntries().get(0).getCommitMeta().getAuthor()).isEqualTo(author);
    log = rest().queryParam("filter", String.format("timestamp(commit.commitTime) > timestamp('%s')", firstCommitTime)).get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
    assertThat(log.getLogEntries()).hasSize(numCommits - 1);
    log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getCommitTime()).isAfter(firstCommitTime));
    log = rest().queryParam("filter", String.format("timestamp(commit.commitTime) < timestamp('%s')", lastCommitTime)).get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
    assertThat(log.getLogEntries()).hasSize(numCommits - 1);
    log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getCommitTime()).isBefore(lastCommitTime));
    log = rest().queryParam("filter", String.format("timestamp(commit.commitTime) > timestamp('%s') && timestamp(commit.commitTime) < timestamp('%s')", firstCommitTime, lastCommitTime)).get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
    assertThat(log.getLogEntries()).hasSize(1);
    assertThat(log.getLogEntries().get(0).getCommitMeta().getCommitTime()).isBefore(lastCommitTime).isAfter(firstCommitTime);
}
Also used : LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 34 with Branch

use of org.projectnessie.model.Branch 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 35 with Branch

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

Aggregations

Branch (org.projectnessie.model.Branch)81 Test (org.junit.jupiter.api.Test)56 IcebergTable (org.projectnessie.model.IcebergTable)30 ContentKey (org.projectnessie.model.ContentKey)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 LogResponse (org.projectnessie.model.LogResponse)19 Reference (org.projectnessie.model.Reference)19 CommitMeta (org.projectnessie.model.CommitMeta)18 Instant (java.time.Instant)16 LogEntry (org.projectnessie.model.LogResponse.LogEntry)13 List (java.util.List)12 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)12 Tag (org.projectnessie.model.Tag)12 Collectors (java.util.stream.Collectors)11 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)11 Content (org.projectnessie.model.Content)11 Entry (org.projectnessie.model.EntriesResponse.Entry)10 Put (org.projectnessie.model.Operation.Put)10 IcebergView (org.projectnessie.model.IcebergView)9 Map (java.util.Map)8