Search in sources :

Example 6 with LogResponse

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

the class AbstractRestCommitLog method filterCommitLogByProperties.

@Test
public void filterCommitLogByProperties() throws BaseNessieClientServerException {
    Branch branch = createBranch("filterCommitLogByProperties");
    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.properties['prop1'] == 'val1'").get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).hasSize(numAuthors * commitsPerAuthor);
    log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getProperties().get("prop1")).isEqualTo("val1"));
    log = getApi().getCommitLog().refName(branch.getName()).filter("commit.properties['prop1'] == 'val3'").get();
    assertThat(log).isNotNull();
    assertThat(log.getLogEntries()).isEmpty();
}
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 7 with LogResponse

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

the class AbstractRestCommitLog method verifyPaging.

void verifyPaging(String branchName, int commits, int pageSizeHint, List<String> commitMessages, String filterByAuthor) throws NessieNotFoundException {
    String pageToken = null;
    for (int pos = 0; pos < commits; pos += pageSizeHint) {
        String filter = null;
        if (null != filterByAuthor) {
            filter = String.format("commit.author=='%s'", filterByAuthor);
        }
        LogResponse response = getApi().getCommitLog().refName(branchName).maxRecords(pageSizeHint).pageToken(pageToken).filter(filter).get();
        if (pos + pageSizeHint <= commits) {
            assertTrue(response.isHasMore());
            assertNotNull(response.getToken());
            assertEquals(commitMessages.subList(pos, pos + pageSizeHint), response.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).collect(Collectors.toList()));
            pageToken = response.getToken();
        } else {
            assertFalse(response.isHasMore());
            assertNull(response.getToken());
            assertEquals(commitMessages.subList(pos, commitMessages.size()), response.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).collect(Collectors.toList()));
            break;
        }
    }
}
Also used : LogResponse(org.projectnessie.model.LogResponse) CommitMeta(org.projectnessie.model.CommitMeta)

Example 8 with LogResponse

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

the class AbstractRestInvalidRefs method testValidHashesOnValidNamedRefs.

@Test
public void testValidHashesOnValidNamedRefs() throws BaseNessieClientServerException {
    Branch branch = createBranch("testValidHashesOnValidNamedRefs");
    int commits = 10;
    String currentHash = branch.getHash();
    createCommits(branch, 1, commits, currentHash);
    LogResponse entireLog = getApi().getCommitLog().refName(branch.getName()).get();
    assertThat(entireLog).isNotNull();
    assertThat(entireLog.getLogEntries()).hasSize(commits);
    EntriesResponse allEntries = getApi().getEntries().refName(branch.getName()).get();
    assertThat(allEntries).isNotNull();
    assertThat(allEntries.getEntries()).hasSize(commits);
    List<ContentKey> keys = new ArrayList<>();
    IntStream.range(0, commits).forEach(i -> keys.add(ContentKey.of("table" + i)));
    // TODO: check where hashOnRef is set
    Map<ContentKey, Content> allContent = getApi().getContent().keys(keys).refName(branch.getName()).get();
    for (int i = 0; i < commits; i++) {
        String hash = entireLog.getLogEntries().get(i).getCommitMeta().getHash();
        LogResponse log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(hash).get();
        assertThat(log).isNotNull();
        assertThat(log.getLogEntries()).hasSize(commits - i);
        assertThat(ImmutableList.copyOf(entireLog.getLogEntries()).subList(i, commits)).containsExactlyElementsOf(log.getLogEntries());
        EntriesResponse entries = getApi().getEntries().refName(branch.getName()).hashOnRef(hash).get();
        assertThat(entries).isNotNull();
        assertThat(entries.getEntries()).hasSize(commits - i);
        int idx = commits - 1 - i;
        ContentKey key = ContentKey.of("table" + idx);
        Content c = getApi().getContent().key(key).refName(branch.getName()).hashOnRef(hash).get().get(key);
        assertThat(c).isNotNull().isEqualTo(allContent.get(key));
    }
}
Also used : EntriesResponse(org.projectnessie.model.EntriesResponse) ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 9 with LogResponse

use of org.projectnessie.model.LogResponse 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 10 with LogResponse

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

the class AbstractRestAssign method testAssignRefToFreshMain.

/**
 * Assigning a branch/tag to a fresh main without any commits didn't work in 0.9.2
 */
@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void testAssignRefToFreshMain(ReferenceMode refMode) throws BaseNessieClientServerException {
    Reference main = getApi().getReference().refName("main").get();
    // make sure main doesn't have any commits
    LogResponse log = getApi().getCommitLog().refName(main.getName()).get();
    assertThat(log.getLogEntries()).isEmpty();
    Branch testBranch = createBranch("testBranch");
    getApi().assignBranch().branch(testBranch).assignTo(main).assign();
    Reference testBranchRef = getApi().getReference().refName(testBranch.getName()).get();
    assertThat(testBranchRef.getHash()).isEqualTo(main.getHash());
    String testTag = "testTag";
    Reference testTagRef = getApi().createReference().sourceRefName(main.getName()).reference(Tag.of(testTag, main.getHash())).create();
    assertThat(testTagRef.getHash()).isNotNull();
    getApi().assignTag().hash(testTagRef.getHash()).tagName(testTag).assignTo(refMode.transform(main)).assign();
    testTagRef = getApi().getReference().refName(testTag).get();
    assertThat(testTagRef.getHash()).isEqualTo(main.getHash());
}
Also used : LogResponse(org.projectnessie.model.LogResponse) Reference(org.projectnessie.model.Reference) Branch(org.projectnessie.model.Branch) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

LogResponse (org.projectnessie.model.LogResponse)19 Branch (org.projectnessie.model.Branch)17 Test (org.junit.jupiter.api.Test)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 CommitMeta (org.projectnessie.model.CommitMeta)10 LogEntry (org.projectnessie.model.LogResponse.LogEntry)9 IcebergTable (org.projectnessie.model.IcebergTable)8 ContentKey (org.projectnessie.model.ContentKey)5 Reference (org.projectnessie.model.Reference)5 Put (org.projectnessie.model.Operation.Put)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 Content (org.projectnessie.model.Content)3 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 FetchOption (org.projectnessie.api.params.FetchOption)2 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)2