use of org.projectnessie.versioned.persist.adapter.Difference in project nessie by projectnessie.
the class AbstractDatabaseAdapterTest method diff.
@Test
void diff() throws Exception {
BranchName main = BranchName.of("main");
BranchName branch = BranchName.of("branch");
Hash initialHash = databaseAdapter.create(branch, databaseAdapter.hashOnReference(main, Optional.empty()));
Hash[] commits = new Hash[3];
for (int i = 0; i < commits.length; i++) {
ImmutableCommitAttempt.Builder commit = ImmutableCommitAttempt.builder().commitToBranch(branch).commitMetaSerialized(ByteString.copyFromUtf8("commit " + i));
for (int k = 0; k < 3; k++) {
WithGlobalStateContent c = WithGlobalStateContent.withGlobal("global " + i + " for " + k, "on-ref " + i + " for " + k, "cid-" + i + "-" + k);
commit.addPuts(KeyWithBytes.of(Key.of("key", Integer.toString(k)), ContentId.of("C" + k), SimpleStoreWorker.INSTANCE.getPayload(c), SimpleStoreWorker.INSTANCE.toStoreOnReferenceState(c)));
}
commits[i] = databaseAdapter.commit(commit.build());
}
try (Stream<Difference> diff = databaseAdapter.diff(databaseAdapter.hashOnReference(main, Optional.empty()), databaseAdapter.hashOnReference(branch, Optional.of(initialHash)), KeyFilterPredicate.ALLOW_ALL)) {
assertThat(diff).isEmpty();
}
for (int i = 0; i < commits.length; i++) {
try (Stream<Difference> diff = databaseAdapter.diff(databaseAdapter.hashOnReference(main, Optional.empty()), databaseAdapter.hashOnReference(branch, Optional.of(commits[i])), KeyFilterPredicate.ALLOW_ALL)) {
int c = i;
assertThat(diff).containsExactlyInAnyOrderElementsOf(IntStream.range(0, 3).mapToObj(k -> {
WithGlobalStateContent content = WithGlobalStateContent.withGlobal("global " + c + " for " + k, "on-ref " + c + " for " + k, "cid-" + c + "-" + k);
return Difference.of(Key.of("key", Integer.toString(k)), Optional.empty(), Optional.empty(), Optional.of(SimpleStoreWorker.INSTANCE.toStoreOnReferenceState(content)));
}).collect(Collectors.toList()));
}
}
for (int i = 0; i < commits.length; i++) {
try (Stream<Difference> diff = databaseAdapter.diff(databaseAdapter.hashOnReference(branch, Optional.of(commits[i])), databaseAdapter.hashOnReference(main, Optional.empty()), KeyFilterPredicate.ALLOW_ALL)) {
int c = i;
assertThat(diff).containsExactlyInAnyOrderElementsOf(IntStream.range(0, 3).mapToObj(k -> {
WithGlobalStateContent content = WithGlobalStateContent.withGlobal("global " + c + " for " + k, "on-ref " + c + " for " + k, "cid-" + c + "-" + k);
return Difference.of(Key.of("key", Integer.toString(k)), Optional.empty(), Optional.of(SimpleStoreWorker.INSTANCE.toStoreOnReferenceState(content)), Optional.empty());
}).collect(Collectors.toList()));
}
}
for (int i = 1; i < commits.length; i++) {
try (Stream<Difference> diff = databaseAdapter.diff(databaseAdapter.hashOnReference(branch, Optional.of(commits[i - 1])), databaseAdapter.hashOnReference(branch, Optional.of(commits[i])), KeyFilterPredicate.ALLOW_ALL)) {
int c = i;
assertThat(diff).containsExactlyInAnyOrderElementsOf(IntStream.range(0, 3).mapToObj(k -> {
WithGlobalStateContent from = WithGlobalStateContent.withGlobal("global " + (c - 1) + " for " + k, "on-ref " + (c - 1) + " for " + k, "cid-" + (c - 1) + "-" + k);
WithGlobalStateContent to = WithGlobalStateContent.withGlobal("global " + c + " for " + k, "on-ref " + c + " for " + k, "cid-" + c + "-" + k);
return Difference.of(Key.of("key", Integer.toString(k)), Optional.empty(), Optional.of(SimpleStoreWorker.INSTANCE.toStoreOnReferenceState(from)), Optional.of(SimpleStoreWorker.INSTANCE.toStoreOnReferenceState(to)));
}).collect(Collectors.toList()));
}
}
}
Aggregations