Skip to content

Commit 7e5871b

Browse files
committed
Add lmdb/ref tests
1 parent be21a2b commit 7e5871b

File tree

8 files changed

+527
-28
lines changed

8 files changed

+527
-28
lines changed

Diff for: stroom-lmdb/src/main/java/stroom/lmdb/AbstractLmdbDb.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@
4242

4343
import java.nio.ByteBuffer;
4444
import java.util.Collection;
45+
import java.util.LinkedHashMap;
4546
import java.util.Map;
4647
import java.util.Map.Entry;
4748
import java.util.Objects;
4849
import java.util.Optional;
50+
import java.util.SequencedMap;
4951
import java.util.function.Consumer;
5052
import java.util.function.Function;
5153
import java.util.function.Predicate;
54+
import java.util.stream.Collectors;
5255
import java.util.stream.Stream;
5356
import java.util.stream.StreamSupport;
5457

@@ -138,8 +141,8 @@ public AbstractLmdbDb(final LmdbEnv lmdbEnvironment,
138141
int envMaxKeySize = lmdbEnvironment.getMaxKeySize();
139142
if (keySerdeCapacity > envMaxKeySize) {
140143
LAMBDA_LOGGER.debug(() -> LogUtil.message("Key serde {} capacity {} is greater than the maximum " +
141-
"key size for the environment {}. " +
142-
"The max environment key size {} will be used instead.",
144+
"key size for the environment {}. " +
145+
"The max environment key size {} will be used instead.",
143146
keySerde.getClass().getName(), keySerdeCapacity, envMaxKeySize, envMaxKeySize));
144147
}
145148
this.keyBufferCapacity = Math.min(envMaxKeySize, keySerdeCapacity);
@@ -344,6 +347,21 @@ public <T> T streamEntries(final Txn<ByteBuffer> txn,
344347
}
345348
}
346349

350+
/**
351+
* Get all entries found in keyRange in the order they are found in the DB.
352+
*
353+
* @return The result of the stream mapping function.
354+
*/
355+
public SequencedMap<K, V> asSequencedMap(final Txn<ByteBuffer> txn,
356+
final KeyRange<K> keyRange) {
357+
return streamEntries(txn, keyRange, stream -> stream
358+
.collect(Collectors.toMap(
359+
Entry::getKey,
360+
Entry::getValue,
361+
(o, o2) -> o, // Merge shouldn't be an issue as the db is essentially a map
362+
LinkedHashMap::new)));
363+
}
364+
347365
/**
348366
* Find the first entry matching the supplied key predicate in the supplied key range.
349367
* Not very efficient as it will scan over all entries in the range (de-serialising

0 commit comments

Comments
 (0)