Search in sources :

Example 61 with Branch

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

the class AbstractRestCommitLog method filterCommitLogOperations.

@Test
public void filterCommitLogOperations() throws BaseNessieClientServerException {
    Branch branch = createBranch("filterCommitLogOperations");
    branch = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("some awkward message")).operation(Put.of(ContentKey.of("hello", "world", "BaseTable"), IcebergView.of("path1", 1, 1, "Spark", "SELECT ALL THE THINGS"))).operation(Put.of(ContentKey.of("dlrow", "olleh", "BaseTable"), IcebergView.of("path2", 1, 1, "Spark", "SELECT ALL THE THINGS"))).commit();
    assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.type == 'PUT')").get().getLogEntries()).hasSize(1);
    assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.key.startsWith('hello.world.'))").get().getLogEntries()).hasSize(1);
    assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.key.startsWith('not.there.'))").get().getLogEntries()).isEmpty();
    assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.name == 'BaseTable')").get().getLogEntries()).hasSize(1);
    assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.name == 'ThereIsNoSuchTable')").get().getLogEntries()).isEmpty();
}
Also used : Branch(org.projectnessie.model.Branch) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with Branch

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

the class AbstractRestCommitLog method commitLogExtended.

@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void commitLogExtended(ReferenceMode refMode) throws Exception {
    String branch = "commitLogExtended";
    String firstParent = getApi().createReference().sourceRefName("main").reference(Branch.of(branch, null)).create().getHash();
    int numCommits = 10;
    // Hack for tests running via Quarkus :(
    IntFunction<String> c1 = i -> refMode.name() + "-c1-" + i;
    IntFunction<String> c2 = i -> refMode.name() + "-c2-" + i;
    List<String> hashes = IntStream.rangeClosed(1, numCommits).mapToObj(i -> {
        try {
            String head = getApi().getReference().refName(branch).get().getHash();
            return getApi().commitMultipleOperations().operation(Put.of(ContentKey.of("k" + i), IcebergTable.of("m" + i, i, i, i, i, c1.apply(i)))).operation(Put.of(ContentKey.of("key" + i), IcebergTable.of("meta" + i, i, i, i, i, c2.apply(i)))).operation(Delete.of(ContentKey.of("delete" + i))).operation(Unchanged.of(ContentKey.of("key" + i))).commitMeta(CommitMeta.fromMessage("Commit #" + i)).branchName(branch).hash(head).commit().getHash();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());
    List<String> parentHashes = Stream.concat(Stream.of(firstParent), hashes.subList(0, 9).stream()).collect(Collectors.toList());
    Reference branchRef = getApi().getReference().refName(branch).get();
    assertThat(Lists.reverse(getApi().getCommitLog().untilHash(firstParent).reference(refMode.transform(branchRef)).get().getLogEntries())).allSatisfy(c -> {
        assertThat(c.getOperations()).isNull();
        assertThat(c.getParentCommitHash()).isNull();
    }).extracting(e -> e.getCommitMeta().getHash()).containsExactlyElementsOf(hashes);
    List<LogEntry> commits = Lists.reverse(getApi().getCommitLog().fetch(FetchOption.ALL).reference(refMode.transform(branchRef)).untilHash(firstParent).get().getLogEntries());
    assertThat(IntStream.rangeClosed(1, numCommits)).allSatisfy(i -> {
        LogEntry c = commits.get(i - 1);
        assertThat(c).extracting(e -> e.getCommitMeta().getMessage(), e -> e.getCommitMeta().getHash(), LogEntry::getParentCommitHash, LogEntry::getOperations).containsExactly("Commit #" + i, hashes.get(i - 1), parentHashes.get(i - 1), Arrays.asList(Delete.of(ContentKey.of("delete" + i)), Put.of(ContentKey.of("k" + i), IcebergTable.of("m" + i, i, i, i, i, c1.apply(i))), Put.of(ContentKey.of("key" + i), IcebergTable.of("meta" + i, i, i, i, i, c2.apply(i)))));
    });
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) Unchanged(org.projectnessie.model.Operation.Unchanged) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) EnumSource(org.junit.jupiter.params.provider.EnumSource) OptionalInt(java.util.OptionalInt) Reference(org.projectnessie.model.Reference) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMeta(org.projectnessie.model.CommitMeta) IntFunction(java.util.function.IntFunction) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FetchOption(org.projectnessie.api.params.FetchOption) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) IcebergView(org.projectnessie.model.IcebergView) Delete(org.projectnessie.model.Operation.Delete) StreamingUtil(org.projectnessie.client.StreamingUtil) IcebergTable(org.projectnessie.model.IcebergTable) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Collections(java.util.Collections) Reference(org.projectnessie.model.Reference) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) LogEntry(org.projectnessie.model.LogResponse.LogEntry) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 63 with Branch

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

the class AbstractRestCommitLog method filterCommitLogByAuthor.

