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());
}
}
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();
}
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);
}
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);
}
}
Aggregations