@Test
void testGetNextMapDefinition() {

    String pipelineUuid = UUID.randomUUID().toString();
    String pipelineVersion = UUID.randomUUID().toString();
    RefStreamDefinition refStreamDefinition1 = new RefStreamDefinition(pipelineUuid, pipelineVersion, 1);
    RefStreamDefinition refStreamDefinition2 = new RefStreamDefinition(pipelineUuid, pipelineVersion, 2);
    RefStreamDefinition refStreamDefinition3 = new RefStreamDefinition(pipelineUuid, pipelineVersion, 3);
    MapDefinition mapDefinition11 = new MapDefinition(refStreamDefinition1, "map1");
    MapDefinition mapDefinition21 = new MapDefinition(refStreamDefinition2, "map1");
    MapDefinition mapDefinition22 = new MapDefinition(refStreamDefinition2, "map2");
    MapDefinition mapDefinition31 = new MapDefinition(refStreamDefinition3, "map1");
    loadEntries(Arrays.asList(
            mapDefinition11,
            mapDefinition21,
            mapDefinition22,
            mapDefinition31));
    assertThat(mapUidReverseDb.getEntryCount()).isEqualTo(4);
    assertThat(mapUidForwardDb.getEntryCount()).isEqualTo(4);
    LOGGER.info("--------------------------------------------------------------------------------");
    LmdbUtils.doWithWriteTxn(lmdbEnv, writeTxn -> {
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition1, Optional.of(mapDefinition11), false);
        // same match as nothing has changed
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition1, Optional.of(mapDefinition11), false);
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition2, Optional.of(mapDefinition21), false);
        // same match as nothing has changed
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition2, Optional.of(mapDefinition21), false);
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition3, Optional.of(mapDefinition31), false);
        // same match as nothing has changed
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition3, Optional.of(mapDefinition31), false);
        //now delete the match after we find it
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition1, Optional.of(mapDefinition11), true);
        // same match as nothing has changed
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition1, Optional.empty(), true);
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition2, Optional.of(mapDefinition21), true);
        // same match as nothing has changed
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition2, Optional.of(mapDefinition22), true);
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition3, Optional.of(mapDefinition31), true);
        // same match as nothing has changed
        doGetNextMapDefinitionTest(
                writeTxn, refStreamDefinition3, Optional.empty(), true);
    });
}