@Override
    public void rollJournal(long newName) throws JournalException {
        // Doesn't need to roll if current database contains no journals
        if (currentJournalDB.getDb().count() == 0) {
            return;
        }

        String currentDbName = currentJournalDB.getDb().getDatabaseName();
        String currentIdStr = currentDbName;
        if (!prefix.isEmpty()) { // remove prefix
            currentIdStr = currentDbName.substring(prefix.length());
        }
        long currentName = Long.parseLong(currentIdStr);
        long newNameVerify = currentName + currentJournalDB.getDb().count();
        if (newName == newNameVerify) {
            String newDbName = getFullDatabaseName(newName);
            LOG.info("roll edit log. new db name is {}", newDbName);
            currentJournalDB.close();
            currentJournalDB = bdbEnvironment.openDatabase(newDbName);
        } else {
            String msg = String.format("roll journal error! journalId and db journal numbers is not match. "
                            + "journal id: %d, current db: %s, expected db count: %d",
                    newName, currentDbName, newNameVerify);
            LOG.error(msg);
            throw new JournalException(msg);
        }
    }
@Test(expected = JournalException.class)
    public void testRollJournal(@Mocked CloseSafeDatabase closeSafeDatabase,
                                    @Mocked BDBEnvironment environment,
                                    @Mocked Database database) throws Exception {
        new Expectations(closeSafeDatabase) {
            {
                closeSafeDatabase.getDb();
                minTimes = 0;
                result = database;

                closeSafeDatabase.close();
                minTimes = 0;
            }
        };
        BDBJEJournal journal = new BDBJEJournal(environment, closeSafeDatabase);

        // 1. no data, do nothing and return
        new Expectations(database) {
            {
                database.count();
                times = 1;
                result = 0;
            }
        };
        journal.rollJournal(111);


        // 2. normal cases, current db is 9, has 10 logs, new log expect 19
        new Expectations(database) {
            {
                database.count();
                times = 2;
                result = 10;

                database.getDatabaseName();
                times = 1;
                result = 9;
            }
        };
        journal.rollJournal(19);

        // 3. exception  current db is 9, has 10 logs, new log expect 19
        new Expectations(database) {
            {
                database.count();
                times = 2;
                result = 10;

                database.getDatabaseName();
                times = 1;
                result = 9;
            }
        };
        journal.rollJournal(18);
        Assert.fail();
    }