Search in sources :

Example 1 with KeyListEntry

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);
    }
}
Also used : KeyListEntry(org.projectnessie.versioned.persist.adapter.KeyListEntry) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) ByteString(com.google.protobuf.ByteString) ContentAndState(org.projectnessie.versioned.persist.adapter.ContentAndState) Key(org.projectnessie.versioned.Key) WithGlobalStateContent(org.projectnessie.versioned.testworker.WithGlobalStateContent)

Example 2 with KeyListEntry

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);
    }
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Hash(org.projectnessie.versioned.Hash) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) KeyListEntry(org.projectnessie.versioned.persist.adapter.KeyListEntry) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) KeyWithBytes(org.projectnessie.versioned.persist.adapter.KeyWithBytes) ByteString(com.google.protobuf.ByteString) HashSet(java.util.HashSet) BranchName(org.projectnessie.versioned.BranchName) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) KeyFilterPredicate(org.projectnessie.versioned.persist.adapter.KeyFilterPredicate) Stream(java.util.stream.Stream) ImmutableCommitAttempt(org.projectnessie.versioned.persist.adapter.ImmutableCommitAttempt) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Optional(java.util.Optional) ContentId(org.projectnessie.versioned.persist.adapter.ContentId) DatabaseAdapter(org.projectnessie.versioned.persist.adapter.DatabaseAdapter) MethodSource(org.junit.jupiter.params.provider.MethodSource) ImmutableCommitAttempt(org.projectnessie.versioned.persist.adapter.ImmutableCommitAttempt) ByteString(com.google.protobuf.ByteString) Hash(org.projectnessie.versioned.Hash) KeyListEntry(org.projectnessie.versioned.persist.adapter.KeyListEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BranchName(org.projectnessie.versioned.BranchName) Key(org.projectnessie.versioned.Key) HashSet(java.util.HashSet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ByteString (com.google.protobuf.ByteString)2 Key (org.projectnessie.versioned.Key)2 KeyListEntry (org.projectnessie.versioned.persist.adapter.KeyListEntry)2 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 BranchName (org.projectnessie.versioned.BranchName)1 Hash (org.projectnessie.versioned.Hash)1 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)1 ContentAndState (org.projectnessie.versioned.persist.adapter.ContentAndState)1 ContentId (org.projectnessie.versioned.persist.adapter.ContentId)1