use of org.projectnessie.error.BaseNessieClientServerException 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.error.BaseNessieClientServerException in project nessie by projectnessie.
the class AbstractRestNamespace method testNamespaceDeletion.
@Test
public void testNamespaceDeletion() throws BaseNessieClientServerException {
Branch branch = createBranch("testNamespaceDeletion");
CommitMultipleOperationsBuilder commit = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("verifyAllContentAndOperationTypes"));
contentAndOperationTypes().flatMap(c -> c.globalOperation == null ? Stream.of(c.operation) : Stream.of(c.operation, c.globalOperation)).forEach(commit::operation);
commit.commit();
List<Entry> entries = contentAndOperationTypes().filter(c -> c.operation instanceof Put).map(c -> Entry.builder().type(c.type).name(c.operation.getKey()).build()).collect(Collectors.toList());
for (Entry e : entries) {
Namespace namespace = e.getName().getNamespace();
assertThat(getApi().getNamespace().refName(branch.getName()).namespace(namespace).get()).isEqualTo(namespace);
assertThatThrownBy(() -> getApi().deleteNamespace().refName(branch.getName()).namespace(namespace).delete()).isInstanceOf(NessieNamespaceNotEmptyException.class).hasMessage(String.format("Namespace '%s' is not empty", namespace));
}
}
use of org.projectnessie.error.BaseNessieClientServerException in project nessie by projectnessie.
the class AbstractRestContents method verifyAllContentAndOperationTypes.
@Test
public void verifyAllContentAndOperationTypes() throws BaseNessieClientServerException {
Branch branch = createBranch("contentAndOperationAll");
CommitMultipleOperationsBuilder commit = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("verifyAllContentAndOperationTypes"));
contentAndOperationTypes().flatMap(c -> c.globalOperation == null ? Stream.of(c.operation) : Stream.of(c.operation, c.globalOperation)).forEach(commit::operation);
commit.commit();
List<Entry> entries = getApi().getEntries().refName(branch.getName()).get().getEntries();
List<Entry> expect = contentAndOperationTypes().filter(c -> c.operation instanceof Put).map(c -> Entry.builder().type(c.type).name(c.operation.getKey()).build()).collect(Collectors.toList());
assertThat(entries).containsExactlyInAnyOrderElementsOf(expect);
}
use of org.projectnessie.error.BaseNessieClientServerException in project nessie by projectnessie.
the class AbstractRestReferences method referenceNames.
@ParameterizedTest
@ValueSource(strings = { "normal", "with-no_space", "slash/thing" })
public void referenceNames(String refNamePart) throws BaseNessieClientServerException {
String tagName = "tag" + refNamePart;
String branchName = "branch" + refNamePart;
String branchName2 = "branch2" + refNamePart;
String root = "ref_name_" + refNamePart.replaceAll("[^a-z]", "");
Branch main = createBranch(root);
IcebergTable meta = IcebergTable.of("meep", 42, 42, 42, 42);
main = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("common-merge-ancestor").properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Operation.Put.of(ContentKey.of("meep"), meta)).commit();
String someHash = main.getHash();
Reference createdTag = getApi().createReference().sourceRefName(main.getName()).reference(Tag.of(tagName, someHash)).create();
assertEquals(Tag.of(tagName, someHash), createdTag);
Reference createdBranch1 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName, someHash)).create();
assertEquals(Branch.of(branchName, someHash), createdBranch1);
Reference createdBranch2 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName2, someHash)).create();
assertEquals(Branch.of(branchName2, someHash), createdBranch2);
Map<String, Reference> references = getApi().getAllReferences().get().getReferences().stream().filter(r -> root.equals(r.getName()) || r.getName().endsWith(refNamePart)).collect(Collectors.toMap(Reference::getName, Function.identity()));
assertThat(references).containsAllEntriesOf(ImmutableMap.of(main.getName(), main, createdTag.getName(), createdTag, createdBranch1.getName(), createdBranch1, createdBranch2.getName(), createdBranch2));
assertThat(references.get(main.getName())).isInstanceOf(Branch.class);
assertThat(references.get(createdTag.getName())).isInstanceOf(Tag.class);
assertThat(references.get(createdBranch1.getName())).isInstanceOf(Branch.class);
assertThat(references.get(createdBranch2.getName())).isInstanceOf(Branch.class);
Reference tagRef = references.get(tagName);
Reference branchRef = references.get(branchName);
Reference branchRef2 = references.get(branchName2);
String tagHash = tagRef.getHash();
String branchHash = branchRef.getHash();
String branchHash2 = branchRef2.getHash();
assertThat(getApi().getReference().refName(tagName).get()).isEqualTo(tagRef);
assertThat(getApi().getReference().refName(branchName).get()).isEqualTo(branchRef);
EntriesResponse entries = getApi().getEntries().refName(tagName).get();
assertThat(entries).isNotNull();
entries = getApi().getEntries().refName(branchName).get();
assertThat(entries).isNotNull();
LogResponse log = getApi().getCommitLog().refName(tagName).get();
assertThat(log).isNotNull();
log = getApi().getCommitLog().refName(branchName).get();
assertThat(log).isNotNull();
// Need to have at least one op, otherwise all following operations (assignTag/Branch, merge,
// delete) will fail
meta = IcebergTable.of("foo", 42, 42, 42, 42);
getApi().commitMultipleOperations().branchName(branchName).hash(branchHash).operation(Put.of(ContentKey.of("some-key"), meta)).commitMeta(CommitMeta.fromMessage("One dummy op")).commit();
log = getApi().getCommitLog().refName(branchName).get();
String newHash = log.getLogEntries().get(0).getCommitMeta().getHash();
getApi().assignTag().tagName(tagName).hash(tagHash).assignTo(Branch.of(branchName, newHash)).assign();
getApi().assignBranch().branchName(branchName).hash(newHash).assignTo(Branch.of(branchName, newHash)).assign();
getApi().mergeRefIntoBranch().branchName(branchName2).hash(branchHash2).fromRefName(branchName).fromHash(newHash).merge();
}
use of org.projectnessie.error.BaseNessieClientServerException in project nessie by projectnessie.
the class AbstractRestReferences method testReferencesHaveMetadataProperties.
@Test
public void testReferencesHaveMetadataProperties() throws BaseNessieClientServerException {
String branchPrefix = "branchesHaveMetadataProperties";
String tagPrefix = "tagsHaveMetadataProperties";
int numBranches = 5;
int commitsPerBranch = 10;
for (int i = 0; i < numBranches; i++) {
Reference r = getApi().createReference().reference(Branch.of(branchPrefix + i, null)).create();
String currentHash = r.getHash();
currentHash = createCommits(r, 1, commitsPerBranch, currentHash);
getApi().createReference().reference(Tag.of(tagPrefix + i, currentHash)).sourceRefName(r.getName()).create();
}
// not fetching additional metadata
List<Reference> references = getApi().getAllReferences().get().getReferences();
Optional<Reference> main = references.stream().filter(r -> r.getName().equals("main")).findFirst();
assertThat(main).isPresent();
assertThat(references.stream().filter(r -> r.getName().startsWith(branchPrefix)).map(r -> (Branch) r)).hasSize(numBranches).allSatisfy(branch -> assertThat(branch.getMetadata()).isNull());
assertThat(references.stream().filter(r -> r.getName().startsWith(tagPrefix)).map(r -> (Tag) r)).hasSize(numBranches).allSatisfy(tag -> assertThat(tag.getMetadata()).isNull());
// fetching additional metadata for each reference
references = getApi().getAllReferences().fetch(FetchOption.ALL).get().getReferences();
assertThat(references.stream().filter(r -> r.getName().startsWith(branchPrefix)).map(r -> (Branch) r)).hasSize(numBranches).allSatisfy(branch -> verifyMetadataProperties(commitsPerBranch, 0, branch, main.get(), commitsPerBranch));
assertThat(references.stream().filter(r -> r.getName().startsWith(tagPrefix)).map(r -> (Tag) r)).hasSize(numBranches).allSatisfy(this::verifyMetadataProperties);
}
Aggregations