use of org.projectnessie.versioned.Key in project nessie by projectnessie.
the class CommitBench method initialOperations.
static List<Operation<BaseContent>> initialOperations(BenchmarkParam bp, List<Key> keys, Map<Key, String> contentIds) {
List<Operation<BaseContent>> operations = new ArrayList<>(bp.tablesPerCommit);
for (Key key : keys) {
String contentId = contentIds.get(key);
operations.add(Put.of(key, withGlobal("0", "initial commit content", contentId)));
}
return operations;
}
use of org.projectnessie.versioned.Key in project nessie by projectnessie.
the class ContentApiImpl method getMultipleContents.
@Override
public GetMultipleContentsResponse getMultipleContents(String namedRef, String hashOnRef, GetMultipleContentsRequest request) throws NessieNotFoundException {
try {
WithHash<NamedRef> ref = namedRefWithHashOrThrow(namedRef, hashOnRef);
List<ContentKey> externalKeys = request.getRequestedKeys();
List<Key> internalKeys = externalKeys.stream().map(ContentApiImpl::toKey).collect(Collectors.toList());
Map<Key, Content> values = getStore().getValues(ref.getHash(), internalKeys);
List<ContentWithKey> output = values.entrySet().stream().map(e -> ContentWithKey.of(toContentKey(e.getKey()), e.getValue())).collect(Collectors.toList());
return ImmutableGetMultipleContentsResponse.builder().contents(output).build();
} catch (ReferenceNotFoundException ex) {
throw new NessieReferenceNotFoundException(ex.getMessage(), ex);
}
}
use of org.projectnessie.versioned.Key in project nessie by projectnessie.
the class NamespaceApiImpl method deleteNamespace.
@Override
public void deleteNamespace(NamespaceParams params) throws NessieReferenceNotFoundException, NessieNamespaceNotEmptyException, NessieNamespaceNotFoundException {
BranchName branch = branchFromRefName(params.getRefName());
try {
Namespace namespace = getNamespace(params, branch);
Delete delete = Delete.of(ContentKey.of(namespace.getElements()));
Callable<Void> validator = () -> {
try (Stream<WithType<Key, Type>> keys = getStore().getKeys(branch)) {
if (keys.anyMatch(k -> Namespace.of(k.getValue().getElements()).name().startsWith(params.getNamespace().name()) && k.getType() != Type.NAMESPACE)) {
throw namespaceNotEmptyException(params);
}
}
return null;
};
commit(branch, "delete namespace " + namespace.name(), TreeApiImpl.toOp(delete), validator);
} catch (ReferenceNotFoundException | ReferenceConflictException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
}
}
use of org.projectnessie.versioned.Key in project nessie by projectnessie.
the class AbstractCommitLog method commitLogExtendedNoGlobalState.
@Test
public void commitLogExtendedNoGlobalState() throws Exception {
BranchName branch = BranchName.of("commitLogExtended");
Hash firstParent = store().create(branch, Optional.empty());
int numCommits = 10;
List<Hash> hashes = IntStream.rangeClosed(1, numCommits).mapToObj(i -> {
try {
return commit("Commit #" + i).put("k" + i, onRef("v" + i, "c" + i)).put("key" + i, onRef("value" + i, "cid" + i)).delete("delete" + i).toBranch(branch);
} catch (Exception e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
List<Hash> parentHashes = Stream.concat(Stream.of(firstParent), hashes.subList(0, 9).stream()).collect(Collectors.toList());
assertThat(Lists.reverse(commitsList(branch, false))).allSatisfy(c -> {
assertThat(c.getOperations()).isNull();
assertThat(c.getParentHash()).isNull();
}).extracting(Commit::getHash).containsExactlyElementsOf(hashes);
List<Commit<CommitMessage, BaseContent>> commits = Lists.reverse(commitsList(branch, true));
assertThat(IntStream.rangeClosed(1, numCommits)).allSatisfy(i -> {
Commit<CommitMessage, BaseContent> c = commits.get(i - 1);
assertThat(c).extracting(Commit::getCommitMeta, Commit::getHash, Commit::getParentHash, Commit::getOperations).containsExactly(commitMessage("Commit #" + i), hashes.get(i - 1), parentHashes.get(i - 1), Arrays.asList(Delete.of(Key.of("delete" + i)), Put.of(Key.of("k" + i), onRef("v" + i, "c" + i)), Put.of(Key.of("key" + i), onRef("value" + i, "cid" + i))));
});
}
use of org.projectnessie.versioned.Key in project nessie by projectnessie.
the class AbstractCommits method commitWithValidation.
@Test
void commitWithValidation() throws Exception {
BranchName branch = BranchName.of("main");
Key key = Key.of("my", "table0");
Hash branchHead = store().getNamedRef(branch.getName(), GetNamedRefsParams.DEFAULT).getHash();
String cid = "cid-0";
RuntimeException exception = new ArithmeticException("Whatever");
assertThatThrownBy(() -> doCommitWithValidation(branch, cid, key, () -> {
// do some operations here
try {
assertThat(store().getValue(branch, key)).isNull();
store().getKeys(branch).close();
} catch (ReferenceNotFoundException e) {
throw new RuntimeException(e);
}
// let the custom commit-validation fail
throw exception;
})).isSameAs(exception);
assertThat(store().getNamedRef(branch.getName(), GetNamedRefsParams.DEFAULT).getHash()).isEqualTo(branchHead);
assertThat(store().getValue(branch, key)).isNull();
}
Aggregations