use of org.projectnessie.model.Tag in project nessie by projectnessie.
the class AbstractDeltaTest method removeBranches.
@AfterEach
void removeBranches() throws NessieConflictException, NessieNotFoundException {
for (Reference ref : api.getAllReferences().get().getReferences()) {
if (ref instanceof Branch) {
api.deleteBranch().branchName(ref.getName()).hash(ref.getHash()).delete();
}
if (ref instanceof Tag) {
api.deleteTag().tagName(ref.getName()).hash(ref.getHash()).delete();
}
}
api.createReference().reference(Branch.of("main", null)).create();
api.close();
api = null;
}
use of org.projectnessie.model.Tag in project nessie by projectnessie.
the class AbstractSparkSqlTest method removeBranches.
@AfterEach
void removeBranches() throws NessieConflictException, NessieNotFoundException {
for (Reference ref : api.getAllReferences().get().getReferences()) {
if (ref instanceof Branch) {
api.deleteBranch().branchName(ref.getName()).hash(ref.getHash()).delete();
}
if (ref instanceof Tag) {
api.deleteTag().tagName(ref.getName()).hash(ref.getHash()).delete();
}
}
api.createReference().reference(Branch.of("main", null)).create();
api.close();
api = null;
}
use of org.projectnessie.model.Tag 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));
}
use of org.projectnessie.model.Tag in project nessie by projectnessie.
the class AbstractRest method tearDown.
@AfterEach
public void tearDown() throws Exception {
Branch defaultBranch = api.getDefaultBranch();
for (Reference ref : api.getAllReferences().get().getReferences()) {
if (ref.getName().equals(defaultBranch.getName())) {
continue;
}
if (ref instanceof Branch) {
api.deleteBranch().branch((Branch) ref).delete();
} else if (ref instanceof Tag) {
api.deleteTag().tag((Tag) ref).delete();
}
}
api.close();
}
use of org.projectnessie.model.Tag 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();
}
Aggregations