use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.
the class AbstractRestCommitLog method commitLogPaging.
@Test
public void commitLogPaging() throws BaseNessieClientServerException {
Branch branch = createBranch("commitLogPaging");
int commits = 95;
int pageSizeHint = 10;
String currentHash = branch.getHash();
List<String> allMessages = new ArrayList<>();
for (int i = 0; i < commits; i++) {
String msg = "message-for-" + i;
allMessages.add(msg);
IcebergTable tableMeta = IcebergTable.of("some-file-" + i, 42, 42, 42, 42);
String nextHash = getApi().commitMultipleOperations().branchName(branch.getName()).hash(currentHash).commitMeta(CommitMeta.fromMessage(msg)).operation(Put.of(ContentKey.of("table"), tableMeta)).commit().getHash();
assertNotEquals(currentHash, nextHash);
currentHash = nextHash;
}
Collections.reverse(allMessages);
verifyPaging(branch.getName(), commits, pageSizeHint, allMessages, null);
List<CommitMeta> completeLog = StreamingUtil.getCommitLogStream(getApi(), c -> c.refName(branch.getName()).fetch(FetchOption.MINIMAL), OptionalInt.of(pageSizeHint)).map(LogEntry::getCommitMeta).collect(Collectors.toList());
assertEquals(completeLog.stream().map(CommitMeta::getMessage).collect(Collectors.toList()), allMessages);
}
use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.
the class AbstractRestContents method multiget.
@Test
public void multiget() throws BaseNessieClientServerException {
Branch branch = createBranch("foo");
ContentKey a = ContentKey.of("a");
ContentKey b = ContentKey.of("b");
IcebergTable ta = IcebergTable.of("path1", 42, 42, 42, 42);
IcebergTable tb = IcebergTable.of("path2", 42, 42, 42, 42);
getApi().commitMultipleOperations().branch(branch).operation(Put.of(a, ta)).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
getApi().commitMultipleOperations().branch(branch).operation(Put.of(b, tb)).commitMeta(CommitMeta.fromMessage("commit 2")).commit();
Map<ContentKey, Content> response = getApi().getContent().key(a).key(b).key(ContentKey.of("noexist")).refName("foo").get();
assertThat(response).containsEntry(a, ta).containsEntry(b, tb).doesNotContainKey(ContentKey.of("noexist"));
}
use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.
the class AbstractRestDiff method testDiff.
@ParameterizedTest
@MethodSource("diffRefModes")
public void testDiff(ReferenceMode refModeFrom, ReferenceMode refModeTo) throws BaseNessieClientServerException {
int commitsPerBranch = 10;
Reference fromRef = getApi().createReference().reference(Branch.of("testDiffFromRef", null)).create();
Reference toRef = getApi().createReference().reference(Branch.of("testDiffToRef", null)).create();
String toRefHash = createCommits(toRef, 1, commitsPerBranch, toRef.getHash());
toRef = Branch.of(toRef.getName(), toRefHash);
List<DiffEntry> diffOnRefHeadResponse = getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRef)).get().getDiffs();
// we only committed to toRef, the "from" diff should be null
assertThat(diffOnRefHeadResponse).hasSize(commitsPerBranch).allSatisfy(diff -> {
assertThat(diff.getKey()).isNotNull();
assertThat(diff.getFrom()).isNull();
assertThat(diff.getTo()).isNotNull();
});
// Some combinations with explicit fromHashOnRef/toHashOnRef
assertThat(getApi().getDiff().fromRefName(fromRef.getName()).fromHashOnRef(fromRef.getHash()).toRefName(toRef.getName()).toHashOnRef(toRef.getHash()).get().getDiffs()).isEqualTo(diffOnRefHeadResponse);
// result
if (refModeTo != ReferenceMode.NAME_ONLY) {
Branch toRefAtFrom = Branch.of(toRef.getName(), fromRef.getHash());
assertThat(getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRefAtFrom)).get().getDiffs()).isEmpty();
}
// after committing to fromRef, "from/to" diffs should both have data
fromRef = Branch.of(fromRef.getName(), createCommits(fromRef, 1, commitsPerBranch, fromRef.getHash()));
assertThat(getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRef)).get().getDiffs()).hasSize(commitsPerBranch).allSatisfy(diff -> {
assertThat(diff.getKey()).isNotNull();
assertThat(diff.getFrom()).isNotNull();
assertThat(diff.getTo()).isNotNull();
// we only have a diff on the ID
assertThat(diff.getFrom().getId()).isNotEqualTo(diff.getTo().getId());
Optional<IcebergTable> fromTable = diff.getFrom().unwrap(IcebergTable.class);
assertThat(fromTable).isPresent();
Optional<IcebergTable> toTable = diff.getTo().unwrap(IcebergTable.class);
assertThat(toTable).isPresent();
assertThat(fromTable.get().getMetadataLocation()).isEqualTo(toTable.get().getMetadataLocation());
assertThat(fromTable.get().getSchemaId()).isEqualTo(toTable.get().getSchemaId());
assertThat(fromTable.get().getSnapshotId()).isEqualTo(toTable.get().getSnapshotId());
assertThat(fromTable.get().getSortOrderId()).isEqualTo(toTable.get().getSortOrderId());
assertThat(fromTable.get().getSpecId()).isEqualTo(toTable.get().getSpecId());
});
List<ContentKey> keys = IntStream.rangeClosed(0, commitsPerBranch).mapToObj(i -> ContentKey.of("table" + i)).collect(Collectors.toList());
// request all keys and delete the tables for them on toRef
Map<ContentKey, Content> map = getApi().getContent().refName(toRef.getName()).keys(keys).get();
for (Map.Entry<ContentKey, Content> entry : map.entrySet()) {
toRef = getApi().commitMultipleOperations().branchName(toRef.getName()).hash(toRefHash).commitMeta(CommitMeta.fromMessage("delete")).operation(Delete.of(entry.getKey())).commit();
}
// now that we deleted all tables on toRef, the diff for "to" should be null
assertThat(getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRef)).get().getDiffs()).hasSize(commitsPerBranch).allSatisfy(diff -> {
assertThat(diff.getKey()).isNotNull();
assertThat(diff.getFrom()).isNotNull();
assertThat(diff.getTo()).isNull();
});
}
use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.
the class AbstractRestGC method commitSingleOp.
CommitOutput commitSingleOp(String prefix, Reference branch, String currentHash, long snapshotId, String contentId, String contentKey, String metadataFile, IcebergTable previous, String beforeRename) throws NessieNotFoundException, NessieConflictException {
IcebergTable meta = IcebergTable.of(prefix + "_" + metadataFile, snapshotId, 42, 42, 42, prefix + "_" + contentId);
CommitMultipleOperationsBuilder multiOp = getApi().commitMultipleOperations().branchName(branch.getName()).hash(currentHash).commitMeta(CommitMeta.builder().author("someone").message("some commit").properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Put.of(ContentKey.of(prefix + "_" + contentKey), meta, previous));
if (beforeRename != null) {
multiOp.operation(Operation.Delete.of(ContentKey.of(prefix + "_" + beforeRename)));
}
String nextHash = multiOp.commit().getHash();
assertThat(currentHash).isNotEqualTo(nextHash);
return new CommitOutput(nextHash, meta);
}
use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.
the class AbstractResteasyTest method testGetContent.
@Test
public void testGetContent() {
Branch branch = makeBranch("content-test");
IcebergTable table = IcebergTable.of("content-table1", 42, 42, 42, 42);
branch = commit(table.getId(), branch, "key1", table.getMetadataLocation());
Content content = rest().queryParam("ref", branch.getName()).queryParam("hashOnRef", branch.getHash()).get(String.format("contents/%s", "key1")).then().statusCode(200).extract().as(Content.class);
assertThat(content).isEqualTo(table);
}
Aggregations