@Test
    void testLoadingSortedKeys() {
        final List<Entry<String, String>> entries = IntStream.rangeClosed(1, 10)
                .boxed()
                .map(i -> new SimpleEntry<>("key-" + i, "value-" + i))
                .collect(Collectors.toList());

        // Random order for 1st load
        Collections.shuffle(entries);

        lmdbEnv.doWithWriteTxn(writeTxn -> {
            LOGGER.logDurationIfDebugEnabled(() -> {
                entries
                        .forEach(entry -> {
                            try (final PooledByteBufferPair pooledBufferPair = basicLmdbDb.getPooledBufferPair()) {
                                final ByteBuffer keyBuff = pooledBufferPair.getKeyBuffer();
                                final ByteBuffer valBuff = pooledBufferPair.getValueBuffer();
                                basicLmdbDb.serializeKey(keyBuff, entry.getKey());
                                basicLmdbDb.serializeValue(valBuff, entry.getValue());
                                basicLmdbDb.getLmdbDbi().put(
                                        writeTxn,
                                        keyBuff,
                                        valBuff,
                                        PutFlags.MDB_NOOVERWRITE);
                            }
                        });
            }, "un-sorted puts");
        });

        // Read all entries back out in lmdb sort order
        final List<Entry<String, String>> sortedEntries = lmdbEnv.getWithReadTxn(readTxn ->
                basicLmdbDb.streamEntries(readTxn, KeyRange.all(), stream ->
                        stream.collect(Collectors.toList())));

        // Now load them into the other db in order using MDB_APPEND to tell LMDB they are in order
        lmdbEnv.doWithWriteTxn(writeTxn -> {
            LOGGER.logDurationIfDebugEnabled(() -> {
                sortedEntries
                        .forEach(entry -> {
                            try (final PooledByteBufferPair pooledBufferPair = basicLmdbDb2.getPooledBufferPair()) {
                                final ByteBuffer keyBuff = pooledBufferPair.getKeyBuffer();
                                final ByteBuffer valBuff = pooledBufferPair.getValueBuffer();
                                basicLmdbDb2.serializeKey(keyBuff, entry.getKey());
                                basicLmdbDb2.serializeValue(valBuff, entry.getValue());
                                basicLmdbDb2.getLmdbDbi().put(
                                        writeTxn,
                                        keyBuff,
                                        valBuff,
                                        PutFlags.MDB_NOOVERWRITE,
                                        PutFlags.MDB_APPEND);
                            }
                        });
            }, "sorted puts");
        });

        // Now do all the puts again overwriting values
        lmdbEnv.doWithWriteTxn(writeTxn -> {
            LOGGER.logDurationIfDebugEnabled(() -> {
                sortedEntries
                        .forEach(entry -> {
                            try (final PooledByteBufferPair pooledBufferPair = basicLmdbDb2.getPooledBufferPair()) {
                                final ByteBuffer keyBuff = pooledBufferPair.getKeyBuffer();
                                final ByteBuffer valBuff = pooledBufferPair.getValueBuffer();
                                basicLmdbDb2.serializeKey(keyBuff, entry.getKey());
                                basicLmdbDb2.serializeValue(valBuff, entry.getValue());
                                basicLmdbDb2.getLmdbDbi().put(
                                        writeTxn,
                                        keyBuff,
                                        valBuff);
                                // Can't user MDB_APPEND now as it will barf when it finds an existing key
                            }
                        });
            }, "sorted puts 2");
        });
    }
This test is an example of how to abuse LMDB. If run it will crash the JVM
as a direct bytebuffer returned from a get() was mutated outside the transaction.
stroom-lmdb/src/test/java/stroom/lmdb/TestBasicLmdbDb.java