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