use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class AbstractRestInvalidWithHttp method invalidBranchNames.
@ParameterizedTest
@CsvSource({ "x/" + COMMA_VALID_HASH_1, "abc'" + COMMA_VALID_HASH_1, ".foo" + COMMA_VALID_HASH_2, "abc'def'..'blah" + COMMA_VALID_HASH_2, "abc'de..blah" + COMMA_VALID_HASH_3, "abc'de@{blah" + COMMA_VALID_HASH_3 })
public void invalidBranchNames(String invalidBranchName, String validHash) {
ContentKey key = ContentKey.of("x");
Tag tag = Tag.of("valid", validHash);
String opsCountMsg = ".operations.operations: size must be between 1 and 2147483647";
assertAll(() -> assertThatThrownBy(() -> getApi().commitMultipleOperations().branchName(invalidBranchName).hash(validHash).commitMeta(CommitMeta.fromMessage("")).commit()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE).hasMessageContaining(opsCountMsg), () -> assertThatThrownBy(() -> getApi().deleteBranch().branchName(invalidBranchName).hash(validHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getCommitLog().refName(invalidBranchName).untilHash(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getEntries().refName(invalidBranchName).hashOnRef(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getReference().refName(invalidBranchName).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().assignTag().tagName(invalidBranchName).hash(validHash).assignTo(tag).assign()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> {
if (null != getHttpClient()) {
assertThatThrownBy(() -> getHttpClient().newRequest().path("trees/branch/{branchName}/merge").resolveTemplate("branchName", invalidBranchName).queryParam("expectedHash", validHash).post(null)).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE).hasMessageContaining(".merge: must not be null");
}
}, () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().branchName(invalidBranchName).hash(validHash).fromRef(getApi().getDefaultBranch()).merge()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().deleteTag().tagName(invalidBranchName).hash(validHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().branchName(invalidBranchName).hash(validHash).fromRefName("main").hashesToTransplant(singletonList(getApi().getReference().refName("main").get().getHash())).transplant()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().key(key).refName(invalidBranchName).hashOnRef(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().key(key).refName(invalidBranchName).hashOnRef(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getDiff().fromRefName(invalidBranchName).toRefName("main").get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE));
}
use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class AbstractRestMisc method checkSpecialCharacterRoundTrip.
@Test
public void checkSpecialCharacterRoundTrip() throws BaseNessieClientServerException {
Branch branch = createBranch("specialchar");
// ContentKey k = ContentKey.of("/%国","国.国");
ContentKey k = ContentKey.of("a.b", "c.txt");
IcebergTable ta = IcebergTable.of("path1", 42, 42, 42, 42);
getApi().commitMultipleOperations().branch(branch).operation(Put.of(k, ta)).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
assertThat(getApi().getContent().key(k).refName(branch.getName()).get()).containsEntry(k, ta);
assertEquals(ta, getApi().getContent().key(k).refName(branch.getName()).get().get(k));
}
use of org.projectnessie.model.ContentKey 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.ContentKey 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.ContentKey in project nessie by projectnessie.
the class AbstractRestEntries method filterEntriesByNamespace.
@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void filterEntriesByNamespace(ReferenceMode refMode) throws BaseNessieClientServerException {
Branch branch = createBranch("filterEntriesByNamespace");
ContentKey first = ContentKey.of("a", "b", "c", "firstTable");
ContentKey second = ContentKey.of("a", "b", "c", "secondTable");
ContentKey third = ContentKey.of("a", "thirdTable");
ContentKey fourth = ContentKey.of("a", "fourthTable");
getApi().commitMultipleOperations().branch(branch).operation(Put.of(first, IcebergTable.of("path1", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
getApi().commitMultipleOperations().branch(branch).operation(Put.of(second, IcebergTable.of("path2", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 2")).commit();
getApi().commitMultipleOperations().branch(branch).operation(Put.of(third, IcebergTable.of("path3", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 3")).commit();
branch = getApi().commitMultipleOperations().branch(branch).operation(Put.of(fourth, IcebergTable.of("path4", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 4")).commit();
List<Entry> entries = getApi().getEntries().reference(refMode.transform(branch)).get().getEntries();
assertThat(entries).isNotNull().hasSize(4);
entries = getApi().getEntries().reference(refMode.transform(branch)).get().getEntries();
assertThat(entries).isNotNull().hasSize(4);
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a.b')").get().getEntries();
assertThat(entries).hasSize(2);
entries.forEach(e -> assertThat(e.getName().getNamespace().name()).startsWith("a.b"));
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a')").get().getEntries();
assertThat(entries).hasSize(4);
entries.forEach(e -> assertThat(e.getName().getNamespace().name()).startsWith("a"));
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a.b.c.firstTable')").get().getEntries();
assertThat(entries).isEmpty();
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a.fourthTable')").get().getEntries();
assertThat(entries).isEmpty();
getApi().deleteBranch().branchName(branch.getName()).hash(getApi().getReference().refName(branch.getName()).get().getHash()).delete();
}
Aggregations