@Override
    public void deleteJournals(long deleteToJournalId) {
        List<Long> dbNames = bdbEnvironment.getDatabaseNamesWithPrefix(prefix);
        if (dbNames == null) {
            LOG.info("delete database names is null.");
            return;
        }

        StringBuilder msg = new StringBuilder("existing database names: ");
        for (long name : dbNames) {
            msg.append(name).append(" ");
        }
        msg.append(", deleteToJournalId is ").append(deleteToJournalId);
        LOG.info(msg.toString());

        for (int i = 1; i < dbNames.size(); i++) {
            if (deleteToJournalId >= dbNames.get(i)) {
                long name = dbNames.get(i - 1);
                String dbName = getFullDatabaseName(name);
                LOG.info("delete database name {}", dbName);
                bdbEnvironment.removeDatabase(dbName);
            } else {
                LOG.info("database name {} is larger than deleteToJournalId {}, not delete",
                        dbNames.get(i), deleteToJournalId);
                break;
            }
        }
    }
@Test
    public void testDeleteJournals(@Mocked BDBEnvironment environment)  throws Exception {
        BDBJEJournal journal = new BDBJEJournal(environment);

        // failed to get database names; do nothing
        new Expectations(environment) {
            {
                environment.getDatabaseNamesWithPrefix("");
                times = 1;
                result = null;
            }
        };
        journal.deleteJournals(11);

        // 2. find journal and delete
        // current db (3, 23, 45) checkpoint is made on 44, should remove 3, 23
        new Expectations(environment) {
            {
                environment.getDatabaseNamesWithPrefix("");
                times = 1;
                result = Arrays.asList(3L, 23L, 45L);

                environment.removeDatabase("3");
                times = 1;
                environment.removeDatabase("23");
                times = 1;
            }
        };
        journal.deleteJournals(45);
        journal.close();  // no db will closed
    }