Search in sources :

Example 11 with ReferenceInfo

use of org.projectnessie.versioned.ReferenceInfo in project nessie by projectnessie.

the class NonTransactionalDatabaseAdapter method namedRef.

@Override
public ReferenceInfo<ByteString> namedRef(String ref, GetNamedRefsParams params) throws ReferenceNotFoundException {
    Preconditions.checkNotNull(params, "Parameter for GetNamedRefsParams must not be null");
    GlobalStatePointer pointer = fetchGlobalPointer(NON_TRANSACTIONAL_OPERATION_CONTEXT);
    ReferenceInfo<ByteString> refHead = referenceHead(pointer, ref);
    Hash defaultBranchHead = namedRefsDefaultBranchHead(params, pointer);
    Stream<ReferenceInfo<ByteString>> refs = Stream.of(refHead);
    return namedRefsFilterAndEnhance(NON_TRANSACTIONAL_OPERATION_CONTEXT, params, defaultBranchHead, refs).findFirst().orElseThrow(() -> referenceNotFound(ref));
}
Also used : GlobalStatePointer(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStatePointer) ByteString(com.google.protobuf.ByteString) 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) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo)

Example 12 with ReferenceInfo

use of org.projectnessie.versioned.ReferenceInfo in project nessie by projectnessie.

the class AbstractDatabaseAdapterTest method createNamedRef.

private void createNamedRef(NamedRef create, NamedRef opposite) throws Exception {
    BranchName branch = BranchName.of("main");
    try (Stream<ReferenceInfo<ByteString>> refs = databaseAdapter.namedRefs(GetNamedRefsParams.DEFAULT)) {
        assertThat(refs.map(ReferenceInfo::getNamedRef)).containsExactlyInAnyOrder(branch);
    }
    Hash mainHash = databaseAdapter.hashOnReference(branch, Optional.empty());
    assertThatThrownBy(() -> databaseAdapter.hashOnReference(create, Optional.empty())).isInstanceOf(ReferenceNotFoundException.class);
    Hash createHash = databaseAdapter.create(create, databaseAdapter.hashOnReference(branch, Optional.empty()));
    assertThat(createHash).isEqualTo(mainHash);
    try (Stream<ReferenceInfo<ByteString>> refs = databaseAdapter.namedRefs(GetNamedRefsParams.DEFAULT)) {
        assertThat(refs.map(ReferenceInfo::getNamedRef)).containsExactlyInAnyOrder(branch, create);
    }
    assertThatThrownBy(() -> databaseAdapter.create(create, databaseAdapter.hashOnReference(branch, Optional.empty()))).isInstanceOf(ReferenceAlreadyExistsException.class);
    assertThat(databaseAdapter.hashOnReference(create, Optional.empty())).isEqualTo(createHash);
    assertThatThrownBy(() -> databaseAdapter.hashOnReference(opposite, Optional.empty())).isInstanceOf(ReferenceNotFoundException.class);
    assertThatThrownBy(() -> databaseAdapter.create(BranchName.of(create.getName()), databaseAdapter.hashOnReference(branch, Optional.empty()))).isInstanceOf(ReferenceAlreadyExistsException.class);
    assertThatThrownBy(() -> databaseAdapter.delete(create, Optional.of(Hash.of("dead00004242fee18eef")))).isInstanceOf(ReferenceConflictException.class);
    assertThatThrownBy(() -> databaseAdapter.delete(opposite, Optional.of(createHash))).isInstanceOf(ReferenceNotFoundException.class);
    databaseAdapter.delete(create, Optional.of(createHash));
    assertThatThrownBy(() -> databaseAdapter.hashOnReference(create, Optional.empty())).isInstanceOf(ReferenceNotFoundException.class);
    try (Stream<ReferenceInfo<ByteString>> refs = databaseAdapter.namedRefs(GetNamedRefsParams.DEFAULT)) {
        assertThat(refs.map(ReferenceInfo::getNamedRef)).containsExactlyInAnyOrder(branch);
    }
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo)

Example 13 with ReferenceInfo

use of org.projectnessie.versioned.ReferenceInfo in project nessie by projectnessie.

the class AbstractDatabaseAdapterTest method multipleRepositories.

