Search in sources :

Example 16 with LogResponse

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

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

the class AbstractRestReferences method referenceNames.

@ParameterizedTest
@ValueSource(strings = { "normal", "with-no_space", "slash/thing" })
public void referenceNames(String refNamePart) throws BaseNessieClientServerException {
    String tagName = "tag" + refNamePart;
    String branchName = "branch" + refNamePart;
    String branchName2 = "branch2" + refNamePart;
    String root = "ref_name_" + refNamePart.replaceAll("[^a-z]", "");
    Branch main = createBranch(root);
    IcebergTable meta = IcebergTable.of("meep", 42, 42, 42, 42);
    main = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("common-merge-ancestor").properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Operation.Put.of(ContentKey.of("meep"), meta)).commit();
    String someHash = main.getHash();
    Reference createdTag = getApi().createReference().sourceRefName(main.getName()).reference(Tag.of(tagName, someHash)).create();
    assertEquals(Tag.of(tagName, someHash), createdTag);
    Reference createdBranch1 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName, someHash)).create();
    assertEquals(Branch.of(branchName, someHash), createdBranch1);
    Reference createdBranch2 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName2, someHash)).create();
    assertEquals(Branch.of(branchName2, someHash), createdBranch2);
    Map<String, Reference> references = getApi().getAllReferences().get().getReferences().stream().filter(r -> root.equals(r.getName()) || r.getName().endsWith(refNamePart)).collect(Collectors.toMap(Reference::getName, Function.identity()));
    assertThat(references).containsAllEntriesOf(ImmutableMap.of(main.getName(), main, createdTag.getName(), createdTag, createdBranch1.getName(), createdBranch1, createdBranch2.getName(), createdBranch2));
    assertThat(references.get(main.getName())).isInstanceOf(Branch.class);
    assertThat(references.get(createdTag.getName())).isInstanceOf(Tag.class);
    assertThat(references.get(createdBranch1.getName())).isInstanceOf(Branch.class);
    assertThat(references.get(createdBranch2.getName())).isInstanceOf(Branch.class);
    Reference tagRef = references.get(tagName);
    Reference branchRef = references.get(branchName);
    Reference branchRef2 = references.get(branchName2);
    String tagHash = tagRef.getHash();
    String branchHash = branchRef.getHash();
    String branchHash2 = branchRef2.getHash();
    assertThat(getApi().getReference().refName(tagName).get()).isEqualTo(tagRef);
    assertThat(getApi().getReference().refName(branchName).get()).isEqualTo(branchRef);
    EntriesResponse entries = getApi().getEntries().refName(tagName).get();
    assertThat(entries).isNotNull();
    entries = getApi().getEntries().refName(branchName).get();
    assertThat(entries).isNotNull();
    LogResponse log = getApi().getCommitLog().refName(tagName).get();
    assertThat(log).isNotNull();
    log = getApi().getCommitLog().refName(branchName).get();
    assertThat(log).isNotNull();
    // Need to have at least one op, otherwise all following operations (assignTag/Branch, merge,
    // delete) will fail
    meta = IcebergTable.of("foo", 42, 42, 42, 42);
    getApi().commitMultipleOperations().branchName(branchName).hash(branchHash).operation(Put.of(ContentKey.of("some-key"), meta)).commitMeta(CommitMeta.fromMessage("One dummy op")).commit();
    log = getApi().getCommitLog().refName(branchName).get();
    String newHash = log.getLogEntries().get(0).getCommitMeta().getHash();
    getApi().assignTag().tagName(tagName).hash(tagHash).assignTo(Branch.of(branchName, newHash)).assign();
    getApi().assignBranch().branchName(branchName).hash(newHash).assignTo(Branch.of(branchName, newHash)).assign();
    getApi().mergeRefIntoBranch().branchName(branchName2).hash(branchHash2).fromRefName(branchName).fromHash(newHash).merge();
}
Also used : ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Function(java.util.function.Function) Reference(org.projectnessie.model.Reference) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMeta(org.projectnessie.model.CommitMeta) ValueSource(org.junit.jupiter.params.provider.ValueSource) Operation(org.projectnessie.model.Operation) ImmutableMap(com.google.common.collect.ImmutableMap) Validation(org.projectnessie.model.Validation) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) EntriesResponse(org.projectnessie.model.EntriesResponse) 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) Stream(java.util.stream.Stream) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) Optional(java.util.Optional) Tag(org.projectnessie.model.Tag) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) EntriesResponse(org.projectnessie.model.EntriesResponse) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) IcebergTable(org.projectnessie.model.IcebergTable) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with LogResponse

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

the class AbstractResteasyTest method testBasic.