@Test
public void filterCommitLogByAuthor() throws BaseNessieClientServerException {
    Branch branch = createBranch("filterCommitLogByAuthor");
    int numAuthors = 5;
    int commitsPerAuthor = 10;
    String currentHash = branch.getHash();
    createCommits(branch, numAuthors, commitsPerAuthor, currentHash);
    LogResponse log = getApi().getCommitLog().refName(branch.getName()).get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).hasSize(numAuthors * commitsPerAuthor);
    log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author == 'author-3'").get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).hasSize(commitsPerAuthor);
    log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getAuthor()).isEqualTo("author-3"));
    log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author == 'author-3' && commit.committer == 'random-committer'").get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).isEmpty();
    log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author == 'author-3'").get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).hasSize(commitsPerAuthor);
    log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getAuthor()).isEqualTo("author-3"));
    log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author in ['author-1', 'author-3', 'author-4']").get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).hasSize(commitsPerAuthor * 3);
    log.getLogEntries().forEach(commit -> assertThat(ImmutableList.of("author-1", "author-3", "author-4")).contains(commit.getCommitMeta().getAuthor()));
    log = getApi().getCommitLog().refName(branch.getName()).filter("!(commit.author in ['author-1', 'author-0'])").get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).hasSize(commitsPerAuthor * 3);
    log.getLogEntries().forEach(commit -> assertThat(ImmutableList.of("author-2", "author-3", "author-4")).contains(commit.getCommitMeta().getAuthor()));
    log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author.matches('au.*-(2|4)')").get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).hasSize(commitsPerAuthor * 2);
    log.getLogEntries().forEach(commit -> assertThat(ImmutableList.of("author-2", "author-4")).contains(commit.getCommitMeta().getAuthor()));
}
Also used : LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with Branch

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

the class AbstractRestCommitLog method filterCommitLogByCommitRange.

@Test
public void filterCommitLogByCommitRange() throws BaseNessieClientServerException {
    Branch branch = createBranch("filterCommitLogByCommitRange");
    int numCommits = 10;
    String currentHash = branch.getHash();
    createCommits(branch, 1, numCommits, currentHash);
    LogResponse entireLog = getApi().getCommitLog().refName(branch.getName()).get();
    assertThat(entireLog).isNotNull();
    assertThat(entireLog.getLogEntries()).hasSize(numCommits);
    // if startHash > endHash, then we return all commits starting from startHash
    String startHash = entireLog.getLogEntries().get(numCommits / 2).getCommitMeta().getHash();
    String endHash = entireLog.getLogEntries().get(0).getCommitMeta().getHash();
    LogResponse log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(endHash).untilHash(startHash).get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).hasSize(numCommits / 2 + 1);
    for (int i = 0, j = numCommits - 1; i < j; i++, j--) {
        startHash = entireLog.getLogEntries().get(j).getCommitMeta().getHash();
        endHash = entireLog.getLogEntries().get(i).getCommitMeta().getHash();
        log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(endHash).untilHash(startHash).get();
        assertThat(log).isNotNull();
        assertThat(log.getLogEntries()).hasSize(numCommits - (i * 2));
        assertThat(ImmutableList.copyOf(entireLog.getLogEntries()).subList(i, j + 1)).containsExactlyElementsOf(log.getLogEntries());
    }
}
Also used : LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with Branch

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

the class AbstractRestContents method verifyAllContentAndOperationTypes.

@Test
public void verifyAllContentAndOperationTypes() throws BaseNessieClientServerException {
    Branch branch = createBranch("contentAndOperationAll");
    CommitMultipleOperationsBuilder commit = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("verifyAllContentAndOperationTypes"));
    contentAndOperationTypes().flatMap(c -> c.globalOperation == null ? Stream.of(c.operation) : Stream.of(c.operation, c.globalOperation)).forEach(commit::operation);
    commit.commit();
    List<Entry> entries = getApi().getEntries().refName(branch.getName()).get().getEntries();
    List<Entry> expect = contentAndOperationTypes().filter(c -> c.operation instanceof Put).map(c -> Entry.builder().type(c.type).name(c.operation.getKey()).build()).collect(Collectors.toList());
    assertThat(entries).containsExactlyInAnyOrderElementsOf(expect);
}
Also used : Put(org.projectnessie.model.Operation.Put) Unchanged(org.projectnessie.model.Operation.Unchanged) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Entry(org.projectnessie.model.EntriesResponse.Entry) Collections.singletonList(java.util.Collections.singletonList) Type(org.projectnessie.model.Content.Type) Map(java.util.Map) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) MethodSource(org.junit.jupiter.params.provider.MethodSource) Operation(org.projectnessie.model.Operation) Collections.emptyList(java.util.Collections.emptyList) Branch(org.projectnessie.model.Branch) ImmutableDeltaLakeTable(org.projectnessie.model.ImmutableDeltaLakeTable) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) IcebergView(org.projectnessie.model.IcebergView) Delete(org.projectnessie.model.Operation.Delete) IcebergTable(org.projectnessie.model.IcebergTable) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) Entry(org.projectnessie.model.EntriesResponse.Entry) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) Branch(org.projectnessie.model.Branch) Put(org.projectnessie.model.Operation.Put) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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