@Test
void multipleRepositories(@NessieDbAdapter @NessieDbAdapterConfigItem(name = "repository.id", value = "foo") DatabaseAdapter foo, @NessieDbAdapter @NessieDbAdapterConfigItem(name = "repository.id", value = "bar") DatabaseAdapter bar) throws Exception {
    BranchName main = BranchName.of("main");
    BranchName fooBranchName = BranchName.of("foo-branch");
    BranchName barBranchName = BranchName.of("bar-branch");
    ByteString fooCommitMeta = ByteString.copyFromUtf8("meta-foo");
    ByteString barCommitMeta = ByteString.copyFromUtf8("meta-bar");
    foo.commit(ImmutableCommitAttempt.builder().commitToBranch(main).commitMetaSerialized(fooCommitMeta).addPuts(KeyWithBytes.of(Key.of("foo"), ContentId.of("foo"), (byte) 0, ByteString.copyFromUtf8("foo"))).build());
    bar.commit(ImmutableCommitAttempt.builder().commitToBranch(main).commitMetaSerialized(barCommitMeta).addPuts(KeyWithBytes.of(Key.of("bar"), ContentId.of("bar"), (byte) 0, ByteString.copyFromUtf8("bar"))).build());
    Hash fooMain = foo.hashOnReference(main, Optional.empty());
    Hash barMain = bar.hashOnReference(main, Optional.empty());
    Hash fooBranch = foo.create(fooBranchName, fooMain);
    Hash barBranch = bar.create(barBranchName, barMain);
    assertThat(fooMain).isNotEqualTo(barMain).isEqualTo(fooBranch);
    assertThat(barMain).isNotEqualTo(fooMain).isEqualTo(barBranch);
    // Verify that key-prefix "foo" only sees "its" main-branch and foo-branch
    try (Stream<ReferenceInfo<ByteString>> refs = foo.namedRefs(GetNamedRefsParams.DEFAULT)) {
        assertThat(refs).containsExactlyInAnyOrder(ReferenceInfo.of(fooMain, main), ReferenceInfo.of(fooBranch, fooBranchName));
    }
    try (Stream<ReferenceInfo<ByteString>> refs = bar.namedRefs(GetNamedRefsParams.DEFAULT)) {
        assertThat(refs).containsExactlyInAnyOrder(ReferenceInfo.of(barMain, main), ReferenceInfo.of(barBranch, barBranchName));
    }
    assertThatThrownBy(() -> foo.commitLog(barBranch)).isInstanceOf(ReferenceNotFoundException.class);
    assertThatThrownBy(() -> bar.commitLog(fooBranch)).isInstanceOf(ReferenceNotFoundException.class);
    try (Stream<CommitLogEntry> log = foo.commitLog(fooBranch)) {
        assertThat(log.collect(Collectors.toList())).extracting(CommitLogEntry::getMetadata).containsExactlyInAnyOrder(fooCommitMeta);
    }
    try (Stream<CommitLogEntry> log = bar.commitLog(barBranch)) {
        assertThat(log.collect(Collectors.toList())).extracting(CommitLogEntry::getMetadata).containsExactlyInAnyOrder(barCommitMeta);
    }
}
Also used : CommitLogEntry(org.projectnessie.versioned.persist.adapter.CommitLogEntry) ByteString(com.google.protobuf.ByteString) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Test(org.junit.jupiter.api.Test)

Aggregations

ReferenceInfo (org.projectnessie.versioned.ReferenceInfo)13 Hash (org.projectnessie.versioned.Hash)11 BranchName (org.projectnessie.versioned.BranchName)7 ByteString (com.google.protobuf.ByteString)5 Test (org.junit.jupiter.api.Test)5 DatabaseAdapterUtil.randomHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)5 DatabaseAdapterUtil.verifyExpectedHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash)4 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)3 TagName (org.projectnessie.versioned.TagName)3 Optional (java.util.Optional)2 Stream (java.util.stream.Stream)2 GetNamedRefsParams (org.projectnessie.versioned.GetNamedRefsParams)2 ImmutableReferenceInfo (org.projectnessie.versioned.ImmutableReferenceInfo)2 NamedRef (org.projectnessie.versioned.NamedRef)2 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)2 GlobalStatePointer (org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStatePointer)2 Preconditions (com.google.common.base.Preconditions)1 Hasher (com.google.common.hash.Hasher)1 UnsafeByteOperations (com.google.protobuf.UnsafeByteOperations)1 StandardCharsets (java.nio.charset.StandardCharsets)1