Search in sources :

Example 1 with CommitMessage

use of org.projectnessie.versioned.testworker.CommitMessage in project nessie by projectnessie.

the class AbstractAssign method assignReferenceToFreshMain.

/**
 * Assigning a branch/tag to a fresh main without any commits didn't work in 0.9.2
 */
@Test
public void assignReferenceToFreshMain() throws ReferenceNotFoundException, ReferenceAlreadyExistsException, ReferenceConflictException {
    ReferenceInfo<CommitMessage> main = store.getNamedRef("main", GetNamedRefsParams.DEFAULT);
    try (Stream<Commit<CommitMessage, BaseContent>> commits = store().getCommits(main.getHash(), false)) {
        assertThat(commits).isEmpty();
    }
    try (Stream<ReferenceInfo<CommitMessage>> refs = store().getNamedRefs(GetNamedRefsParams.DEFAULT)) {
        assertThat(refs).extracting(r -> r.getNamedRef().getName()).containsExactly(main.getNamedRef().getName());
    }
    BranchName testBranch = BranchName.of("testBranch");
    Hash testBranchHash = store.create(testBranch, Optional.empty());
    store.assign(testBranch, Optional.of(testBranchHash), main.getHash());
    assertThat(store.getNamedRef(testBranch.getName(), GetNamedRefsParams.DEFAULT).getHash()).isEqualTo(main.getHash());
    TagName testTag = TagName.of("testTag");
    Hash testTagHash = store.create(testTag, Optional.empty());
    store.assign(testTag, Optional.of(testTagHash), main.getHash());
    assertThat(store.getNamedRef(testTag.getName(), GetNamedRefsParams.DEFAULT).getHash()).isEqualTo(main.getHash());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Hash(org.projectnessie.versioned.Hash) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) Commit(org.projectnessie.versioned.Commit) TagName(org.projectnessie.versioned.TagName) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) VersionStoreException(org.projectnessie.versioned.VersionStoreException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) GetNamedRefsParams(org.projectnessie.versioned.GetNamedRefsParams) Test(org.junit.jupiter.api.Test) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) Stream(java.util.stream.Stream) BaseContent(org.projectnessie.versioned.testworker.BaseContent) VersionStore(org.projectnessie.versioned.VersionStore) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Optional(java.util.Optional) Commit(org.projectnessie.versioned.Commit) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) 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 2 with CommitMessage

use of org.projectnessie.versioned.testworker.CommitMessage in project nessie by projectnessie.

the class AbstractCommitLog method commitLogExtendedNoGlobalState.

@Test
public void commitLogExtendedNoGlobalState() throws Exception {
    BranchName branch = BranchName.of("commitLogExtended");
    Hash firstParent = store().create(branch, Optional.empty());
    int numCommits = 10;
    List<Hash> hashes = IntStream.rangeClosed(1, numCommits).mapToObj(i -> {
        try {
            return commit("Commit #" + i).put("k" + i, onRef("v" + i, "c" + i)).put("key" + i, onRef("value" + i, "cid" + i)).delete("delete" + i).toBranch(branch);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());
    List<Hash> parentHashes = Stream.concat(Stream.of(firstParent), hashes.subList(0, 9).stream()).collect(Collectors.toList());
    assertThat(Lists.reverse(commitsList(branch, false))).allSatisfy(c -> {
        assertThat(c.getOperations()).isNull();
        assertThat(c.getParentHash()).isNull();
    }).extracting(Commit::getHash).containsExactlyElementsOf(hashes);
    List<Commit<CommitMessage, BaseContent>> commits = Lists.reverse(commitsList(branch, true));
    assertThat(IntStream.rangeClosed(1, numCommits)).allSatisfy(i -> {
        Commit<CommitMessage, BaseContent> c = commits.get(i - 1);
        assertThat(c).extracting(Commit::getCommitMeta, Commit::getHash, Commit::getParentHash, Commit::getOperations).containsExactly(commitMessage("Commit #" + i), hashes.get(i - 1), parentHashes.get(i - 1), Arrays.asList(Delete.of(Key.of("delete" + i)), Put.of(Key.of("k" + i), onRef("v" + i, "c" + i)), Put.of(Key.of("key" + i), onRef("value" + i, "cid" + i))));
    });
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) BaseContent(org.projectnessie.versioned.testworker.BaseContent) ImmutableList(com.google.common.collect.ImmutableList) VersionStore(org.projectnessie.versioned.VersionStore) Delete(org.projectnessie.versioned.Delete) OnRefOnly.onRef(org.projectnessie.versioned.testworker.OnRefOnly.onRef) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMessage.commitMessage(org.projectnessie.versioned.testworker.CommitMessage.commitMessage) Hash(org.projectnessie.versioned.Hash) Commit(org.projectnessie.versioned.Commit) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) BranchName(org.projectnessie.versioned.BranchName) List(java.util.List) Stream(java.util.stream.Stream) OnRefOnly.newOnRef(org.projectnessie.versioned.testworker.OnRefOnly.newOnRef) Optional(java.util.Optional) Put(org.projectnessie.versioned.Put) Collections(java.util.Collections) Commit(org.projectnessie.versioned.Commit) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) BaseContent(org.projectnessie.versioned.testworker.BaseContent) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 3 with CommitMessage

