Search in sources :

Example 1 with TagName

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()));
}
Also used : TagName(org.projectnessie.versioned.TagName) Test(org.junit.jupiter.api.Test)

Example 2 with TagName

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]);
}
Also used : TagName(org.projectnessie.versioned.TagName) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 3 with TagName

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"));
}
Also used : TagName(org.projectnessie.versioned.TagName) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 4 with TagName

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."));
}
Also used : TagName(org.projectnessie.versioned.TagName) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 5 with TagName

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);
    }
}
Also used : ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) GlobalStateLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry) RefType(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.RefType) TagName(org.projectnessie.versioned.TagName) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Hash(org.projectnessie.versioned.Hash) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) RefLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) RefLogNotFoundException(org.projectnessie.versioned.RefLogNotFoundException) VersionStoreException(org.projectnessie.versioned.VersionStoreException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException)

Aggregations

TagName (org.projectnessie.versioned.TagName)12 Hash (org.projectnessie.versioned.Hash)11 Test (org.junit.jupiter.api.Test)8 BranchName (org.projectnessie.versioned.BranchName)7 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)4 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)4 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)4 VersionStoreException (org.projectnessie.versioned.VersionStoreException)4 DatabaseAdapterUtil.randomHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)4 DatabaseAdapterUtil.verifyExpectedHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash)4 RefLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry)4 RefLogNotFoundException (org.projectnessie.versioned.RefLogNotFoundException)3 GlobalStateLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry)3 RefType (org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.RefType)3 ReferenceInfo (org.projectnessie.versioned.ReferenceInfo)2 ByteString (com.google.protobuf.ByteString)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1