CacheUtil { public void resetCache() throws FailedCacheRefreshException { logger.info("resetCache() -- refilling tumor types cache"); Map<Version, Map<String, TumorType>> latestTumorTypesCache = new HashMap<>(); ArrayList<Version> oncoTreeVersions = new ArrayList<Version>(); ArrayList<String> failedVersions = new ArrayList<String>(); HashMap<String, ArrayList<String>> topBraidURIsToOncotreeCodes = new HashMap<String, ArrayList<String>>(); boolean failedOncoTreeVersionsCacheRefresh = false; boolean failedVersionedOncoTreeNodesCacheRefresh = false; try { oncoTreePersistentCache.updateOncoTreeVersionsInPersistentCache(); } catch (TopBraidException exception) { logger.error("resetCache() -- failed to pull versions from repository"); failedOncoTreeVersionsCacheRefresh = true; } try { oncoTreeVersions = oncoTreePersistentCache.getOncoTreeVersionsFromPersistentCache(); } catch (RuntimeException e) { throw new FailedCacheRefreshException("No data found in specified backup cache location..."); } if (!failedOncoTreeVersionsCacheRefresh) { try { oncoTreePersistentCache.backupOncoTreeVersionsPersistentCache(oncoTreeVersions); } catch (Exception e) { logger.error("Unable to backup versions EHCache"); slackUtil.sendSlackNotification("*OncoTree Error* - OncoTreeVersionsCache backup failed." + e.getMessage()); } } for (Version version : oncoTreeVersions) { Map<String, TumorType> latestTumorTypes = new HashMap<String, TumorType>(); ArrayList<OncoTreeNode> oncoTreeNodes = new ArrayList<OncoTreeNode>(); failedVersionedOncoTreeNodesCacheRefresh = false; if (version != null) { try { oncoTreePersistentCache.updateOncoTreeNodesInPersistentCache(version); } catch (TopBraidException e) { logger.error("resetCache() -- failed to pull tumor types for version '" + version.getVersion() + "' from repository : " + e.toString()); failedVersionedOncoTreeNodesCacheRefresh = true; } try { oncoTreeNodes = oncoTreePersistentCache.getOncoTreeNodesFromPersistentCache(version); } catch (RuntimeException e) { failedVersions.add(version.getVersion()); logger.warn("resetCache() -- failed to retrieve version '" + version.getVersion() + "'"); continue; } if (!failedVersionedOncoTreeNodesCacheRefresh) { try { oncoTreePersistentCache.backupOncoTreeNodesPersistentCache(oncoTreeNodes, version); } catch (Exception e) { logger.error("Unable to backup oncotree nodes EHCache"); slackUtil.sendSlackNotification("*OncoTree Error* - OncoTreeNodesCache backup failed." + e.getMessage()); } } try { latestTumorTypes = tumorTypesUtil.getAllTumorTypesFromOncoTreeNodes(oncoTreeNodes, version, topBraidURIsToOncotreeCodes); } catch (InvalidOncoTreeDataException exception) { logger.error("Unable to get tumor types from oncotree nodes"); failedVersions.add(version.getVersion()); logger.warn("resetCache() -- failed to retrieve version : " + version.getVersion() + " : " + exception.toString()); continue; } } latestTumorTypesCache.put(version, latestTumorTypes); } if (latestTumorTypesCache.keySet().size() == 0) { logger.error("resetCache() -- failed to pull a single valid OncoTree version"); throw new FailedCacheRefreshException("Failed to refresh cache - no versions constructed"); } if (failedVersions.contains(requiredOncotreeVersion)) { logger.error("resetCache() -- failed to pull required oncotree version: " + requiredOncotreeVersion); throw new FailedCacheRefreshException("Failed to refresh cache - required version not constructed"); } if (failedVersions.size() > 0) { slackUtil.sendSlackNotification("OncoTree successfully recached `" + requiredOncotreeVersion + "`, but ran into issues with the following versions: " + String.join(", ", failedVersions)); } tumorTypesCache = latestTumorTypesCache; if (failedOncoTreeVersionsCacheRefresh || failedVersionedOncoTreeNodesCacheRefresh) { throw new FailedCacheRefreshException("Failed to refresh cache - composite error"); } else { dateOfLastCacheRefresh = new Date(); logger.info("resetCache() -- successfully reset cache from repository"); } }  void resetCache(); Date getDateOfLastCacheRefresh(); void setDateOfLastCacheRefresh(Date date); List<Version> getCachedVersions(); Map<String, TumorType> getTumorTypesByVersion(Version version); boolean cacheIsStale(); static final Integer MAXIMUM_CACHE_AGE_IN_DAYS; }
@Test(expected = FailedCacheRefreshException.class) public void testRecacheWithBrokenOncoTreeVersionRepository() { OncotreeTestConfig config = new OncotreeTestConfig(); config.resetNotWorkingVersionRepository(oncoTreeVersionRepository); cacheUtil.resetCache(); }