@Test
public void testBasic() {
    int preSize = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class).getReferences().size();
    rest().get("trees/tree/mainx").then().statusCode(404);
    rest().body(Branch.of("mainx", null)).post("trees/tree").then().statusCode(200);
    ReferencesResponse references = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class);
    Assertions.assertEquals(preSize + 1, references.getReferences().size());
    Reference reference = rest().get("trees/tree/mainx").then().statusCode(200).extract().as(Reference.class);
    assertEquals("mainx", reference.getName());
    Branch newReference = ImmutableBranch.builder().hash(reference.getHash()).name("test").build();
    rest().queryParam("expectedHash", reference.getHash()).body(Branch.of("test", null)).post("trees/tree").then().statusCode(200);
    assertEquals(newReference, rest().get("trees/tree/test").then().statusCode(200).extract().as(Branch.class));
    IcebergTable table = IcebergTable.of("/the/directory/over/there", 42, 42, 42, 42);
    Branch commitResponse = rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", newReference.getHash()).post("trees/branch/{branch}/commit", newReference.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(newReference.getHash(), commitResponse.getHash());
    Put[] updates = new Put[11];
    for (int i = 0; i < 10; i++) {
        updates[i] = ImmutablePut.builder().key(ContentKey.of("item", Integer.toString(i))).content(IcebergTable.of("/the/directory/over/there/" + i, 42, 42, 42, 42)).build();
    }
    updates[10] = ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(IcebergTable.of("/the/directory/over/there/has/been/moved", 42, 42, 42, 42)).build();
    Reference branch = rest().get("trees/tree/test").as(Reference.class);
    Operations contents = ImmutableOperations.builder().addOperations(updates).commitMeta(CommitMeta.fromMessage("")).build();
    commitResponse = rest().body(contents).queryParam("expectedHash", branch.getHash()).post("trees/branch/{branch}/commit", branch.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(branch.getHash(), commitResponse.getHash());
    Response res = rest().queryParam("ref", "test").get("contents/xxx.test").then().extract().response();
    Assertions.assertEquals(updates[10].getContent(), res.body().as(Content.class));
    IcebergTable currentTable = table;
    table = IcebergTable.of("/the/directory/over/there/has/been/moved/again", 42, 42, 42, 42, table.getId());
    Branch b2 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).expectedContent(currentTable).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", b2.getHash()).post("trees/branch/{branch}/commit", b2.getName()).then().statusCode(200).extract().as(Branch.class);
    Content returned = rest().queryParam("ref", "test").get("contents/xxx.test").then().statusCode(200).extract().as(Content.class);
    Assertions.assertEquals(table, returned);
    Branch b3 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(Tag.of("tagtest", b3.getHash())).queryParam("sourceRefName", b3.getName()).post("trees/tree").then().statusCode(200);
    assertThat(rest().get("trees/tree/tagtest").then().statusCode(200).extract().body().as(Tag.class).getHash()).isEqualTo(b3.getHash());
    rest().queryParam("expectedHash", "0011223344556677889900112233445566778899001122334455667788990011".substring(0, b2.getHash().length())).delete("trees/tag/tagtest").then().statusCode(409);
    rest().queryParam("expectedHash", b3.getHash()).delete("trees/tag/tagtest").then().statusCode(204);
    LogResponse log = rest().get("trees/tree/test/log").then().statusCode(200).extract().as(LogResponse.class);
    Assertions.assertEquals(3, log.getLogEntries().size());
    Branch b1 = rest().get("trees/tree/test").as(Branch.class);
    rest().queryParam("expectedHash", b1.getHash()).delete("trees/branch/test").then().statusCode(204);
    Branch bx = rest().get("trees/tree/mainx").as(Branch.class);
    rest().queryParam("expectedHash", bx.getHash()).delete("trees/branch/mainx").then().statusCode(204);
}
Also used : LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Response(io.restassured.response.Response) DiffResponse(org.projectnessie.model.DiffResponse) LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) Reference(org.projectnessie.model.Reference) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Tag(org.projectnessie.model.Tag) ImmutableOperations(org.projectnessie.model.ImmutableOperations) Operations(org.projectnessie.model.Operations) Put(org.projectnessie.model.Operation.Put) ImmutablePut(org.projectnessie.model.ImmutablePut) Test(org.junit.jupiter.api.Test)

Example 19 with LogResponse

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

the class ReadCommits method execute.

@Override
public void execute() throws NessieNotFoundException {
    try (NessieApiV1 api = createNessieApiInstance()) {
        spec.commandLine().getOut().printf("Reading commits for ref '%s'\n\n", ref);
        FetchOption fetchOption = isVerbose() ? FetchOption.ALL : FetchOption.MINIMAL;
        LogResponse logResponse = api.getCommitLog().refName(ref).fetch(fetchOption).get();
        for (LogResponse.LogEntry logEntry : logResponse.getLogEntries()) {
            CommitMeta commitMeta = logEntry.getCommitMeta();
            spec.commandLine().getOut().printf("%s\t%s\t%s [%s]\n", Objects.requireNonNull(commitMeta.getHash()).substring(0, 8), commitMeta.getAuthorTime(), commitMeta.getMessage(), commitMeta.getAuthor());
            List<Operation> operations = logEntry.getOperations();
            if (operations != null) {
                for (Operation op : operations) {
                    spec.commandLine().getOut().printf("  %s\n", op);
                    if (isVerbose()) {
                        List<String> key = op.getKey().getElements();
                        for (int i = 0; i < key.size(); i++) {
                            spec.commandLine().getOut().printf("    key[%d]: %s\n", i, key.get(i));
                        }
                    }
                }
            }
        }
        spec.commandLine().getOut().printf("\nDone reading commits for ref '%s'\n\n", ref);
    }
}
Also used : LogResponse(org.projectnessie.model.LogResponse) Operation(org.projectnessie.model.Operation) CommitMeta(org.projectnessie.model.CommitMeta) NessieApiV1(org.projectnessie.client.api.NessieApiV1) FetchOption(org.projectnessie.api.params.FetchOption)

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