@Test
    void testSortOrder() {
        final ValueStoreKey valueStoreKey = new ValueStoreKey(123, (short) 0);
        int max = 100_000;
        int fromDelta = 30;
        int firstFrom = 10;
        int rangeSize = 15;

        final AtomicInteger putCount = new AtomicInteger();
        lmdbEnv.doWithWriteTxn(writeTxn -> {
            for (long from = firstFrom; from <= max; from += fromDelta) {
                final long to = from + rangeSize;
                rangeStoreDb.put(
                        writeTxn, RangeStoreKey.of(UID_1, from, to), valueStoreKey, false);
                putCount.incrementAndGet();

                // Dump the first 50 rows
                if (from == (fromDelta * 50) + firstFrom) {
                    rangeStoreDb.logDatabaseContents(writeTxn, LOGGER::info);
                }
            }
        });

        // Check that the cursor iterates over the ranges in the expected order
        final AtomicReference<Range<Long>> lastRangeRef = new AtomicReference<>();
        lmdbEnv.doWithReadTxn(readTxn -> {
            rangeStoreDb.forEachEntry(readTxn, entry -> {
                final Range<Long> range = entry.getKey().getKeyRange();
                final Range<Long> lastRange = lastRangeRef.get();
                if (lastRange != null) {
                    Assertions.assertThat(range.getFrom())
                            .isGreaterThan(lastRange.getFrom());
                    Assertions.assertThat(range.getFrom() - fromDelta)
                            .isEqualTo(lastRange.getFrom());
                }
                lastRangeRef.set(range);
            });
        });

        lmdbEnv.doWithReadTxn(readTxn -> {
            int i = 0;
            for (long from = firstFrom; from <= max; from += fromDelta) {
                i++;
                final long stopKeyFrom = from + fromDelta + 10;
                final RangeStoreKey startKeyInc = RangeStoreKey.of(UID_1, from, from);
                final RangeStoreKey stopKeyExc = RangeStoreKey.of(UID_1, stopKeyFrom, stopKeyFrom);

                final AtomicInteger count = new AtomicInteger();

                LOGGER.debug("startKeyInc: {}, stopKeyExc: {}", startKeyInc, stopKeyExc);
                rangeStoreDb.forEachEntry(readTxn, KeyRange.closedOpen(startKeyInc, stopKeyExc), entry -> {
                    count.incrementAndGet();
                    LOGGER.debug("Entry {}: {}", count.get(), entry.getKey().getKeyRange());
                });

                if (i < putCount.get() - 2) {
                    Assertions.assertThat(count)
                            .hasValue(2);
                }
            }
        });
    }
Make sure that the entries are stored in the db in the order we expect.
stroom-pipeline/src/test/java/stroom/pipeline/refdata/store/offheapstore/databases/TestRangeStoreDb.java