use of org.projectnessie.model.EntriesResponse in project nessie by projectnessie.
the class AbstractRestInvalidRefs method testValidHashesOnValidNamedRefs.
@Test
public void testValidHashesOnValidNamedRefs() throws BaseNessieClientServerException {
Branch branch = createBranch("testValidHashesOnValidNamedRefs");
int commits = 10;
String currentHash = branch.getHash();
createCommits(branch, 1, commits, currentHash);
LogResponse entireLog = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(entireLog).isNotNull();
assertThat(entireLog.getLogEntries()).hasSize(commits);
EntriesResponse allEntries = getApi().getEntries().refName(branch.getName()).get();
assertThat(allEntries).isNotNull();
assertThat(allEntries.getEntries()).hasSize(commits);
List<ContentKey> keys = new ArrayList<>();
IntStream.range(0, commits).forEach(i -> keys.add(ContentKey.of("table" + i)));
// TODO: check where hashOnRef is set
Map<ContentKey, Content> allContent = getApi().getContent().keys(keys).refName(branch.getName()).get();
for (int i = 0; i < commits; i++) {
String hash = entireLog.getLogEntries().get(i).getCommitMeta().getHash();
LogResponse log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(hash).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commits - i);
assertThat(ImmutableList.copyOf(entireLog.getLogEntries()).subList(i, commits)).containsExactlyElementsOf(log.getLogEntries());
EntriesResponse entries = getApi().getEntries().refName(branch.getName()).hashOnRef(hash).get();
assertThat(entries).isNotNull();
assertThat(entries.getEntries()).hasSize(commits - i);
int idx = commits - 1 - i;
ContentKey key = ContentKey.of("table" + idx);
Content c = getApi().getContent().key(key).refName(branch.getName()).hashOnRef(hash).get().get(key);
assertThat(c).isNotNull().isEqualTo(allContent.get(key));
}
}
use of org.projectnessie.model.EntriesResponse 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.model.EntriesResponse in project nessie by projectnessie.
the class TreeApiImpl method getEntries.
@Override
public EntriesResponse getEntries(String namedRef, EntriesParams params) throws NessieNotFoundException {
Preconditions.checkArgument(params.pageToken() == null, "Paging not supported");
WithHash<NamedRef> refWithHash = namedRefWithHashOrThrow(namedRef, params.hashOnRef());
// all existing VersionStore implementations have to read all keys anyways so we don't get much
try {
List<EntriesResponse.Entry> entries;
try (Stream<EntriesResponse.Entry> entryStream = getStore().getKeys(refWithHash.getHash()).map(key -> EntriesResponse.Entry.builder().name(fromKey(key.getValue())).type((Type) key.getType()).build())) {
Stream<EntriesResponse.Entry> entriesStream = filterEntries(entryStream, params.filter());
if (params.namespaceDepth() != null && params.namespaceDepth() > 0) {
entriesStream = entriesStream.filter(e -> e.getName().getElements().size() >= params.namespaceDepth()).map(e -> truncate(e, params.namespaceDepth())).distinct();
}
entries = entriesStream.collect(ImmutableList.toImmutableList());
}
return EntriesResponse.builder().addAllEntries(entries).build();
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
}
}
Aggregations