@Test public void testGetSendingFileList() throws IOException { Map<String, Set<String>> allFileList = new HashMap<>(); Map<String, Set<String>> newFileList = new HashMap<>(); Map<String, Set<String>> sendingFileList = new HashMap<>(); Set<String> lastlocalList = new HashSet<>(); manager.setNowLocalFiles(new HashMap<>()); manager.getNowLocalFileList(new String[]{SENDER_FILE_PATH_TEST}); allFileList = manager.getNowLocalFiles(); manager.getLastLocalFileList(LAST_FILE_INFO_TEST); lastlocalList = manager.getLastLocalFiles(); manager.getSendingFileList(); sendingFileList = manager.getSendingFiles(); assert (lastlocalList.size() == 0); assert (isEmpty(allFileList)); assert (isEmpty(sendingFileList)); newFileList.clear(); manager.backupNowLocalFileInfo(LAST_FILE_INFO_TEST); Random r = new Random(0); for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { if (!allFileList.containsKey(String.valueOf(i))) { allFileList.put(String.valueOf(i), new HashSet<>()); } if (!newFileList.containsKey(String.valueOf(i))) { newFileList.put(String.valueOf(i), new HashSet<>()); } String rand = String.valueOf(r.nextInt(10000)); String fileName = SENDER_FILE_PATH_TEST + File.separator + String.valueOf(i) + File.separator + rand; File file = new File(fileName); allFileList.get(String.valueOf(i)).add(file.getAbsolutePath()); newFileList.get(String.valueOf(i)).add(file.getAbsolutePath()); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } if (!file.exists()) { file.createNewFile(); } } } manager.getNowLocalFileList(new String[]{SENDER_FILE_PATH_TEST}); allFileList = manager.getNowLocalFiles(); manager.backupNowLocalFileInfo(LAST_FILE_INFO_TEST); manager.getLastLocalFileList(LAST_FILE_INFO_TEST); lastlocalList = manager.getLastLocalFiles(); manager.getSendingFileList(); sendingFileList = manager.getSendingFiles(); assert (sendingFileList.size() == newFileList.size()); for (Entry<String, Set<String>> entry : sendingFileList.entrySet()) { assert (newFileList.containsKey(entry.getKey())); assert (newFileList.get(entry.getKey()).containsAll(entry.getValue())); } int count = 0; Map<String, Set<String>> deleteFile = new HashMap<>(); for (Entry<String, Set<String>> entry : allFileList.entrySet()) { deleteFile.put(entry.getKey(), new HashSet<>()); for (String path : entry.getValue()) { count++; if (count % 3 == 0) { deleteFile.get(entry.getKey()).add(path); } } } for (Entry<String, Set<String>> entry : deleteFile.entrySet()) { for (String path : entry.getValue()) { new File(path).delete(); allFileList.get(entry.getKey()).remove(path); } } newFileList.clear(); r = new Random(1); for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { if (!allFileList.containsKey(String.valueOf(i))) { allFileList.put(String.valueOf(i), new HashSet<>()); } if (!newFileList.containsKey(String.valueOf(i))) { newFileList.put(String.valueOf(i), new HashSet<>()); } String rand = String.valueOf(r.nextInt(10000)); String fileName = SENDER_FILE_PATH_TEST + File.separator + String.valueOf(i) + File.separator + rand; File file = new File(fileName); allFileList.get(String.valueOf(i)).add(file.getAbsolutePath()); newFileList.get(String.valueOf(i)).add(file.getAbsolutePath()); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } if (!file.exists()) { file.createNewFile(); } } } manager.getNowLocalFileList(new String[]{SENDER_FILE_PATH_TEST}); allFileList = manager.getNowLocalFiles(); manager.getLastLocalFileList(LAST_FILE_INFO_TEST); lastlocalList = manager.getLastLocalFiles(); manager.getSendingFileList(); sendingFileList = manager.getSendingFiles(); assert (sendingFileList.size() == newFileList.size()); for (Entry<String, Set<String>> entry : sendingFileList.entrySet()) { assert (newFileList.containsKey(entry.getKey())); assert (newFileList.get(entry.getKey()).containsAll(entry.getValue())); } }
public void getSendingFileList() { for (Entry<String, Set<String>> entry : nowLocalFiles.entrySet()) { for (String path : entry.getValue()) { if (!lastLocalFiles.contains(path)) { sendingFiles.get(entry.getKey()).add(path); } } } LOGGER.info("IoTDB sender : Sender has got list of sending files."); for (Entry<String, Set<String>> entry : sendingFiles.entrySet()) { for (String path : entry.getValue()) { LOGGER.info(path); nowLocalFiles.get(entry.getKey()).remove(path); } } }
FileManager { public void getSendingFileList() { for (Entry<String, Set<String>> entry : nowLocalFiles.entrySet()) { for (String path : entry.getValue()) { if (!lastLocalFiles.contains(path)) { sendingFiles.get(entry.getKey()).add(path); } } } LOGGER.info("IoTDB sender : Sender has got list of sending files."); for (Entry<String, Set<String>> entry : sendingFiles.entrySet()) { for (String path : entry.getValue()) { LOGGER.info(path); nowLocalFiles.get(entry.getKey()).remove(path); } } } }
FileManager { public void getSendingFileList() { for (Entry<String, Set<String>> entry : nowLocalFiles.entrySet()) { for (String path : entry.getValue()) { if (!lastLocalFiles.contains(path)) { sendingFiles.get(entry.getKey()).add(path); } } } LOGGER.info("IoTDB sender : Sender has got list of sending files."); for (Entry<String, Set<String>> entry : sendingFiles.entrySet()) { for (String path : entry.getValue()) { LOGGER.info(path); nowLocalFiles.get(entry.getKey()).remove(path); } } } private  FileManager(); }
FileManager { public void getSendingFileList() { for (Entry<String, Set<String>> entry : nowLocalFiles.entrySet()) { for (String path : entry.getValue()) { if (!lastLocalFiles.contains(path)) { sendingFiles.get(entry.getKey()).add(path); } } } LOGGER.info("IoTDB sender : Sender has got list of sending files."); for (Entry<String, Set<String>> entry : sendingFiles.entrySet()) { for (String path : entry.getValue()) { LOGGER.info(path); nowLocalFiles.get(entry.getKey()).remove(path); } } } private  FileManager(); static final FileManager getInstance(); void init(); void getSendingFileList(); void getLastLocalFileList(String path); void getNowLocalFileList(String[] paths); void backupNowLocalFileInfo(String backupFile); Map<String, Set<String>> getSendingFiles(); Set<String> getLastLocalFiles(); Map<String, Set<String>> getNowLocalFiles(); void setNowLocalFiles(Map<String, Set<String>> newNowLocalFiles); }
FileManager { public void getSendingFileList() { for (Entry<String, Set<String>> entry : nowLocalFiles.entrySet()) { for (String path : entry.getValue()) { if (!lastLocalFiles.contains(path)) { sendingFiles.get(entry.getKey()).add(path); } } } LOGGER.info("IoTDB sender : Sender has got list of sending files."); for (Entry<String, Set<String>> entry : sendingFiles.entrySet()) { for (String path : entry.getValue()) { LOGGER.info(path); nowLocalFiles.get(entry.getKey()).remove(path); } } } private  FileManager(); static final FileManager getInstance(); void init(); void getSendingFileList(); void getLastLocalFileList(String path); void getNowLocalFileList(String[] paths); void backupNowLocalFileInfo(String backupFile); Map<String, Set<String>> getSendingFiles(); Set<String> getLastLocalFiles(); Map<String, Set<String>> getNowLocalFiles(); void setNowLocalFiles(Map<String, Set<String>> newNowLocalFiles);  }