@Test
    void testKeyUseOutsideCursor() {
        basicLmdbDb.put("key1", "value1", false);
        basicLmdbDb.put("key2", "value2", false);

        lmdbEnv.doWithReadTxn(txn -> {

            ByteBuffer keyBuffer1 = ByteBuffer.allocateDirect(100);
            basicLmdbDb.serializeKey(keyBuffer1, "key1");

            ByteBuffer startKeyBuf = ByteBuffer.allocateDirect(100);
            basicLmdbDb.serializeKey(startKeyBuf, "key1");

            // Same start/end key
            final KeyRange<ByteBuffer> keyRange = KeyRange.closed(startKeyBuf, startKeyBuf);

            ByteBuffer foundKeyBuffer = null;
            try (CursorIterable<ByteBuffer> cursorIterable = basicLmdbDb.iterate(txn, keyRange)) {
                final Iterator<KeyVal<ByteBuffer>> iterator = cursorIterable.iterator();
                if (iterator.hasNext()) {
                    foundKeyBuffer = iterator.next().key();
                }
            }

            // foundKeyBuffer is not out of scope of the cursor
            assertThat(foundKeyBuffer)
                    .isNotNull();

            assertThat(basicLmdbDb.deserializeKey(foundKeyBuffer))
                    .isEqualTo("key1");

            // now do another get on a different key to get a different value
            ByteBuffer keyBuffer2 = ByteBuffer.allocateDirect(100);
            basicLmdbDb.serializeKey(keyBuffer2, "key2");
            basicLmdbDb.getAsBytes(txn, keyBuffer2).get();

            // Now bake sure the buffer we got in the cursor is still the same
            // and has not been affected by the other get.
            assertThat(basicLmdbDb.deserializeKey(foundKeyBuffer))
                    .isEqualTo("key1");
        });
    }
Comparing overwriting the same key N times vs putting N entries each with a different key
stroom-lmdb/src/test/java/stroom/lmdb/TestBasicLmdbDb.java