@Test
    void testConcurrentEnvs() throws IOException, ExecutionException, InterruptedException {

        try (TemporaryPathCreator temporaryPathCreator = new TemporaryPathCreator()) {
            final EnvFlags[] envFlags = new EnvFlags[]{
                    EnvFlags.MDB_NOTLS
            };
            LOGGER.info("baseDir: {}", temporaryPathCreator.getBaseTempDir().toAbsolutePath().normalize());

            final BasicLmdbDb<String, String> basicLmdb1 = createDb(temporaryPathCreator, envFlags, "1");
            final BasicLmdbDb<String, String> basicLmdb2 = createDb(temporaryPathCreator, envFlags, "2");

            final LmdbEnv lmdbEnv1 = basicLmdb1.getLmdbEnvironment();
            final LmdbEnv lmdbEnv2 = basicLmdb2.getLmdbEnvironment();

            final CountDownLatch countDownLatch = new CountDownLatch(2);

            final CompletableFuture<Void> future1 = CompletableFuture.runAsync(() -> {
                LOGGER.info("Opening writeTxn1");
                final WriteTxn writeTxn1 = lmdbEnv1.openWriteTxn();
                LOGGER.info("writeTxn1 open");
                basicLmdb1.put(writeTxn1.getTxn(), "1", "one", true);
                countDownLatch.countDown();
                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                try {
                    LOGGER.info("Closing writeTxn1");
                    writeTxn1.commit();
                    writeTxn1.close();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            });

            final CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> {
                LOGGER.info("Opening writeTxn2");
                final WriteTxn writeTxn2 = lmdbEnv2.openWriteTxn();
                LOGGER.info("writeTxn2 open");
                basicLmdb1.put(writeTxn2.getTxn(), "2", "two", true);
                countDownLatch.countDown();
                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                try {
                    LOGGER.info("Closing writeTxn2");
                    writeTxn2.commit();
                    writeTxn2.close();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            });

            future1.get();
            future2.get();

            assertThat(basicLmdb1.get("1"))
                    .hasValue("one");
            assertThat(basicLmdb2.get("2"))
                    .hasValue("two");
        }
    }
Ensure two envs can operate independently of each other, i.e. both hold a write txn open
in different threads.
stroom-lmdb/src/test/java/stroom/lmdb/TestBasicLmdbDb.java