Search in sources :

Example 6 with ReferenceInfo

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

Example 7 with ReferenceInfo

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

Example 8 with ReferenceInfo

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";
}
Also used : PersistVersionStore(org.projectnessie.versioned.persist.store.PersistVersionStore) MediaType(javax.ws.rs.core.MediaType) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) BackendLimitExceededException(org.projectnessie.versioned.BackendLimitExceededException) BaseContent(org.projectnessie.versioned.testworker.BaseContent) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) BackendLimitExceededException(org.projectnessie.versioned.BackendLimitExceededException) ConstraintDefinitionException(javax.validation.ConstraintDefinitionException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) ConstraintDeclarationException(javax.validation.ConstraintDeclarationException) GroupDefinitionException(javax.validation.GroupDefinitionException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) DatabaseAdapter(org.projectnessie.versioned.persist.adapter.DatabaseAdapter) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 9 with ReferenceInfo

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

Example 10 with ReferenceInfo

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);
}
Also used : GlobalStatePointer(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStatePointer) 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)

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