use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class ITUpgradePath method commitLog.
@Test
@Order(104)
void commitLog() {
assertThat(api.getAllReferences().get().getReferences().stream().filter(r -> r.getName().startsWith(VERSION_BRANCH_PREFIX))).isNotEmpty().allSatisfy(ref -> {
String versionFromRef = ref.getName().substring(VERSION_BRANCH_PREFIX.length());
LogResponse commitLog = api.getCommitLog().refName(ref.getName()).get();
String commitMessage = "hello world " + versionFromRef;
assertThat(commitLog.getLogEntries()).hasSize(1).map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).containsExactly(commitMessage);
}).allSatisfy(ref -> {
String versionFromRef = ref.getName().substring(VERSION_BRANCH_PREFIX.length());
ContentKey key = ContentKey.of("my", "tables", "table_name");
IcebergTable content = IcebergTable.of("metadata-location", 42L, 43, 44, 45, "content-id-" + versionFromRef);
Map<ContentKey, Content> contents = api.getContent().reference(ref).key(key).get();
assertThat(contents).containsExactly(entry(key, content));
});
}
use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class AbstractRestMergeTransplant method merge.
@ParameterizedTest
@EnumSource(value = ReferenceMode.class, mode = Mode.EXCLUDE, // merge requires the hash
names = "NAME_ONLY")
public void merge(ReferenceMode refMode) throws BaseNessieClientServerException {
Branch base = createBranch("merge-base");
Branch branch = createBranch("merge-branch");
IcebergTable table1 = IcebergTable.of("merge-table1", 42, 42, 42, 42);
IcebergTable table2 = IcebergTable.of("merge-table2", 43, 43, 43, 43);
Branch committed1 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-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-merge-branch2")).operation(Put.of(ContentKey.of("key1"), table1, table1)).commit();
assertThat(committed2.getHash()).isNotNull();
int commitsToMerge = 2;
LogResponse logBranch = getApi().getCommitLog().refName(branch.getName()).untilHash(branch.getHash()).maxRecords(commitsToMerge).get();
getApi().commitMultipleOperations().branchName(base.getName()).hash(base.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-main")).operation(Put.of(ContentKey.of("key2"), table2)).commit();
getApi().mergeRefIntoBranch().branch(base).fromRef(refMode.transform(committed2)).merge();
LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("test-merge-branch2", "test-merge-branch1", "test-merge-main");
// Verify that the commit-timestamp was updated
LogResponse logOfMerged = getApi().getCommitLog().refName(base.getName()).maxRecords(commitsToMerge).get();
assertThat(logOfMerged.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 AbstractRestMergeTransplant method mergeWithNamespaces.
@ParameterizedTest
@EnumSource(value = ReferenceMode.class, mode = Mode.EXCLUDE, // merge requires the hash
names = "NAME_ONLY")
public void mergeWithNamespaces(ReferenceMode refMode) 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();
IcebergTable table1 = IcebergTable.of("merge-table1", 42, 42, 42, 42);
IcebergTable table2 = IcebergTable.of("merge-table2", 43, 43, 43, 43);
ContentKey key1 = ContentKey.of(ns, "key1");
ContentKey key2 = ContentKey.of(ns, "key2");
Branch committed1 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch1")).operation(Put.of(key1, table1)).commit();
assertThat(committed1.getHash()).isNotNull();
Branch committed2 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(committed1.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch2")).operation(Put.of(key1, table1, table1)).commit();
assertThat(committed2.getHash()).isNotNull();
getApi().commitMultipleOperations().branchName(base.getName()).hash(base.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-main")).operation(Put.of(key2, table2)).commit();
getApi().mergeRefIntoBranch().branch(base).fromRef(refMode.transform(committed2)).merge();
LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("test-merge-branch2", "test-merge-branch1", "create namespace a.b.c", "test-merge-main", "create namespace a.b.c");
assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(Entry::getName)).containsExactlyInAnyOrder(key1, key2, 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 commitLogExtended.
@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void commitLogExtended(ReferenceMode refMode) throws Exception {
String branch = "commitLogExtended";
String firstParent = getApi().createReference().sourceRefName("main").reference(Branch.of(branch, null)).create().getHash();
int numCommits = 10;
// Hack for tests running via Quarkus :(
IntFunction<String> c1 = i -> refMode.name() + "-c1-" + i;
IntFunction<String> c2 = i -> refMode.name() + "-c2-" + i;
List<String> hashes = IntStream.rangeClosed(1, numCommits).mapToObj(i -> {
try {
String head = getApi().getReference().refName(branch).get().getHash();
return getApi().commitMultipleOperations().operation(Put.of(ContentKey.of("k" + i), IcebergTable.of("m" + i, i, i, i, i, c1.apply(i)))).operation(Put.of(ContentKey.of("key" + i), IcebergTable.of("meta" + i, i, i, i, i, c2.apply(i)))).operation(Delete.of(ContentKey.of("delete" + i))).operation(Unchanged.of(ContentKey.of("key" + i))).commitMeta(CommitMeta.fromMessage("Commit #" + i)).branchName(branch).hash(head).commit().getHash();
} catch (Exception e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
List<String> parentHashes = Stream.concat(Stream.of(firstParent), hashes.subList(0, 9).stream()).collect(Collectors.toList());
Reference branchRef = getApi().getReference().refName(branch).get();
assertThat(Lists.reverse(getApi().getCommitLog().untilHash(firstParent).reference(refMode.transform(branchRef)).get().getLogEntries())).allSatisfy(c -> {
assertThat(c.getOperations()).isNull();
assertThat(c.getParentCommitHash()).isNull();
}).extracting(e -> e.getCommitMeta().getHash()).containsExactlyElementsOf(hashes);
List<LogEntry> commits = Lists.reverse(getApi().getCommitLog().fetch(FetchOption.ALL).reference(refMode.transform(branchRef)).untilHash(firstParent).get().getLogEntries());
assertThat(IntStream.rangeClosed(1, numCommits)).allSatisfy(i -> {
LogEntry c = commits.get(i - 1);
assertThat(c).extracting(e -> e.getCommitMeta().getMessage(), e -> e.getCommitMeta().getHash(), LogEntry::getParentCommitHash, LogEntry::getOperations).containsExactly("Commit #" + i, hashes.get(i - 1), parentHashes.get(i - 1), Arrays.asList(Delete.of(ContentKey.of("delete" + i)), Put.of(ContentKey.of("k" + i), IcebergTable.of("m" + i, i, i, i, i, c1.apply(i))), Put.of(ContentKey.of("key" + i), IcebergTable.of("meta" + i, i, i, i, i, c2.apply(i)))));
});
}
use of org.projectnessie.model.LogResponse.LogEntry in project nessie by projectnessie.
the class AbstractRestReferences method verifyMetadataProperties.
void verifyMetadataProperties(Tag tag) throws NessieNotFoundException {
List<LogEntry> commits = getApi().getCommitLog().refName(tag.getName()).maxRecords(1).get().getLogEntries();
assertThat(commits).hasSize(1);
CommitMeta commitMeta = commits.get(0).getCommitMeta();
ReferenceMetadata referenceMetadata = tag.getMetadata();
assertThat(referenceMetadata).isNotNull();
assertThat(referenceMetadata.getNumCommitsAhead()).isNull();
assertThat(referenceMetadata.getNumCommitsBehind()).isNull();
assertThat(referenceMetadata.getCommitMetaOfHEAD()).isEqualTo(commitMeta);
assertThat(referenceMetadata.getCommonAncestorHash()).isNull();
assertThat(referenceMetadata.getNumTotalCommits()).isEqualTo(10);
}
Aggregations