use of org.projectnessie.versioned.ReferenceInfo in project nessie by projectnessie.
the class AbstractCommits method commitToBranch.
/*
* Test:
* - Create a new branch
* - Add a commit to it
* - Check that another commit with no operations can be added with the initial hash
* - Check the commit can be listed
* - Check that the commit can be deleted
*/
@Test
public void commitToBranch() throws Exception {
final BranchName branch = BranchName.of("foo");
final Hash createHash = store().create(branch, Optional.empty());
final Hash initialHash = store().hashOnReference(branch, Optional.empty());
assertEquals(createHash, initialHash);
final Hash commitHash0 = store().commit(branch, Optional.of(initialHash), commitMessage("Some commit"), Collections.emptyList());
final Hash commitHash = store().hashOnReference(branch, Optional.empty());
assertEquals(commitHash, commitHash0);
assertThat(commitHash).isNotEqualTo(initialHash);
store().commit(branch, Optional.of(initialHash), commitMessage("Another commit"), Collections.emptyList());
final Hash anotherCommitHash = store().hashOnReference(branch, Optional.empty());
assertThat(commitsList(branch, false)).contains(commit(anotherCommitHash, "Another commit"), commit(commitHash, "Some commit"));
assertThat(commitsList(commitHash, false)).contains(commit(commitHash, "Some commit"));
assertThrows(ReferenceConflictException.class, () -> store().delete(branch, Optional.of(initialHash)));
store().delete(branch, Optional.of(anotherCommitHash));
assertThrows(ReferenceNotFoundException.class, () -> store().hashOnReference(branch, Optional.empty()));
try (Stream<ReferenceInfo<CommitMessage>> str = store().getNamedRefs(GetNamedRefsParams.DEFAULT).filter(this::filterMainBranch)) {
assertThat(str).isEmpty();
}
assertThrows(ReferenceNotFoundException.class, () -> store().delete(branch, Optional.of(commitHash)));
}
use of org.projectnessie.versioned.ReferenceInfo in project nessie by projectnessie.
the class AbstractReferences method createAndDeleteTag.
/*
* Test:
* - Create a branch with no hash assigned to it
* - add a commit to the branch
* - create a tag for the initial hash
* - create another tag for the hash after the commit
* - check that cannot create existing tags, or tag with no assigned hash
* - check that a hash is returned by toHash
* - check the tags are returned by getNamedRefs
* - check that expected commits are returned by getCommits
* - check the branch can be deleted
*/
@Test
public void createAndDeleteTag() throws Exception {
final BranchName branch = BranchName.of("foo");
store().create(branch, Optional.empty());
final Hash initialHash = store().hashOnReference(branch, Optional.empty());
final Hash commitHash = commit("Some commit").toBranch(branch);
final TagName tag = TagName.of("tag");
store().create(tag, Optional.of(initialHash));
final TagName anotherTag = TagName.of("another-tag");
store().create(anotherTag, Optional.of(commitHash));
assertThrows(ReferenceAlreadyExistsException.class, () -> store().create(tag, Optional.of(initialHash)));
assertThat(store().hashOnReference(tag, Optional.empty())).isEqualTo(initialHash);
assertThat(store().hashOnReference(anotherTag, Optional.empty())).isEqualTo(commitHash);
List<ReferenceInfo<CommitMessage>> namedRefs;
try (Stream<ReferenceInfo<CommitMessage>> str = store().getNamedRefs(GetNamedRefsParams.DEFAULT).filter(this::filterMainBranch)) {
namedRefs = str.collect(Collectors.toList());
}
assertThat(namedRefs).containsExactlyInAnyOrder(ReferenceInfo.of(commitHash, branch), ReferenceInfo.of(initialHash, tag), ReferenceInfo.of(commitHash, anotherTag));
assertThat(commitsList(tag, false)).isEmpty();
// empty commit should not be listed
assertThat(commitsList(initialHash, false)).isEmpty();
assertThat(commitsList(anotherTag, false)).hasSize(1);
// empty commit should not be listed
assertThat(commitsList(commitHash, false)).hasSize(1);
store().delete(tag, Optional.of(initialHash));
assertThrows(ReferenceNotFoundException.class, () -> store().hashOnReference(tag, Optional.empty()));
try (Stream<ReferenceInfo<CommitMessage>> str = store().getNamedRefs(GetNamedRefsParams.DEFAULT).filter(this::filterMainBranch)) {
// foo + another-tag
assertThat(str).hasSize(2);
}
assertThrows(ReferenceNotFoundException.class, () -> store().delete(tag, Optional.of(initialHash)));
}
use of org.projectnessie.versioned.ReferenceInfo in project nessie by projectnessie.
the class ErrorTestService method unhandledExceptionInTvsStore.
/**
* Throws an exception depending on the parameter.
*
* @return nothing
* @see TestNessieError#unhandledRuntimeExceptionInStore()
* @see TestNessieError#backendThrottledExceptionInStore()
*/
@Path("unhandledExceptionInTvsStore/{exception}")
@GET
@Consumes(MediaType.APPLICATION_JSON)
public String unhandledExceptionInTvsStore(@PathParam("exception") String exception) throws ReferenceNotFoundException {
Exception ex;
switch(exception) {
case "runtime":
ex = new RuntimeException("Store.getValues-throwing");
break;
case "throttle":
ex = new BackendLimitExceededException("Store.getValues-throttled");
break;
default:
throw new IllegalArgumentException("test code error");
}
DatabaseAdapter databaseAdapter = Mockito.mock(DatabaseAdapter.class);
Mockito.when(databaseAdapter.namedRefs(Mockito.any())).thenThrow(ex);
PersistVersionStore<BaseContent, CommitMessage, BaseContent.Type> tvs = new PersistVersionStore<>(databaseAdapter, SimpleStoreWorker.INSTANCE);
try (Stream<ReferenceInfo<CommitMessage>> refs = tvs.getNamedRefs(GetNamedRefsParams.DEFAULT)) {
refs.forEach(ref -> {
});
}
return "we should not get here";
}
use of org.projectnessie.versioned.ReferenceInfo in project nessie by projectnessie.
the class AbstractReferences method createAndDeleteBranch.
/*
* Test:
* - Create a branch with no hash assigned to it
* - check that a hash is returned by toHash
* - check the branch is returned by getNamedRefs
* - check that no commits are returned using getCommits
* - check the branch cannot be created
* - check the branch can be deleted
*/
@Test
public void createAndDeleteBranch() throws Exception {
final BranchName branch = BranchName.of("foo");
store().create(branch, Optional.empty());
final Hash hash = store().hashOnReference(branch, Optional.empty());
assertThat(hash).isNotNull();
final BranchName anotherBranch = BranchName.of("bar");
final Hash createHash = store().create(anotherBranch, Optional.of(hash));
final Hash commitHash = commit("Some Commit").toBranch(anotherBranch);
assertNotEquals(createHash, commitHash);
final BranchName anotherAnotherBranch = BranchName.of("baz");
final Hash otherCreateHash = store().create(anotherAnotherBranch, Optional.of(commitHash));
assertEquals(commitHash, otherCreateHash);
List<ReferenceInfo<CommitMessage>> namedRefs;
try (Stream<ReferenceInfo<CommitMessage>> str = store().getNamedRefs(GetNamedRefsParams.DEFAULT).filter(this::filterMainBranch)) {
namedRefs = str.collect(Collectors.toList());
}
assertThat(namedRefs).containsExactlyInAnyOrder(ReferenceInfo.of(hash, branch), ReferenceInfo.of(commitHash, anotherBranch), ReferenceInfo.of(commitHash, anotherAnotherBranch));
assertThat(commitsList(branch, false)).isEmpty();
assertThat(commitsList(anotherBranch, false)).hasSize(1);
assertThat(commitsList(anotherAnotherBranch, false)).hasSize(1);
// empty commit should not be listed
assertThat(commitsList(hash, false)).isEmpty();
// empty commit should not be listed
assertThat(commitsList(commitHash, false)).hasSize(1);
assertThrows(ReferenceAlreadyExistsException.class, () -> store().create(branch, Optional.empty()));
assertThrows(ReferenceAlreadyExistsException.class, () -> store().create(branch, Optional.of(hash)));
store().delete(branch, Optional.of(hash));
assertThrows(ReferenceNotFoundException.class, () -> store().hashOnReference(branch, Optional.empty()));
try (Stream<ReferenceInfo<CommitMessage>> str = store().getNamedRefs(GetNamedRefsParams.DEFAULT).filter(this::filterMainBranch)) {
// bar + baz
assertThat(str).hasSize(2);
}
assertThrows(ReferenceNotFoundException.class, () -> store().delete(branch, Optional.of(hash)));
}
use of org.projectnessie.versioned.ReferenceInfo in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method namedRefs.
@Override
public Stream<ReferenceInfo<ByteString>> namedRefs(GetNamedRefsParams params) throws ReferenceNotFoundException {
Preconditions.checkNotNull(params, "Parameter for GetNamedRefsParams must not be null.");
Preconditions.checkArgument(namedRefsAnyRetrieves(params), "Must retrieve branches or tags or both.");
GlobalStatePointer pointer = fetchGlobalPointer(NON_TRANSACTIONAL_OPERATION_CONTEXT);
if (pointer == null) {
return Stream.empty();
}
Hash defaultBranchHead = namedRefsDefaultBranchHead(params, pointer);
Stream<ReferenceInfo<ByteString>> refs = pointer.getNamedReferencesList().stream().map(r -> ReferenceInfo.of(Hash.of(r.getRef().getHash()), toNamedRef(r.getRef().getType(), r.getName())));
return namedRefsFilterAndEnhance(NON_TRANSACTIONAL_OPERATION_CONTEXT, params, defaultBranchHead, refs);
}
Aggregations