use of org.projectnessie.versioned.Commit 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());
}
use of org.projectnessie.versioned.Commit 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))));
});
}
use of org.projectnessie.versioned.Commit 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;
}
}
}
use of org.projectnessie.versioned.Commit 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.Commit in project nessie by projectnessie.
the class AbstractMerge method mergeIntoNonConflictingBranch.
@Test
protected void mergeIntoNonConflictingBranch() throws VersionStoreException {
final BranchName newBranch = BranchName.of("bar_2");
store().create(newBranch, Optional.of(initialHash));
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).satisfiesExactly(c0 -> assertThat(c0).extracting(Commit::getCommitMeta).isEqualTo(commitMessage("Third Commit")), c1 -> assertThat(c1).extracting(Commit::getCommitMeta).isEqualTo(commitMessage("Second Commit")), c2 -> assertThat(c2).extracting(Commit::getCommitMeta).isEqualTo(commitMessage("First Commit")), c3 -> assertThat(c3).extracting(Commit::getHash).isEqualTo(newCommit), c4 -> assertThat(c4).extracting(Commit::getHash).isEqualTo(initialHash));
}
Aggregations