use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class ITReadCommits method readCommitsVerbose.
@Test
void readCommitsVerbose() throws UnsupportedEncodingException, NessieNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintWriter out = new PrintWriter(new PrintStream(baos), true)) {
assertThat(NessieContentGenerator.runMain(out, new String[] { "commits", "--uri", NESSIE_API_URI, "--ref", branch.getName(), "--verbose" })).isEqualTo(0);
String[] output = baos.toString(StandardCharsets.UTF_8.toString()).split("\n");
assertThat(output).anySatisfy(s -> assertThat(s).contains(COMMIT_MSG));
assertThat(output).anySatisfy(s -> assertThat(s).contains(CONTENT_KEY.toString()));
assertThat(output).anySatisfy(s -> assertThat(s).contains("key[0]: " + CONTENT_KEY.getElements().get(0)));
assertThat(output).anySatisfy(s -> assertThat(s).contains("key[1]: " + CONTENT_KEY.getElements().get(1)));
assertThat(output).anySatisfy(s -> assertThat(s).contains(contentId));
}
try (NessieApiV1 api = buildNessieApi()) {
List<LogEntry> logEntries = api.getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).get().getLogEntries();
assertThat(logEntries).hasSize(1);
assertThat(logEntries.get(0).getOperations()).isNotEmpty();
assertThat(logEntries.get(0).getParentCommitHash()).isNotNull();
}
}
use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class AbstractRestMergeTransplant method transplant.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void transplant(boolean withDetachedCommit) throws BaseNessieClientServerException {
Branch base = createBranch("transplant-base");
Branch branch = createBranch("transplant-branch");
IcebergTable table1 = IcebergTable.of("transplant-table1", 42, 42, 42, 42);
IcebergTable table2 = IcebergTable.of("transplant-table2", 43, 43, 43, 43);
Branch committed1 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-transplant-branch1")).operation(Put.of(ContentKey.of("key1"), table1)).commit();
assertThat(committed1.getHash()).isNotNull();
Branch committed2 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(committed1.getHash()).commitMeta(CommitMeta.fromMessage("test-transplant-branch2")).operation(Put.of(ContentKey.of("key1"), table1, table1)).commit();
assertThat(committed2.getHash()).isNotNull();
int commitsToTransplant = 2;
LogResponse logBranch = getApi().getCommitLog().refName(branch.getName()).untilHash(branch.getHash()).maxRecords(commitsToTransplant).get();
getApi().commitMultipleOperations().branchName(base.getName()).hash(base.getHash()).commitMeta(CommitMeta.fromMessage("test-transplant-main")).operation(Put.of(ContentKey.of("key2"), table2)).commit();
getApi().transplantCommitsIntoBranch().hashesToTransplant(ImmutableList.of(committed1.getHash(), committed2.getHash())).fromRefName(maybeAsDetachedName(withDetachedCommit, branch)).branch(base).transplant();
LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("test-transplant-branch2", "test-transplant-branch1", "test-transplant-main");
// Verify that the commit-timestamp was updated
LogResponse logOfTransplanted = getApi().getCommitLog().refName(base.getName()).maxRecords(commitsToTransplant).get();
assertThat(logOfTransplanted.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getCommitTime)).isNotEqualTo(logBranch.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getCommitTime));
assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(e -> e.getName().getName())).containsExactlyInAnyOrder("key1", "key2");
}
use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class AbstractRestNamespace method testNamespaceMerge.
@Test
public void testNamespaceMerge() throws BaseNessieClientServerException {
Branch base = createBranch("merge-base");
Branch branch = createBranch("merge-branch");
Namespace ns = Namespace.parse("a.b.c");
// create the same namespace on both branches
getApi().createNamespace().namespace(ns).refName(branch.getName()).create();
getApi().createNamespace().namespace(ns).refName(base.getName()).create();
base = (Branch) getApi().getReference().refName(base.getName()).get();
branch = (Branch) getApi().getReference().refName(branch.getName()).get();
getApi().mergeRefIntoBranch().branch(base).fromRef(branch).merge();
LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
String expectedCommitMsg = "create namespace a.b.c";
assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly(expectedCommitMsg, expectedCommitMsg);
assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(Entry::getName)).containsExactly(ContentKey.of(ns.getElements()));
assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class AbstractRestNamespace method testNamespaceMergeWithConflict.
@Test
public void testNamespaceMergeWithConflict() throws BaseNessieClientServerException {
Branch base = createBranch("merge-base");
Branch branch = createBranch("merge-branch");
Namespace ns = Namespace.parse("a.b.c");
// create a namespace on the base branch
getApi().createNamespace().namespace(ns).refName(base.getName()).create();
base = (Branch) getApi().getReference().refName(base.getName()).get();
// create a table with the same name on the other branch
IcebergTable table = IcebergTable.of("merge-table1", 42, 42, 42, 42);
branch = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch1")).operation(Put.of(ContentKey.of("a", "b", "c"), table)).commit();
Branch finalBase = base;
Branch finalBranch = branch;
assertThatThrownBy(() -> getApi().mergeRefIntoBranch().branch(finalBase).fromRef(finalBranch).merge()).isInstanceOf(NessieReferenceConflictException.class).hasMessage("The following keys have been changed in conflict: 'a.b.c'");
LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
// merging should not have been possible ("test-merge-branch1" shouldn't be in the commits)
assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("create namespace a.b.c");
List<Entry> entries = getApi().getEntries().refName(base.getName()).get().getEntries();
assertThat(entries.stream().map(Entry::getName)).containsExactly(ContentKey.of(ns.getElements()));
assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class AbstractRestCommitLog method commitLogPagingAndFilteringByAuthor.
@Test
public void commitLogPagingAndFilteringByAuthor() throws BaseNessieClientServerException {
Branch branch = createBranch("commitLogPagingAndFiltering");
int numAuthors = 3;
int commits = 45;
int pageSizeHint = 10;
int expectedTotalSize = numAuthors * commits;
createCommits(branch, numAuthors, commits, branch.getHash());
LogResponse log = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(expectedTotalSize);
String author = "author-1";
List<String> messagesOfAuthorOne = log.getLogEntries().stream().map(LogEntry::getCommitMeta).filter(c -> author.equals(c.getAuthor())).map(CommitMeta::getMessage).collect(Collectors.toList());
verifyPaging(branch.getName(), commits, pageSizeHint, messagesOfAuthorOne, author);
List<String> allMessages = log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).collect(Collectors.toList());
List<CommitMeta> completeLog = StreamingUtil.getCommitLogStream(getApi(), c -> c.refName(branch.getName()).fetch(FetchOption.MINIMAL), OptionalInt.of(pageSizeHint)).map(LogEntry::getCommitMeta).collect(Collectors.toList());
assertThat(completeLog.stream().map(CommitMeta::getMessage)).containsExactlyElementsOf(allMessages);
}
Aggregations