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));
}
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);
}
}
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);
}
}
Aggregations