use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class AbstractRestCommitLog method filterCommitLogOperations.
@Test
public void filterCommitLogOperations() throws BaseNessieClientServerException {
Branch branch = createBranch("filterCommitLogOperations");
branch = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("some awkward message")).operation(Put.of(ContentKey.of("hello", "world", "BaseTable"), IcebergView.of("path1", 1, 1, "Spark", "SELECT ALL THE THINGS"))).operation(Put.of(ContentKey.of("dlrow", "olleh", "BaseTable"), IcebergView.of("path2", 1, 1, "Spark", "SELECT ALL THE THINGS"))).commit();
assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.type == 'PUT')").get().getLogEntries()).hasSize(1);
assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.key.startsWith('hello.world.'))").get().getLogEntries()).hasSize(1);
assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.key.startsWith('not.there.'))").get().getLogEntries()).isEmpty();
assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.name == 'BaseTable')").get().getLogEntries()).hasSize(1);
assertThat(getApi().getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).filter("operations.exists(op, op.name == 'ThereIsNoSuchTable')").get().getLogEntries()).isEmpty();
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class AbstractRestCommitLog method commitLogExtended.
@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void commitLogExtended(ReferenceMode refMode) throws Exception {
String branch = "commitLogExtended";
String firstParent = getApi().createReference().sourceRefName("main").reference(Branch.of(branch, null)).create().getHash();
int numCommits = 10;
// Hack for tests running via Quarkus :(
IntFunction<String> c1 = i -> refMode.name() + "-c1-" + i;
IntFunction<String> c2 = i -> refMode.name() + "-c2-" + i;
List<String> hashes = IntStream.rangeClosed(1, numCommits).mapToObj(i -> {
try {
String head = getApi().getReference().refName(branch).get().getHash();
return getApi().commitMultipleOperations().operation(Put.of(ContentKey.of("k" + i), IcebergTable.of("m" + i, i, i, i, i, c1.apply(i)))).operation(Put.of(ContentKey.of("key" + i), IcebergTable.of("meta" + i, i, i, i, i, c2.apply(i)))).operation(Delete.of(ContentKey.of("delete" + i))).operation(Unchanged.of(ContentKey.of("key" + i))).commitMeta(CommitMeta.fromMessage("Commit #" + i)).branchName(branch).hash(head).commit().getHash();
} catch (Exception e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
List<String> parentHashes = Stream.concat(Stream.of(firstParent), hashes.subList(0, 9).stream()).collect(Collectors.toList());
Reference branchRef = getApi().getReference().refName(branch).get();
assertThat(Lists.reverse(getApi().getCommitLog().untilHash(firstParent).reference(refMode.transform(branchRef)).get().getLogEntries())).allSatisfy(c -> {
assertThat(c.getOperations()).isNull();
assertThat(c.getParentCommitHash()).isNull();
}).extracting(e -> e.getCommitMeta().getHash()).containsExactlyElementsOf(hashes);
List<LogEntry> commits = Lists.reverse(getApi().getCommitLog().fetch(FetchOption.ALL).reference(refMode.transform(branchRef)).untilHash(firstParent).get().getLogEntries());
assertThat(IntStream.rangeClosed(1, numCommits)).allSatisfy(i -> {
LogEntry c = commits.get(i - 1);
assertThat(c).extracting(e -> e.getCommitMeta().getMessage(), e -> e.getCommitMeta().getHash(), LogEntry::getParentCommitHash, LogEntry::getOperations).containsExactly("Commit #" + i, hashes.get(i - 1), parentHashes.get(i - 1), Arrays.asList(Delete.of(ContentKey.of("delete" + i)), Put.of(ContentKey.of("k" + i), IcebergTable.of("m" + i, i, i, i, i, c1.apply(i))), Put.of(ContentKey.of("key" + i), IcebergTable.of("meta" + i, i, i, i, i, c2.apply(i)))));
});
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class AbstractRestCommitLog method filterCommitLogByAuthor.
@Test
public void filterCommitLogByAuthor() throws BaseNessieClientServerException {
Branch branch = createBranch("filterCommitLogByAuthor");
int numAuthors = 5;
int commitsPerAuthor = 10;
String currentHash = branch.getHash();
createCommits(branch, numAuthors, commitsPerAuthor, currentHash);
LogResponse log = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(numAuthors * commitsPerAuthor);
log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author == 'author-3'").get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commitsPerAuthor);
log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getAuthor()).isEqualTo("author-3"));
log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author == 'author-3' && commit.committer == 'random-committer'").get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).isEmpty();
log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author == 'author-3'").get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commitsPerAuthor);
log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getAuthor()).isEqualTo("author-3"));
log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author in ['author-1', 'author-3', 'author-4']").get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commitsPerAuthor * 3);
log.getLogEntries().forEach(commit -> assertThat(ImmutableList.of("author-1", "author-3", "author-4")).contains(commit.getCommitMeta().getAuthor()));
log = getApi().getCommitLog().refName(branch.getName()).filter("!(commit.author in ['author-1', 'author-0'])").get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commitsPerAuthor * 3);
log.getLogEntries().forEach(commit -> assertThat(ImmutableList.of("author-2", "author-3", "author-4")).contains(commit.getCommitMeta().getAuthor()));
log = getApi().getCommitLog().refName(branch.getName()).filter("commit.author.matches('au.*-(2|4)')").get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commitsPerAuthor * 2);
log.getLogEntries().forEach(commit -> assertThat(ImmutableList.of("author-2", "author-4")).contains(commit.getCommitMeta().getAuthor()));
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class AbstractRestCommitLog method filterCommitLogByCommitRange.
@Test
public void filterCommitLogByCommitRange() throws BaseNessieClientServerException {
Branch branch = createBranch("filterCommitLogByCommitRange");
int numCommits = 10;
String currentHash = branch.getHash();
createCommits(branch, 1, numCommits, currentHash);
LogResponse entireLog = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(entireLog).isNotNull();
assertThat(entireLog.getLogEntries()).hasSize(numCommits);
// if startHash > endHash, then we return all commits starting from startHash
String startHash = entireLog.getLogEntries().get(numCommits / 2).getCommitMeta().getHash();
String endHash = entireLog.getLogEntries().get(0).getCommitMeta().getHash();
LogResponse log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(endHash).untilHash(startHash).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(numCommits / 2 + 1);
for (int i = 0, j = numCommits - 1; i < j; i++, j--) {
startHash = entireLog.getLogEntries().get(j).getCommitMeta().getHash();
endHash = entireLog.getLogEntries().get(i).getCommitMeta().getHash();
log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(endHash).untilHash(startHash).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(numCommits - (i * 2));
assertThat(ImmutableList.copyOf(entireLog.getLogEntries()).subList(i, j + 1)).containsExactlyElementsOf(log.getLogEntries());
}
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class AbstractRestContents method verifyAllContentAndOperationTypes.
@Test
public void verifyAllContentAndOperationTypes() throws BaseNessieClientServerException {
Branch branch = createBranch("contentAndOperationAll");
CommitMultipleOperationsBuilder commit = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("verifyAllContentAndOperationTypes"));
contentAndOperationTypes().flatMap(c -> c.globalOperation == null ? Stream.of(c.operation) : Stream.of(c.operation, c.globalOperation)).forEach(commit::operation);
commit.commit();
List<Entry> entries = getApi().getEntries().refName(branch.getName()).get().getEntries();
List<Entry> expect = contentAndOperationTypes().filter(c -> c.operation instanceof Put).map(c -> Entry.builder().type(c.type).name(c.operation.getKey()).build()).collect(Collectors.toList());
assertThat(entries).containsExactlyInAnyOrderElementsOf(expect);
}
Aggregations