use of org.projectnessie.versioned.testworker.CommitMessage in project nessie by projectnessie.

the class AbstractCommitLog method commitLogPaging.

@Test
public void commitLogPaging() throws Exception {
    BranchName branch = BranchName.of("commitLogPaging");
    Hash createHash = store().create(branch, Optional.empty());
    // this should be enough
    int commits = 95;
    Hash[] commitHashes = new Hash[commits];
    List<CommitMessage> messages = new ArrayList<>(commits);
    for (int i = 0; i < commits; i++) {
        CommitMessage msg = commitMessage(String.format("commit#%05d", i));
        messages.add(msg);
        commitHashes[i] = store().commit(branch, Optional.of(i == 0 ? createHash : commitHashes[i - 1]), msg, ImmutableList.of(Put.of(Key.of("table"), newOnRef(String.format("value#%05d", i)))));
    }
    Collections.reverse(messages);
    List<CommitMessage> justTwo = commitsList(branch, s -> s.limit(2).map(Commit::getCommitMeta), false);
    assertEquals(messages.subList(0, 2), justTwo);
    List<CommitMessage> justTen = commitsList(branch, s -> s.limit(10).map(Commit::getCommitMeta), false);
    assertEquals(messages.subList(0, 10), justTen);
    int pageSize = 10;
    // Test parameter sanity check. Want the last page to be smaller than the page-size.
    assertNotEquals(0, commits % (pageSize - 1));
    Hash lastHash = null;
    for (int offset = 0; ; ) {
        List<Commit<CommitMessage, BaseContent>> logPage = commitsList(lastHash == null ? branch : lastHash, s -> s.limit(pageSize), false);
        assertEquals(messages.subList(offset, Math.min(offset + pageSize, commits)), logPage.stream().map(Commit::getCommitMeta).collect(Collectors.toList()));
        lastHash = logPage.get(logPage.size() - 1).getHash();
        offset += pageSize - 1;
        if (offset >= commits) {
            // The "next after last page" should always return just a single commit, that's basically
            // the "end of commit-log"-condition.
            logPage = commitsList(lastHash, s -> s.limit(pageSize), false);
            assertEquals(Collections.singletonList(messages.get(commits - 1)), logPage.stream().map(Commit::getCommitMeta).collect(Collectors.toList()));
            break;
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) BaseContent(org.projectnessie.versioned.testworker.BaseContent) ImmutableList(com.google.common.collect.ImmutableList) VersionStore(org.projectnessie.versioned.VersionStore) Delete(org.projectnessie.versioned.Delete) OnRefOnly.onRef(org.projectnessie.versioned.testworker.OnRefOnly.onRef) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMessage.commitMessage(org.projectnessie.versioned.testworker.CommitMessage.commitMessage) Hash(org.projectnessie.versioned.Hash) Commit(org.projectnessie.versioned.Commit) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) BranchName(org.projectnessie.versioned.BranchName) List(java.util.List) Stream(java.util.stream.Stream) OnRefOnly.newOnRef(org.projectnessie.versioned.testworker.OnRefOnly.newOnRef) Optional(java.util.Optional) Put(org.projectnessie.versioned.Put) Collections(java.util.Collections) Commit(org.projectnessie.versioned.Commit) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) ArrayList(java.util.ArrayList) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 4 with CommitMessage

