use of org.projectnessie.versioned.persist.adapter.KeyListEntry in project nessie by projectnessie.
the class AbstractManyCommits method verify.
private void verify(int i, int numCommits, BranchName branch, Hash commit, ContentId contentId) {
Key key = Key.of("many", "commits", Integer.toString(numCommits));
try {
commit = databaseAdapter.hashOnReference(branch, Optional.of(commit));
} catch (ReferenceNotFoundException e) {
throw new RuntimeException(e);
}
try {
Map<Key, ContentAndState<ByteString>> values = databaseAdapter.values(commit, Collections.singletonList(key), KeyFilterPredicate.ALLOW_ALL);
WithGlobalStateContent expected = WithGlobalStateContent.withGlobal("state for #" + (numCommits - 1) + " of " + numCommits, "value for #" + i + " of " + numCommits, contentId.getId());
ByteString expectValue = SimpleStoreWorker.INSTANCE.toStoreOnReferenceState(expected);
ByteString expectState = SimpleStoreWorker.INSTANCE.toStoreGlobalState(expected);
ContentAndState<ByteString> expect = ContentAndState.of(expectValue, expectState);
assertThat(values).containsExactly(Maps.immutableEntry(key, expect));
} catch (ReferenceNotFoundException e) {
throw new RuntimeException(e);
}
try (Stream<KeyListEntry> keys = databaseAdapter.keys(commit, KeyFilterPredicate.ALLOW_ALL)) {
assertThat(keys.map(KeyListEntry::getKey)).containsExactly(key);
} catch (ReferenceNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.persist.adapter.KeyListEntry in project nessie by projectnessie.
the class AbstractManyKeys method manyKeys.
@ParameterizedTest
@MethodSource("manyKeysParams")
void manyKeys(ManyKeysParams params) throws Exception {
BranchName main = BranchName.of("main");
List<ImmutableCommitAttempt.Builder> commits = IntStream.range(0, params.commits).mapToObj(i -> ImmutableCommitAttempt.builder().commitMetaSerialized(ByteString.copyFromUtf8("commit #" + i)).commitToBranch(main)).collect(Collectors.toList());
AtomicInteger commitDist = new AtomicInteger();
Set<Key> allKeys = new HashSet<>();
IntStream.range(0, params.keys).mapToObj(i -> {
Key key = Key.of("some", Integer.toString(i), "long", "key", "value", "foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbaz");
allKeys.add(key);
return KeyWithBytes.of(key, ContentId.of("cid-" + i), (byte) 0, ByteString.copyFromUtf8("value " + i));
}).forEach(kb -> commits.get(commitDist.incrementAndGet() % params.commits).addPuts(kb));
for (ImmutableCommitAttempt.Builder commit : commits) {
databaseAdapter.commit(commit.build());
}
Hash mainHead = databaseAdapter.hashOnReference(main, Optional.empty());
try (Stream<KeyListEntry> keys = databaseAdapter.keys(mainHead, KeyFilterPredicate.ALLOW_ALL)) {
List<Key> fetchedKeys = keys.map(KeyListEntry::getKey).collect(Collectors.toList());
// containsExactlyInAnyOrderElementsOf() is quite expensive and slow with Key's
// implementation of 'Key.equals()' since it uses a collator.
List<String> fetchedKeysStrings = fetchedKeys.stream().map(Key::toString).collect(Collectors.toList());
List<String> allKeysStrings = allKeys.stream().map(Key::toString).collect(Collectors.toList());
assertThat(fetchedKeysStrings).hasSize(allKeysStrings.size()).containsExactlyInAnyOrderElementsOf(allKeysStrings);
}
}
Aggregations