@Test public void testValidateFiles () throws IOException, InterruptedException { Cache.init("../data/junit/file-checker-cache"); Config.load(new File("../config/junit-logger2.cfg")); Log.init(); Map<String,String> requiredFiles = new HashMap<>(); requiredFiles.put("test.txt", "1234"); requiredFiles.put("test1.txt", "1234"); requiredFiles.put("test2.txt", "1234"); requiredFiles.put("dir1/dir1test.txt", "ca2a0cf5b143e25b63fa7e2ef2ac54e7"); requiredFiles.put("dir1/test1.txt", "1234"); requiredFiles.put("dir1/test3.txt", "1234"); List<String> invalideFiles = FileChecker.validateFiles(1, 1, requiredFiles); for (String file : invalideFiles) { System.err.println("invalide file: " + file); } System.err.println("shutdown logger now..."); Log.shutdown(); assertEquals(true, invalideFiles.contains("test.txt")); assertEquals(true, invalideFiles.contains("test1.txt")); assertEquals(true, invalideFiles.contains("test2.txt")); assertEquals(false, invalideFiles.contains("dir1/dir1test.txt")); assertEquals(true, invalideFiles.contains("dir1/test1.txt")); assertEquals(true, invalideFiles.contains("dir1/test3.txt")); assertEquals(5, invalideFiles.size()); new File("../temp-empty/logs/junit-log.txt").delete(); }
public static List<String> validateFiles (long regionID, int instanceID, Map<String,String> requiredFiles) { List<String> invalideFiles = new ArrayList<>(); Log.d(LOG_TAG, "validate cached region files for region " + regionID + ", instanceID: " + instanceID + "..."); String cacheDir = Cache.getInstance().getCachePath("maps/region_" + regionID + "_" + instanceID); Log.d(LOG_TAG, "region cache dir: " + cacheDir); if (!new File(cacheDir).exists()) { Log.d(LOG_TAG, "create cache dir for region " + regionID + ", instanceID: " + instanceID + ": " + cacheDir); new File(cacheDir).mkdirs(); } for (Map.Entry<String,String> entry : requiredFiles.entrySet()) { String filePath = entry.getKey(); String fileHash = entry.getValue(); Log.v(LOG_TAG, "check file " + filePath + " ..."); String cachePath = Cache.getInstance().getCacheFilePath("maps/region_" + regionID + "_" + instanceID + "/" + filePath); if (!new File(cachePath).exists()) { Log.d(LOG_TAG, "CACHE MISS of file: " + cachePath); invalideFiles.add(filePath); } else { Log.d(LOG_TAG, "CACHE HIT of file: " + cachePath); try { String checksum = HashUtils.computeMD5FileHash(new File(cachePath)); if (fileHash.equals(checksum)) { Log.v(LOG_TAG, "cached region file is valide: " + filePath + " (checksum: " + checksum + ")"); } else { Log.d(LOG_TAG, "OUTDATED CACHE file: " + cachePath + " (local checksum: " + checksum + ", remote checksum: " + fileHash + ")"); invalideFiles.add(filePath); } } catch (Exception e) { Log.w(LOG_TAG, "Exception while calculating file checksum: ", e); invalideFiles.add(filePath); } } } Log.d(LOG_TAG, "file checker finished (" + invalideFiles.size() + " invalide cached files)."); return invalideFiles; }
FileChecker { public static List<String> validateFiles (long regionID, int instanceID, Map<String,String> requiredFiles) { List<String> invalideFiles = new ArrayList<>(); Log.d(LOG_TAG, "validate cached region files for region " + regionID + ", instanceID: " + instanceID + "..."); String cacheDir = Cache.getInstance().getCachePath("maps/region_" + regionID + "_" + instanceID); Log.d(LOG_TAG, "region cache dir: " + cacheDir); if (!new File(cacheDir).exists()) { Log.d(LOG_TAG, "create cache dir for region " + regionID + ", instanceID: " + instanceID + ": " + cacheDir); new File(cacheDir).mkdirs(); } for (Map.Entry<String,String> entry : requiredFiles.entrySet()) { String filePath = entry.getKey(); String fileHash = entry.getValue(); Log.v(LOG_TAG, "check file " + filePath + " ..."); String cachePath = Cache.getInstance().getCacheFilePath("maps/region_" + regionID + "_" + instanceID + "/" + filePath); if (!new File(cachePath).exists()) { Log.d(LOG_TAG, "CACHE MISS of file: " + cachePath); invalideFiles.add(filePath); } else { Log.d(LOG_TAG, "CACHE HIT of file: " + cachePath); try { String checksum = HashUtils.computeMD5FileHash(new File(cachePath)); if (fileHash.equals(checksum)) { Log.v(LOG_TAG, "cached region file is valide: " + filePath + " (checksum: " + checksum + ")"); } else { Log.d(LOG_TAG, "OUTDATED CACHE file: " + cachePath + " (local checksum: " + checksum + ", remote checksum: " + fileHash + ")"); invalideFiles.add(filePath); } } catch (Exception e) { Log.w(LOG_TAG, "Exception while calculating file checksum: ", e); invalideFiles.add(filePath); } } } Log.d(LOG_TAG, "file checker finished (" + invalideFiles.size() + " invalide cached files)."); return invalideFiles; } }
FileChecker { public static List<String> validateFiles (long regionID, int instanceID, Map<String,String> requiredFiles) { List<String> invalideFiles = new ArrayList<>(); Log.d(LOG_TAG, "validate cached region files for region " + regionID + ", instanceID: " + instanceID + "..."); String cacheDir = Cache.getInstance().getCachePath("maps/region_" + regionID + "_" + instanceID); Log.d(LOG_TAG, "region cache dir: " + cacheDir); if (!new File(cacheDir).exists()) { Log.d(LOG_TAG, "create cache dir for region " + regionID + ", instanceID: " + instanceID + ": " + cacheDir); new File(cacheDir).mkdirs(); } for (Map.Entry<String,String> entry : requiredFiles.entrySet()) { String filePath = entry.getKey(); String fileHash = entry.getValue(); Log.v(LOG_TAG, "check file " + filePath + " ..."); String cachePath = Cache.getInstance().getCacheFilePath("maps/region_" + regionID + "_" + instanceID + "/" + filePath); if (!new File(cachePath).exists()) { Log.d(LOG_TAG, "CACHE MISS of file: " + cachePath); invalideFiles.add(filePath); } else { Log.d(LOG_TAG, "CACHE HIT of file: " + cachePath); try { String checksum = HashUtils.computeMD5FileHash(new File(cachePath)); if (fileHash.equals(checksum)) { Log.v(LOG_TAG, "cached region file is valide: " + filePath + " (checksum: " + checksum + ")"); } else { Log.d(LOG_TAG, "OUTDATED CACHE file: " + cachePath + " (local checksum: " + checksum + ", remote checksum: " + fileHash + ")"); invalideFiles.add(filePath); } } catch (Exception e) { Log.w(LOG_TAG, "Exception while calculating file checksum: ", e); invalideFiles.add(filePath); } } } Log.d(LOG_TAG, "file checker finished (" + invalideFiles.size() + " invalide cached files)."); return invalideFiles; } protected  FileChecker(); }
FileChecker { public static List<String> validateFiles (long regionID, int instanceID, Map<String,String> requiredFiles) { List<String> invalideFiles = new ArrayList<>(); Log.d(LOG_TAG, "validate cached region files for region " + regionID + ", instanceID: " + instanceID + "..."); String cacheDir = Cache.getInstance().getCachePath("maps/region_" + regionID + "_" + instanceID); Log.d(LOG_TAG, "region cache dir: " + cacheDir); if (!new File(cacheDir).exists()) { Log.d(LOG_TAG, "create cache dir for region " + regionID + ", instanceID: " + instanceID + ": " + cacheDir); new File(cacheDir).mkdirs(); } for (Map.Entry<String,String> entry : requiredFiles.entrySet()) { String filePath = entry.getKey(); String fileHash = entry.getValue(); Log.v(LOG_TAG, "check file " + filePath + " ..."); String cachePath = Cache.getInstance().getCacheFilePath("maps/region_" + regionID + "_" + instanceID + "/" + filePath); if (!new File(cachePath).exists()) { Log.d(LOG_TAG, "CACHE MISS of file: " + cachePath); invalideFiles.add(filePath); } else { Log.d(LOG_TAG, "CACHE HIT of file: " + cachePath); try { String checksum = HashUtils.computeMD5FileHash(new File(cachePath)); if (fileHash.equals(checksum)) { Log.v(LOG_TAG, "cached region file is valide: " + filePath + " (checksum: " + checksum + ")"); } else { Log.d(LOG_TAG, "OUTDATED CACHE file: " + cachePath + " (local checksum: " + checksum + ", remote checksum: " + fileHash + ")"); invalideFiles.add(filePath); } } catch (Exception e) { Log.w(LOG_TAG, "Exception while calculating file checksum: ", e); invalideFiles.add(filePath); } } } Log.d(LOG_TAG, "file checker finished (" + invalideFiles.size() + " invalide cached files)."); return invalideFiles; } protected  FileChecker(); static List<String> validateFiles(long regionID, int instanceID, Map<String,String> requiredFiles); }
FileChecker { public static List<String> validateFiles (long regionID, int instanceID, Map<String,String> requiredFiles) { List<String> invalideFiles = new ArrayList<>(); Log.d(LOG_TAG, "validate cached region files for region " + regionID + ", instanceID: " + instanceID + "..."); String cacheDir = Cache.getInstance().getCachePath("maps/region_" + regionID + "_" + instanceID); Log.d(LOG_TAG, "region cache dir: " + cacheDir); if (!new File(cacheDir).exists()) { Log.d(LOG_TAG, "create cache dir for region " + regionID + ", instanceID: " + instanceID + ": " + cacheDir); new File(cacheDir).mkdirs(); } for (Map.Entry<String,String> entry : requiredFiles.entrySet()) { String filePath = entry.getKey(); String fileHash = entry.getValue(); Log.v(LOG_TAG, "check file " + filePath + " ..."); String cachePath = Cache.getInstance().getCacheFilePath("maps/region_" + regionID + "_" + instanceID + "/" + filePath); if (!new File(cachePath).exists()) { Log.d(LOG_TAG, "CACHE MISS of file: " + cachePath); invalideFiles.add(filePath); } else { Log.d(LOG_TAG, "CACHE HIT of file: " + cachePath); try { String checksum = HashUtils.computeMD5FileHash(new File(cachePath)); if (fileHash.equals(checksum)) { Log.v(LOG_TAG, "cached region file is valide: " + filePath + " (checksum: " + checksum + ")"); } else { Log.d(LOG_TAG, "OUTDATED CACHE file: " + cachePath + " (local checksum: " + checksum + ", remote checksum: " + fileHash + ")"); invalideFiles.add(filePath); } } catch (Exception e) { Log.w(LOG_TAG, "Exception while calculating file checksum: ", e); invalideFiles.add(filePath); } } } Log.d(LOG_TAG, "file checker finished (" + invalideFiles.size() + " invalide cached files)."); return invalideFiles; } protected  FileChecker(); static List<String> validateFiles(long regionID, int instanceID, Map<String,String> requiredFiles);  }