Search in sources :

Example 26 with BranchName

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

the class AbstractCommits method commitSomeOperations.

/*
   * Test:
   * - Create a new branch
   * - Add 3 commits in succession with no conflicts to it with put and delete operations
   * - Check commit metadata
   * - Check keys for each commit hash
   * - Check values for each commit hash
   */
@Test
public void commitSomeOperations() throws Exception {
    final BranchName branch = BranchName.of("foo");
    store().create(branch, Optional.empty());
    final Hash initialCommit = commit("Initial Commit").put("t1", V_1_1).put("t2", V_2_1).put("t3", V_3_1).toBranch(branch);
    final Hash secondCommit = commit("Second Commit").put("t1", V_1_2).delete("t2").delete("t3").put("t4", V_4_1).toBranch(branch);
    final Hash thirdCommit = commit("Third Commit").put("t2", V_2_2).unchanged("t4").toBranch(branch);
    assertThat(commitsList(branch, false)).contains(commit(thirdCommit, "Third Commit"), commit(secondCommit, "Second Commit"), commit(initialCommit, "Initial Commit"));
    try (Stream<Key> keys = store().getKeys(branch).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t2"), Key.of("t4"));
    }
    try (Stream<Key> keys = store().getKeys(secondCommit).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t4"));
    }
    try (Stream<Key> keys = store().getKeys(initialCommit).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t2"), Key.of("t3"));
    }
    assertThat(store().getValues(secondCommit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3"), Key.of("t4")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t4"), V_4_1));
    assertThat(store().getValues(initialCommit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3"), Key.of("t4")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_1, Key.of("t2"), V_2_1, Key.of("t3"), V_3_1));
    assertThat(store().getValue(branch, Key.of("t1"))).isEqualTo(V_1_2);
    assertThat(store().getValue(branch, Key.of("t2"))).isEqualTo(V_2_2);
    assertThat(store().getValue(branch, Key.of("t3"))).isNull();
    assertThat(store().getValue(branch, Key.of("t4"))).isEqualTo(V_4_1);
    assertThat(store().getValue(secondCommit, Key.of("t1"))).isEqualTo(V_1_2);
    assertThat(store().getValue(secondCommit, Key.of("t2"))).isNull();
    assertThat(store().getValue(secondCommit, Key.of("t3"))).isNull();
    assertThat(store().getValue(secondCommit, Key.of("t4"))).isEqualTo(V_4_1);
    assertThat(store().getValue(initialCommit, Key.of("t1"))).isEqualTo(V_1_1);
    assertThat(store().getValue(initialCommit, Key.of("t2"))).isEqualTo(V_2_1);
    assertThat(store().getValue(initialCommit, Key.of("t3"))).isEqualTo(V_3_1);
    assertThat(store().getValue(initialCommit, Key.of("t4"))).isNull();
}
Also used : WithType(org.projectnessie.versioned.WithType) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Key(org.projectnessie.versioned.Key) Test(org.junit.jupiter.api.Test)

Example 27 with BranchName

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

the class AbstractContents method getValueForEmptyBranch.

@Test
public void getValueForEmptyBranch() throws ReferenceNotFoundException, ReferenceAlreadyExistsException {
    BranchName branch = BranchName.of("empty-branch");
    store().create(branch, Optional.empty());
    final Hash hash = store().hashOnReference(branch, Optional.empty());
    assertThat(store().getValue(hash, Key.of("arbitrary"))).isNull();
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 28 with BranchName

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

the class AbstractMerge method mergeWithCommonAncestor.

@Test
protected void mergeWithCommonAncestor() throws VersionStoreException {
    final BranchName newBranch = BranchName.of("bar_2");
    store().create(newBranch, Optional.of(firstCommit));
    final Hash newCommit = commit("Unrelated commit").put("t5", V_5_1).toBranch(newBranch);
    store().merge(thirdCommit, newBranch, Optional.empty(), Function.identity());
    assertThat(store().getValues(newBranch, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3"), Key.of("t4"), Key.of("t5")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t2"), V_2_2, Key.of("t4"), V_4_1, Key.of("t5"), V_5_1));
    final List<Commit<CommitMessage, BaseContent>> commits = commitsList(newBranch, false);
    assertThat(commits).hasSize(5);
    assertThat(commits.get(4).getHash()).isEqualTo(initialHash);
    assertThat(commits.get(3).getHash()).isEqualTo(firstCommit);
    assertThat(commits.get(2).getHash()).isEqualTo(newCommit);
    assertThat(commits.get(1).getCommitMeta()).isEqualTo(commitMessage("Second Commit"));
    assertThat(commits.get(0).getCommitMeta()).isEqualTo(commitMessage("Third Commit"));
}
Also used : Commit(org.projectnessie.versioned.Commit) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 29 with BranchName

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

the class AbstractMerge method mergeIntoNonExistingReference.

@Test
protected void mergeIntoNonExistingReference() throws VersionStoreException {
    final BranchName newBranch = BranchName.of("bar_6");
    store().create(newBranch, Optional.of(initialHash));
    assertThrows(ReferenceNotFoundException.class, () -> store().merge(Hash.of("1234567890abcdef"), newBranch, Optional.of(initialHash), Function.identity()));
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Test(org.junit.jupiter.api.Test)

Example 30 with BranchName

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

the class AbstractMerge method mergeIntoEmptyBranchModifying.

@Test
protected void mergeIntoEmptyBranchModifying() throws VersionStoreException {
    final BranchName newBranch = BranchName.of("mergeIntoEmptyBranchModifying");
    store().create(newBranch, Optional.of(initialHash));
    store().merge(thirdCommit, newBranch, Optional.of(initialHash), this::merged);
    assertThat(store().getValues(newBranch, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3"), Key.of("t4")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t2"), V_2_2, Key.of("t4"), V_4_1));
    // modify the commit meta, will generate new commits and therefore new commit hashes
    assertThat(store().hashOnReference(newBranch, Optional.empty())).isNotEqualTo(thirdCommit);
    assertCommitMeta(commitsList(newBranch, false).subList(0, 3), commits, this::merged);
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Test(org.junit.jupiter.api.Test)

Aggregations

BranchName (org.projectnessie.versioned.BranchName)72 Test (org.junit.jupiter.api.Test)51 Hash (org.projectnessie.versioned.Hash)45 Key (org.projectnessie.versioned.Key)23 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)16 Stream (java.util.stream.Stream)14 ByteString (com.google.protobuf.ByteString)13 Optional (java.util.Optional)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 Collectors (java.util.stream.Collectors)12 IntStream (java.util.stream.IntStream)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 ImmutableCommitAttempt (org.projectnessie.versioned.persist.adapter.ImmutableCommitAttempt)11 List (java.util.List)10 ContentId (org.projectnessie.versioned.persist.adapter.ContentId)10 DatabaseAdapter (org.projectnessie.versioned.persist.adapter.DatabaseAdapter)10 KeyWithBytes (org.projectnessie.versioned.persist.adapter.KeyWithBytes)10 Collections (java.util.Collections)9 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)9 TagName (org.projectnessie.versioned.TagName)9