use of org.projectnessie.model.LogResponse 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 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 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 in project nessie by projectnessie.
the class AbstractRestCommitLog method filterCommitLogByTimeRange.
@Test
public void filterCommitLogByTimeRange() throws BaseNessieClientServerException {
Branch branch = createBranch("filterCommitLogByTimeRange");
int numAuthors = 5;
int commitsPerAuthor = 10;
int expectedTotalSize = numAuthors * commitsPerAuthor;
String currentHash = branch.getHash();
createCommits(branch, numAuthors, commitsPerAuthor, currentHash);
LogResponse log = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(expectedTotalSize);
Instant initialCommitTime = log.getLogEntries().get(log.getLogEntries().size() - 1).getCommitMeta().getCommitTime();
assertThat(initialCommitTime).isNotNull();
Instant lastCommitTime = log.getLogEntries().get(0).getCommitMeta().getCommitTime();
assertThat(lastCommitTime).isNotNull();
Instant fiveMinLater = initialCommitTime.plus(5, ChronoUnit.MINUTES);
log = getApi().getCommitLog().refName(branch.getName()).filter(String.format("timestamp(commit.commitTime) > timestamp('%s')", initialCommitTime)).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(expectedTotalSize - 1);
log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getCommitTime()).isAfter(initialCommitTime));
log = getApi().getCommitLog().refName(branch.getName()).filter(String.format("timestamp(commit.commitTime) < timestamp('%s')", fiveMinLater)).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(expectedTotalSize);
log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getCommitTime()).isBefore(fiveMinLater));
log = getApi().getCommitLog().refName(branch.getName()).filter(String.format("timestamp(commit.commitTime) > timestamp('%s') && timestamp(commit.commitTime) < timestamp('%s')", initialCommitTime, lastCommitTime)).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(expectedTotalSize - 2);
log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getCommitTime()).isAfter(initialCommitTime).isBefore(lastCommitTime));
log = getApi().getCommitLog().refName(branch.getName()).filter(String.format("timestamp(commit.commitTime) > timestamp('%s')", fiveMinLater)).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).isEmpty();
}
use of org.projectnessie.model.LogResponse 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