MysqlServerController { public String moveData(String pathOfMysqlData, long expireTimeOfOldMysqlData) throws IOException { File fileOfMysqlData = new File(pathOfMysqlData).getAbsoluteFile(); if (!fileOfMysqlData.exists()) { Utilities.logInfo(logger, "no need to move not existed path=", pathOfMysqlData); return null; } try { String newPathOfMysqlData = pathOfMysqlData + "-" + Utilities.longTimeToStringTime(System.currentTimeMillis(), ""); fileOfMysqlData.renameTo(new File(newPathOfMysqlData)); File parentFileOfMysqlData = fileOfMysqlData.getParentFile(); for (File oldFileOfMysqlData : parentFileOfMysqlData.listFiles()) { if (oldFileOfMysqlData.getName().startsWith(fileOfMysqlData.getName())) { String timeString = oldFileOfMysqlData.getName().substring(fileOfMysqlData.getName().length()); if (!timeString.startsWith("-")) continue; timeString = timeString.substring(1); long time = Utilities.stringTimeToLongTime(timeString, ""); if (System.currentTimeMillis() - time > expireTimeOfOldMysqlData) { Utilities.delete(oldFileOfMysqlData); Utilities.logInfo(logger, "delete ", oldFileOfMysqlData); } } } Utilities.logInfo(logger, "move ", pathOfMysqlData, " to ", newPathOfMysqlData); return newPathOfMysqlData; } catch (Throwable t) { throw new IOException(t); } }  String getData(Configuration conf, Lock writeLock); String setData(Configuration conf); String moveData(String pathOfMysqlData, long expireTimeOfOldMysqlData); String backupData(Configuration conf); String getMysqlLibPath(String mysqlBinPath); void formatData(Configuration conf); void createDatabase(Configuration conf); String startServer(Configuration conf); void saveMysqlConf(Configuration conf); static String getMysqlConf(Configuration conf, String mysqlConfKey); static String getMysqlConf(Configuration conf, String mysqlConfKey, Object defaultValue); static void setMysqlConf(Configuration conf, String mysqlConfKey, String value); String stopServer(Configuration conf); static final Logger logger; static final String mysqlConfKeyPrefix; }
@Test public void testMoveData() throws IOException, InterruptedException { File dataPath = new File("target/test" + getClass().getSimpleName() + "/testMoveData/dataPathOfTestMoveData"); dataPath.mkdirs(); new MysqlServerController().moveData(dataPath.getAbsolutePath(), Long.MAX_VALUE); assertThat(dataPath.exists(), is(false)); assertThat(dataPath.getParentFile().list().length == 1, is(true)); dataPath.mkdirs(); new MysqlServerController().moveData(dataPath.getAbsolutePath(), Long.MAX_VALUE); assertThat(dataPath.exists(), is(false)); assertThat(dataPath.getParentFile().list().length == 2, is(true)); Thread.sleep(1000); dataPath.mkdirs(); new MysqlServerController().moveData(dataPath.getAbsolutePath(), 500); assertThat(dataPath.exists(), is(false)); assertThat(dataPath.getParentFile().list().length == 1, is(true)); }