use of org.projectnessie.versioned.TagName in project nessie by projectnessie.
the class AbstractDatabaseAdapterTest method createTag.
@Test
void createTag() throws Exception {
TagName create = TagName.of("createTag");
createNamedRef(create, BranchName.of(create.getName()));
}
use of org.projectnessie.versioned.TagName in project nessie by projectnessie.
the class AbstractDatabaseAdapterTest method assign.
@Test
void assign() throws Exception {
BranchName main = BranchName.of("main");
TagName tag = TagName.of("tag");
TagName branch = TagName.of("branch");
databaseAdapter.create(branch, databaseAdapter.hashOnReference(main, Optional.empty()));
databaseAdapter.create(tag, databaseAdapter.hashOnReference(main, Optional.empty()));
Hash beginning = databaseAdapter.hashOnReference(main, Optional.empty());
Hash[] commits = new Hash[3];
for (int i = 0; i < commits.length; i++) {
commits[i] = databaseAdapter.commit(ImmutableCommitAttempt.builder().commitToBranch(main).commitMetaSerialized(ByteString.copyFromUtf8("commit meta " + i)).addPuts(KeyWithBytes.of(Key.of("bar", Integer.toString(i)), ContentId.of("contentId-" + i), (byte) 0, ByteString.copyFromUtf8("hello " + i))).build());
}
Hash expect = beginning;
for (Hash commit : commits) {
assertThat(Arrays.asList(databaseAdapter.hashOnReference(branch, Optional.empty()), databaseAdapter.hashOnReference(tag, Optional.empty()))).containsExactly(expect, expect);
databaseAdapter.assign(tag, Optional.of(expect), commit);
databaseAdapter.assign(branch, Optional.of(expect), commit);
expect = commit;
}
assertThat(Arrays.asList(databaseAdapter.hashOnReference(branch, Optional.empty()), databaseAdapter.hashOnReference(tag, Optional.empty()))).containsExactly(commits[commits.length - 1], commits[commits.length - 1]);
}
use of org.projectnessie.versioned.TagName in project nessie by projectnessie.
the class AbstractGetNamedReferences method parameterValidationNamedRef.
@Test
public void parameterValidationNamedRef() throws Exception {
BranchName main = BranchName.of(MAIN_BRANCH);
BranchName parameterValidation = BranchName.of("parameterValidation");
TagName parameterValidationTag = TagName.of("parameterValidationTag");
Hash hash = databaseAdapter.noAncestorHash();
assertThat(databaseAdapter.hashOnReference(main, Optional.empty())).isEqualTo(hash);
databaseAdapter.create(parameterValidation, hash);
databaseAdapter.create(parameterValidationTag, hash);
assertAll(() -> assertThatThrownBy(() -> databaseAdapter.namedRef(main.getName(), null)).isInstanceOf(NullPointerException.class).hasMessage("Parameter for GetNamedRefsParams must not be null"), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_COMMON_ANCESTOR).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().tagRetrieveOptions(COMPUTE_COMMON_ANCESTOR).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).baseReference(BranchName.of("no-no-no")).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference 'no-no-no' not found"), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).baseReference(TagName.of("blah-no")).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference 'blah-no' not found"), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidationTag.getName(), GetNamedRefsParams.builder().tagRetrieveOptions(RetrieveOptions.OMIT).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference '" + parameterValidationTag.getName() + "' not found"));
}
use of org.projectnessie.versioned.TagName in project nessie by projectnessie.
the class AbstractGetNamedReferences method parameterValidationNamedRefs.
@Test
public void parameterValidationNamedRefs() throws Exception {
BranchName main = BranchName.of(MAIN_BRANCH);
BranchName parameterValidation = BranchName.of("parameterValidation");
TagName parameterValidationTag = TagName.of("parameterValidationTag");
Hash hash = databaseAdapter.noAncestorHash();
assertThat(databaseAdapter.hashOnReference(main, Optional.empty())).isEqualTo(hash);
databaseAdapter.create(parameterValidation, hash);
databaseAdapter.create(parameterValidationTag, hash);
assertAll(() -> assertThatThrownBy(() -> databaseAdapter.namedRefs(null)).isInstanceOf(NullPointerException.class).hasMessage("Parameter for GetNamedRefsParams must not be null."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_COMMON_ANCESTOR).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().tagRetrieveOptions(COMPUTE_COMMON_ANCESTOR).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).baseReference(BranchName.of("no-no-no")).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference 'no-no-no' not found"), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).baseReference(TagName.of("blah-no")).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference 'blah-no' not found"), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(RetrieveOptions.OMIT).tagRetrieveOptions(RetrieveOptions.OMIT).build())).isInstanceOf(IllegalArgumentException.class).hasMessage("Must retrieve branches or tags or both."));
}
use of org.projectnessie.versioned.TagName in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method create.
@Override
public Hash create(NamedRef ref, Hash target) throws ReferenceAlreadyExistsException, ReferenceNotFoundException {
try {
return casOpLoop("createRef", ref, CasOpVariant.REF_UPDATE, (ctx, pointer, branchCommits, newKeyLists) -> {
if (refFromGlobalState(pointer, ref.getName()) != null) {
throw referenceAlreadyExists(ref);
}
Hash hash = target;
if (hash == null) {
// Special case: Don't validate, if the 'target' parameter is null.
// This is mostly used for tests that re-create the default-branch.
hash = NO_ANCESTOR;
}
validateHashExists(ctx, hash);
// Need a new empty global-log entry to be able to CAS
GlobalStateLogEntry newGlobalHead = noopGlobalLogEntry(ctx, pointer);
RefLogEntry.RefType refType = ref instanceof TagName ? RefLogEntry.RefType.Tag : RefLogEntry.RefType.Branch;
RefLogEntry newRefLog = writeRefLogEntry(ctx, pointer, ref.getName(), refType, hash, RefLogEntry.Operation.CREATE_REFERENCE, commitTimeInMicros(), Collections.emptyList());
return updateGlobalStatePointer(ref, pointer, hash, newGlobalHead, newRefLog);
}, () -> createConflictMessage("Retry-Failure", ref, target));
} catch (ReferenceAlreadyExistsException | ReferenceNotFoundException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations