use of org.projectnessie.model.ContentKey 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.ContentKey in project nessie by projectnessie.
the class AbstractRestEntries method filterEntriesByType.
@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void filterEntriesByType(ReferenceMode refMode) throws BaseNessieClientServerException {
Branch branch = createBranch("filterTypes");
ContentKey a = ContentKey.of("a");
ContentKey b = ContentKey.of("b");
IcebergTable tam = IcebergTable.of("path1", 42, 42, 42, 42);
IcebergView tb = IcebergView.of("pathx", 1, 1, "select * from table", "Dremio");
getApi().commitMultipleOperations().branch(branch).operation(Put.of(a, tam)).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
branch = getApi().commitMultipleOperations().branch(branch).operation(Put.of(b, tb)).commitMeta(CommitMeta.fromMessage("commit 2")).commit();
List<Entry> entries = getApi().getEntries().reference(refMode.transform(branch)).get().getEntries();
List<Entry> expected = asList(Entry.builder().name(a).type(Type.ICEBERG_TABLE).build(), Entry.builder().name(b).type(Type.ICEBERG_VIEW).build());
assertThat(entries).containsExactlyInAnyOrderElementsOf(expected);
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.contentType=='ICEBERG_TABLE'").get().getEntries();
assertEquals(singletonList(expected.get(0)), entries);
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.contentType=='ICEBERG_VIEW'").get().getEntries();
assertEquals(singletonList(expected.get(1)), entries);
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.contentType in ['ICEBERG_TABLE', 'ICEBERG_VIEW']").get().getEntries();
assertThat(entries).containsExactlyInAnyOrderElementsOf(expected);
}
use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class AbstractRestEntries method filterEntriesByNamespaceAndPrefixDepth.
@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void filterEntriesByNamespaceAndPrefixDepth(ReferenceMode refMode) throws BaseNessieClientServerException {
Branch branch = createBranch("filterEntriesByNamespaceAndPrefixDepth");
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", "b", "fourthTable");
ContentKey fifth = ContentKey.of("a", "boo", "fifthTable");
ContentKey withoutNamespace = ContentKey.of("withoutNamespace");
List<ContentKey> keys = ImmutableList.of(first, second, third, fourth, fifth, withoutNamespace);
for (int i = 0; i < keys.size(); i++) {
getApi().commitMultipleOperations().branch(branch).operation(Put.of(keys.get(i), IcebergTable.of("path" + i, 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit " + i)).commit();
}
branch = (Branch) getApi().getReference().refName(branch.getName()).get();
Reference reference = refMode.transform(branch);
List<Entry> entries = getApi().getEntries().reference(reference).namespaceDepth(0).get().getEntries();
assertThat(entries).isNotNull().hasSize(6);
entries = getApi().getEntries().reference(reference).namespaceDepth(0).filter("entry.namespace.matches('a(\\\\.|$)')").get().getEntries();
assertThat(entries).isNotNull().hasSize(5);
entries = getApi().getEntries().reference(reference).namespaceDepth(1).filter("entry.namespace.matches('a(\\\\.|$)')").get().getEntries();
assertThat(entries).hasSize(1);
assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a")));
entries = getApi().getEntries().reference(reference).namespaceDepth(2).filter("entry.namespace.matches('a(\\\\.|$)')").get().getEntries();
assertThat(entries).hasSize(3);
assertThat(entries.get(2)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "thirdTable")));
assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "b")));
assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "boo")));
entries = getApi().getEntries().reference(reference).namespaceDepth(3).filter("entry.namespace.matches('a\\\\.b(\\\\.|$)')").get().getEntries();
assertThat(entries).hasSize(2);
assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c")));
assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "fourthTable")));
entries = getApi().getEntries().reference(reference).namespaceDepth(4).filter("entry.namespace.matches('a\\\\.b\\\\.c(\\\\.|$)')").get().getEntries();
assertThat(entries).hasSize(2);
assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c", "firstTable")));
assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c", "secondTable")));
entries = getApi().getEntries().reference(reference).namespaceDepth(5).filter("entry.namespace.matches('(\\\\.|$)')").get().getEntries();
assertThat(entries).isEmpty();
entries = getApi().getEntries().reference(reference).namespaceDepth(3).filter("entry.namespace.matches('(\\\\.|$)')").get().getEntries();
assertThat(entries).hasSize(3);
assertThat(entries.get(2)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c")));
assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "fourthTable")));
assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "boo", "fifthTable")));
assumeTrue(ReferenceMode.DETACHED != refMode);
// check that implicit namespaces are properly detected
checkNamespaces(reference, Arrays.asList("a", "a.b", "a.boo", "a.b.c"), Arrays.asList(first, second, third, fourth, fifth));
}
use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class AbstractRestInvalidRefs method testInvalidNamedRefs.
@Test
public void testInvalidNamedRefs() {
ContentKey key = ContentKey.of("x");
String invalidRef = "1234567890123456";
assertThatThrownBy(() -> getApi().getCommitLog().refName(invalidRef).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE);
assertThatThrownBy(() -> getApi().getEntries().refName(invalidRef).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE);
assertThatThrownBy(() -> getApi().getContent().key(key).refName(invalidRef).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE);
assertThatThrownBy(() -> getApi().getContent().refName(invalidRef).key(key).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 AbstractRestInvalidWithHttp method invalidHashes.
@ParameterizedTest
@CsvSource({ "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 invalidHashes(String invalidHashIn, String validHash) {
// CsvSource maps an empty string as null
String invalidHash = invalidHashIn != null ? invalidHashIn : "";
String validBranchName = "hello";
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(validBranchName).hash(invalidHash).commitMeta(CommitMeta.fromMessage("")).commit()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE).hasMessageContaining(opsCountMsg), () -> assertThatThrownBy(() -> getApi().deleteBranch().branchName(validBranchName).hash(invalidHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().assignTag().tagName(validBranchName).hash(invalidHash).assignTo(tag).assign()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".oldHash: " + HASH_MESSAGE), () -> {
if (null != getHttpClient()) {
assertThatThrownBy(() -> getHttpClient().newRequest().path("trees/branch/{branchName}/merge").resolveTemplate("branchName", validBranchName).queryParam("expectedHash", invalidHash).post(null)).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining("mergeRefIntoBranch.merge: must not be null").hasMessageContaining(".hash: " + HASH_MESSAGE);
}
}, () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().branchName(validBranchName).hash(invalidHash).fromRef(getApi().getDefaultBranch()).merge()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().deleteTag().tagName(validBranchName).hash(invalidHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().branchName(validBranchName).hash(invalidHash).fromRefName("main").hashesToTransplant(singletonList(getApi().getReference().refName("main").get().getHash())).transplant()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().refName(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".request.requestedKeys: size must be between 1 and 2147483647").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".request.requestedKeys: size must be between 1 and 2147483647").hasMessageContaining(".hashOnRef: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().key(key).refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hashOnRef: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getCommitLog().refName(validBranchName).untilHash(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".params.startHash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getCommitLog().refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".params.endHash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getEntries().refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".params.hashOnRef: " + HASH_MESSAGE));
}
Aggregations