use of org.projectnessie.versioned.testworker.CommitMessage 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 5 with CommitMessage

use of org.projectnessie.versioned.testworker.CommitMessage in project nessie by projectnessie.

the class AbstractSingleBranch method singleBranchManyUsers.

/**
 * Use case simulation matrix: single branch, multiple users, each or all user updating a separate
 * or single table.
 */
@ParameterizedTest
@MethodSource("singleBranchManyUsersCases")
void singleBranchManyUsers(SingleBranchParam param) throws Exception {
    BranchName branch = BranchName.of(param.branchName);
    int numUsers = 5;
    int numCommits = 50;
    Hash[] hashesKnownByUser = new Hash[numUsers];
    Hash createHash = store().create(branch, Optional.empty());
    Arrays.fill(hashesKnownByUser, createHash);
    List<CommitMessage> expectedValues = new ArrayList<>();
    Map<Key, String> previousState = new HashMap<>();
    for (int commitNum = 0; commitNum < numCommits; commitNum++) {
        for (int user = 0; user < numUsers; user++) {
            Hash hashKnownByUser = hashesKnownByUser[user];
            CommitMessage msg = commitMessage(String.format("user %03d/commit %03d", user, commitNum));
            expectedValues.add(msg);
            Key key = Key.of(param.tableNameGen.apply(user));
            String contentId = param.contentIdGen.apply(user);
            Operation<BaseContent> put;
            if (param.globalState) {
                String state = String.format("%03d_%03d", user, commitNum);
                if (previousState.containsKey(key)) {
                    put = Put.of(key, withGlobal(state, "data_file", contentId), withGlobal(previousState.get(key), "foo", contentId));
                } else {
                    put = Put.of(key, withGlobal(state, "data_file", contentId));
                }
                previousState.put(key, state);
            } else {
                BaseContent value = newOnRef(String.format("data_file_%03d_%03d", user, commitNum));
                put = Put.of(key, value);
            }
            Hash commitHash;
            List<Operation<BaseContent>> ops = ImmutableList.of(put);
            try {
                commitHash = store().commit(branch, Optional.of(hashKnownByUser), msg, ops);
            } catch (ReferenceConflictException inconsistentValueException) {
                if (param.allowInconsistentValueException) {
                    hashKnownByUser = store().hashOnReference(branch, Optional.empty());
                    commitHash = store().commit(branch, Optional.of(hashKnownByUser), msg, ops);
                } else {
                    throw inconsistentValueException;
                }
            }
            assertNotEquals(hashKnownByUser, commitHash);
            hashesKnownByUser[user] = commitHash;
        }
    }
    // Verify that all commits are there and that the order of the commits is correct
    List<CommitMessage> committedValues = commitsList(branch, s -> s.map(Commit::getCommitMeta), false);
    Collections.reverse(expectedValues);
    assertEquals(expectedValues, committedValues);
}
Also used : CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) HashMap(java.util.HashMap) BaseContent(org.projectnessie.versioned.testworker.BaseContent) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) ArrayList(java.util.ArrayList) Operation(org.projectnessie.versioned.Operation) Hash(org.projectnessie.versioned.Hash) BranchName(org.projectnessie.versioned.BranchName) Key(org.projectnessie.versioned.Key) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

BaseContent (org.projectnessie.versioned.testworker.BaseContent)5 CommitMessage (org.projectnessie.versioned.testworker.CommitMessage)5 BranchName (org.projectnessie.versioned.BranchName)4 Hash (org.projectnessie.versioned.Hash)4 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 Stream (java.util.stream.Stream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Test (org.junit.jupiter.api.Test)3 Commit (org.projectnessie.versioned.Commit)3 Key (org.projectnessie.versioned.Key)3 VersionStore (org.projectnessie.versioned.VersionStore)3 ImmutableList (com.google.common.collect.ImmutableList)2 Lists (com.google.common.collect.Lists)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2