public void testGetNodeLocation() throws Exception { MockCachedUrlSetSpec mspec = new MockCachedUrlSetSpec("http://www.example.com", null); MockCachedUrlSet mcus = new MockCachedUrlSet(mau, mspec); String location = repository.getNodeLocation(mcus); String expected = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); expected = LockssRepositoryImpl.mapUrlToFileLocation(expected, "http://www.example.com"); assertEquals(expected, location); }
// hack only local public synchronized LockssRepositoryImpl getRepositoryFromPath(String path) { LockssRepositoryImpl repo = (LockssRepositoryImpl) localRepos.get(path); if (repo == null) { repo = new LockssRepositoryImpl(path); repo.initService(getDaemon()); repo.startService(); localRepos.put(path, repo); } return repo; }
public void testStoreNodeState() throws Exception { TimeBase.setSimulated(100); CachedUrlSet mcus = new MockCachedUrlSet(mau, new RangeCachedUrlSetSpec("http://www.example.com")); CrawlState crawl = new CrawlState(1, 2, 123); List polls = new ArrayList(2); PollState poll1 = new PollState(1, "sdf", "jkl", 2, 123, Deadline.at(456), false); PollState poll2 = new PollState(2, "abc", "def", 3, 321, Deadline.at(654), false); polls.add(poll1); polls.add(poll2); NodeState nodeState = new NodeStateImpl(mcus, 123321, crawl, polls, repository); ((NodeStateImpl) nodeState).setState(NodeState.DAMAGE_AT_OR_BELOW); repository.storeNodeState(nodeState); String filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath = LockssRepositoryImpl.mapUrlToFileLocation( filePath, "http://www.example.com/" + HistoryRepositoryImpl.NODE_FILE_NAME); File xmlFile = new File(filePath); assertTrue(xmlFile.exists()); nodeState = null; nodeState = repository.loadNodeState(mcus); assertSame(mcus, nodeState.getCachedUrlSet()); assertEquals(123321, nodeState.getAverageHashDuration()); assertEquals(1, nodeState.getCrawlState().getType()); assertEquals(2, nodeState.getCrawlState().getStatus()); assertEquals(123, nodeState.getCrawlState().getStartTime()); assertEquals(NodeState.DAMAGE_AT_OR_BELOW, nodeState.getState()); Iterator pollIt = nodeState.getActivePolls(); assertTrue(pollIt.hasNext()); PollState loadedPoll = (PollState) pollIt.next(); assertEquals(1, loadedPoll.getType()); assertEquals("sdf", loadedPoll.getLwrBound()); assertEquals("jkl", loadedPoll.getUprBound()); assertEquals(2, loadedPoll.getStatus()); assertEquals(123, loadedPoll.getStartTime()); assertEquals(456, loadedPoll.getDeadline().getExpirationTime()); assertTrue(pollIt.hasNext()); loadedPoll = (PollState) pollIt.next(); assertEquals(2, loadedPoll.getType()); assertEquals("abc", loadedPoll.getLwrBound()); assertEquals("def", loadedPoll.getUprBound()); assertEquals(3, loadedPoll.getStatus()); assertEquals(321, loadedPoll.getStartTime()); assertEquals(654, loadedPoll.getDeadline().getExpirationTime()); assertFalse(pollIt.hasNext()); TimeBase.setReal(); }
public List findExistingRepositoriesFor(String auid) { List res = null; for (Iterator iter = getRepositoryList().iterator(); iter.hasNext(); ) { String repoName = (String) iter.next(); String path = LockssRepositoryImpl.getLocalRepositoryPath(repoName); if (LockssRepositoryImpl.doesAuDirExist(auid, path)) { if (res == null) { res = new ArrayList(); } res.add(repoName); } } return res == null ? Collections.EMPTY_LIST : res; }
public void testHandleEmptyFile() throws Exception { MockCachedUrlSetSpec mspec = new MockCachedUrlSetSpec("http://www.example.com", null); CachedUrlSet mcus = new MockCachedUrlSet(mau, mspec); NodeStateImpl nodeState = new NodeStateImpl(mcus, -1, null, null, repository); nodeState.setPollHistoryList(new ArrayList()); // storing empty vector repository.storePollHistories(nodeState); String filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath = LockssRepositoryImpl.mapUrlToFileLocation( filePath, "http://www.example.com/" + HistoryRepositoryImpl.HISTORY_FILE_NAME); File xmlFile = new File(filePath); assertTrue(xmlFile.exists()); nodeState.setPollHistoryList(new ArrayList()); repository.loadPollHistories(nodeState); assertEquals(0, nodeState.pollHistories.size()); mspec = new MockCachedUrlSetSpec("http://www.example2.com", null); mcus = new MockCachedUrlSet(mau, mspec); nodeState = new NodeStateImpl(mcus, -1, null, null, repository); filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath = LockssRepositoryImpl.mapUrlToFileLocation(filePath, "http://www.example2.com/"); xmlFile = new File(filePath); assertFalse(xmlFile.exists()); xmlFile.mkdirs(); filePath += HistoryRepositoryImpl.HISTORY_FILE_NAME; xmlFile = new File(filePath); OutputStream os = new BufferedOutputStream(new FileOutputStream(xmlFile)); os.write(new byte[0]); os.close(); assertTrue(xmlFile.exists()); nodeState.setPollHistoryList(new ArrayList()); repository.loadPollHistories(nodeState); assertEquals(0, nodeState.pollHistories.size()); assertFalse(xmlFile.exists()); xmlFile = new File( filePath + CurrentConfig.getParam( ObjectSerializer.PARAM_FAILED_DESERIALIZATION_EXTENSION, ObjectSerializer.DEFAULT_FAILED_DESERIALIZATION_EXTENSION)); assertTrue(xmlFile.exists()); }
public PlatformUtil.DF getRepositoryDF(String repoName) { String path = LockssRepositoryImpl.getLocalRepositoryPath(repoName); log.debug("path: " + path); // try { return platInfo.getJavaDF(path); // } catch (PlatformUtil.UnsupportedException e) { // return null; // } }
public void testDotUrlHandling() throws Exception { // testing correction of nodes with bad '..'-including urls, // filtering the first '..' but resolving the second // should filter out the first '..' line but resolve the second MockCachedUrlSetSpec mspec = new MockCachedUrlSetSpec("http://www.example.com/branch/test/../test2", null); MockCachedUrlSet mcus = new MockCachedUrlSet(mau, mspec); String location = repository.getNodeLocation(mcus); String expectedStart = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); String expected = LockssRepositoryImpl.mapUrlToFileLocation( expectedStart, "http://www.example.com/branch/test2"); assertEquals(expected, location); mspec = new MockCachedUrlSetSpec("http://www.example.com/branch/./test", null); mcus = new MockCachedUrlSet(mau, mspec); location = repository.getNodeLocation(mcus); expected = LockssRepositoryImpl.mapUrlToFileLocation( expectedStart, "http://www.example.com/branch/test"); assertEquals(expected, location); try { mspec = new MockCachedUrlSetSpec("http://www.example.com/..", null); mcus = new MockCachedUrlSet(mau, mspec); location = repository.getNodeLocation(mcus); fail("Should have thrown MalformedURLException."); } catch (MalformedURLException mue) { } try { mspec = new MockCachedUrlSetSpec("http://www.example.com/test/../../test2", null); mcus = new MockCachedUrlSet(mau, mspec); location = repository.getNodeLocation(mcus); fail("Should have thrown MalformedURLException."); } catch (MalformedURLException mue) { } }
/** * This function returns a RepositoryNode with a canonicalized path. * * @param url the url in String form * @param create true iff the node should be created if absent * @return RepositoryNode the node * @throws MalformedURLException */ private synchronized RepositoryNode getNode(String url, boolean create) throws MalformedURLException { String canonUrl; boolean isAuUrl = false; if (AuUrl.isAuUrl(url)) { // path information is lost here, but is unimportant if it's an AuUrl canonUrl = AuUrl.PROTOCOL; isAuUrl = true; } else { // create a canonical path, handling all illegal path traversal canonUrl = canonicalizePath(url); } // check LRUMap cache for node RepositoryNode node = (RepositoryNode) nodeCache.get(nodeCacheKey(canonUrl)); if (node != null) { return node; } String nodeLocation; if (isAuUrl) { // base directory of ArchivalUnit nodeLocation = rootLocation; node = new AuNodeImpl(canonUrl, nodeLocation, this); } else { // determine proper node location nodeLocation = LockssRepositoryImpl.mapUrlToFileLocation(rootLocation, canonUrl) .replace("?", "") .replace("COM8", "COMEIGHT") .replace("%5c", "/"); // //windows folder structure fix node = new RepositoryNodeImpl(canonUrl, nodeLocation, this); } if (!create) { // if not creating, check for existence File nodeDir = new File(nodeLocation); if (!nodeDir.exists()) { // return null if the node doesn't exist and shouldn't be created return null; } if (!nodeDir.isDirectory()) { logger.error("Cache file not a directory: " + nodeLocation); throw new LockssRepository.RepositoryStateException("Invalid cache file."); } } // add to node cache nodeCache.put(nodeCacheKey(canonUrl), node); return node; }
public void testStoreDamagedNodeSet() throws Exception { DamagedNodeSet damNodes = new DamagedNodeSet(mau, repository); damNodes.nodesWithDamage.add("test1"); damNodes.nodesWithDamage.add("test2"); damNodes.cusToRepair.put("cus1", ListUtil.list("cus1-1", "cus1-2")); damNodes.cusToRepair.put("cus2", ListUtil.list("cus2-1")); assertTrue(damNodes.containsWithDamage("test1")); assertTrue(damNodes.containsWithDamage("test2")); assertFalse(damNodes.containsWithDamage("test3")); repository.storeDamagedNodeSet(damNodes); String filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath += HistoryRepositoryImpl.DAMAGED_NODES_FILE_NAME; File xmlFile = new File(filePath); assertTrue(xmlFile.exists()); damNodes = null; damNodes = repository.loadDamagedNodeSet(); // check damage assertTrue(damNodes.containsWithDamage("test1")); assertTrue(damNodes.containsWithDamage("test2")); assertFalse(damNodes.containsWithDamage("test3")); MockCachedUrlSet mcus1 = new MockCachedUrlSet("cus1"); MockCachedUrlSet mcus2 = new MockCachedUrlSet("cus2"); // check repairs assertTrue(damNodes.containsToRepair(mcus1, "cus1-1")); assertTrue(damNodes.containsToRepair(mcus1, "cus1-2")); assertFalse(damNodes.containsToRepair(mcus1, "cus2-1")); assertTrue(damNodes.containsToRepair(mcus2, "cus2-1")); assertEquals(mau.getAuId(), damNodes.theAu.getAuId()); // check remove damNodes.removeFromRepair(mcus1, "cus1-1"); assertFalse(damNodes.containsToRepair(mcus1, "cus1-1")); assertTrue(damNodes.containsToRepair(mcus1, "cus1-2")); damNodes.removeFromRepair(mcus1, "cus1-2"); assertFalse(damNodes.containsToRepair(mcus1, "cus1-2")); assertNull(damNodes.cusToRepair.get(mcus1)); // check remove from damaged nodes damNodes.removeFromDamage("test1"); damNodes.removeFromDamage("test2"); repository.storeDamagedNodeSet(damNodes); damNodes = repository.loadDamagedNodeSet(); assertNotNull(damNodes); assertFalse(damNodes.containsWithDamage("test1")); assertFalse(damNodes.containsWithDamage("test2")); }
/** * Factory method to create new LockssRepository instances. * * @param au the {@link ArchivalUnit} * @return the new LockssRepository instance */ public static LockssRepository createNewLockssRepository(ArchivalUnit au) { String root = getRepositoryRoot(au); if (root == null || root.equals("null")) { logger.error("No repository dir set in config"); throw new LockssRepository.RepositoryStateException("No repository dir set in config"); } String auDir = LockssRepositoryImpl.mapAuToFileLocation(root, au); if (logger.isDebug2()) { logger.debug2("repo: " + auDir + ", au: " + au.getName()); } staticCacheLocation = extendCacheLocation(root); LockssRepositoryImpl repo = new LockssRepositoryImpl(auDir); Plugin plugin = au.getPlugin(); if (plugin != null) { LockssDaemon daemon = plugin.getDaemon(); if (daemon != null) { RepositoryManager mgr = daemon.getRepositoryManager(); if (mgr != null) { mgr.setRepositoryForPath(auDir, repo); } } } return repo; }
public void setConfig( Configuration config, Configuration oldConfig, Configuration.Differences changedKeys) { // Build list of repositories from list of disk (fs) paths). Needs to // be generalized if ever another repository implementation. if (changedKeys.contains(ConfigManager.PARAM_PLATFORM_DISK_SPACE_LIST)) { List lst = new ArrayList(); String dspace = config.get(ConfigManager.PARAM_PLATFORM_DISK_SPACE_LIST, ""); List paths = StringUtil.breakAt(dspace, ';'); if (paths != null) { for (Iterator iter = paths.iterator(); iter.hasNext(); ) { lst.add("local:" + (String) iter.next()); } } repoList = lst; } if (changedKeys.contains(PARAM_MAX_PER_AU_CACHE_SIZE)) { paramNodeCacheSize = config.getInt(PARAM_MAX_PER_AU_CACHE_SIZE, DEFAULT_MAX_PER_AU_CACHE_SIZE); for (Iterator iter = getDaemon().getAllLockssRepositories().iterator(); iter.hasNext(); ) { LockssRepository repo = (LockssRepository) iter.next(); if (repo instanceof LockssRepositoryImpl) { LockssRepositoryImpl repoImpl = (LockssRepositoryImpl) repo; repoImpl.setNodeCacheSize(paramNodeCacheSize); } } } if (changedKeys.contains(PARAM_MAX_SUSPECT_VERSIONS_CACHE_SIZE)) { paramSuspectVersionsCacheSize = config.getInt( PARAM_MAX_SUSPECT_VERSIONS_CACHE_SIZE, DEFAULT_MAX_SUSPECT_VERSIONS_CACHE_SIZE); suspectVersionsCache.setMaxSize(paramSuspectVersionsCacheSize); } if (changedKeys.contains(GLOBAL_CACHE_PREFIX)) { paramIsGlobalNodeCache = config.getBoolean(PARAM_GLOBAL_CACHE_ENABLED, DEFAULT_GLOBAL_CACHE_ENABLED); if (paramIsGlobalNodeCache) { paramGlobalNodeCacheSize = config.getInt(PARAM_MAX_GLOBAL_CACHE_SIZE, DEFAULT_MAX_GLOBAL_CACHE_SIZE); log.debug("global node cache size: " + paramGlobalNodeCacheSize); globalNodeCache.setMaxSize(paramGlobalNodeCacheSize); } } if (changedKeys.contains(DISK_PREFIX)) { int minMB = config.getInt(PARAM_DISK_WARN_FRRE_MB, DEFAULT_DISK_WARN_FRRE_MB); double minPer = config.getPercentage(PARAM_DISK_WARN_FRRE_PERCENT, DEFAULT_DISK_WARN_FRRE_PERCENT); paramDFWarn = PlatformUtil.DF.makeThreshold(minMB, minPer); minMB = config.getInt(PARAM_DISK_FULL_FRRE_MB, DEFAULT_DISK_FULL_FRRE_MB); minPer = config.getPercentage(PARAM_DISK_FULL_FRRE_PERCENT, DEFAULT_DISK_FULL_FRRE_PERCENT); paramDFFull = PlatformUtil.DF.makeThreshold(minMB, minPer); } if (changedKeys.contains(PARAM_SIZE_CALC_MAX_LOAD)) { sizeCalcMaxLoad = config.getPercentage(PARAM_SIZE_CALC_MAX_LOAD, DEFAULT_SIZE_CALC_MAX_LOAD); } if (changedKeys.contains(PREFIX)) { maxUnusedDirSearch = config.getInt(PARAM_MAX_UNUSED_DIR_SEARCH, DEFAULT_MAX_UNUSED_DIR_SEARCH); isStatefulUnusedDirSearch = config.getBoolean( PARAM_IS_STATEFUL_UNUSED_DIR_SEARCH, DEFAULT_IS_STATEFUL_UNUSED_DIR_SEARCH); enableLongComponents = config.getBoolean(PARAM_ENABLE_LONG_COMPONENTS, DEFAULT_ENABLE_LONG_COMPONENTS); enableLongComponentsCompatibility = config.getBoolean( PARAM_ENABLE_LONG_COMPONENTS_COMPATIBILITY, DEFAULT_ENABLE_LONG_COMPONENTS_COMPATIBILITY); maxComponentLength = config.getInt(PARAM_MAX_COMPONENT_LENGTH, DEFAULT_MAX_COMPONENT_LENGTH); checkUnnormalized = (CheckUnnormalizedMode) config.getEnum( CheckUnnormalizedMode.class, PARAM_CHECK_UNNORMALIZED, DEFAULT_CHECK_UNNORMALIZED); } }
public void testStoreOverwrite() throws Exception { AuState auState = new AuState( mau, 123, // lastCrawlTime 321, // lastCrawlAttempt -1, // lastCrawlResult null, // lastCrawlResultMsg, 321, // lastTopLevelPoll 333, // lastPollStart -1, // lastPollresult null, // lastPollresultMsg 0, // pollDuration -1, // lastTreeWalk null, // crawlUrls null, // accessType 1, // clockssSubscriptionState 1.0, // v3Agreement 1.0, // highestV3Agreement SubstanceChecker.State.Unknown, null, // substanceVersion null, // metadataVersion -1, // lastMetadataIndex 0, // lastContentChange 444, // lastPoPPoll 8, // lastPoPPollResult -1, // lastLocalHashScan 27, // numAgreePeersLastPoR 72, // numWillingRepirers 19, // numCurrentSuspectVersions ListUtil.list("http://foo/"), // cdnStems repository); repository.storeAuState(auState); String filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath += HistoryRepositoryImpl.AU_FILE_NAME; File xmlFile = new File(filePath); FileInputStream fis = new FileInputStream(xmlFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamUtil.copy(fis, baos); fis.close(); String expectedStr = baos.toString(); auState = new AuState( mau, 1234, // lastCrawlTime 4321, // lastCrawlAttempt -1, // lastCrawlResult null, // lastCrawlResultMsg, 4321, // lastTopLevelPoll 5555, // lastPollStart -1, // lastPollresult null, // lastPollresultMsg 0, // pollDuration -1, // lastTreeWalk null, // crawlUrls null, // accessType 1, // clockssSubscriptionState 1.0, // v3Agreement 1.0, // highestV3Agreement SubstanceChecker.State.Unknown, null, // substanceVersion null, // metadataVersion -1, // lastMetadataIndex 0, // lastContentChange -1, // lastPoPPoll -1, // lastPoPPollResult -1, // lastLocalHashScan 13, // numAgreePeersLastPoR 31, // numWillingRepairers 91, // numCurrentSuspectVersions ListUtil.list("http://foo/"), // cdnStems repository); repository.storeAuState(auState); assertEquals(1234, auState.getLastCrawlTime()); assertEquals(4321, auState.getLastCrawlAttempt()); assertEquals(4321, auState.getLastTopLevelPollTime()); assertEquals(5555, auState.getLastPollStart()); assertEquals(13, auState.getNumAgreePeersLastPoR()); assertEquals(31, auState.getNumWillingRepairers()); assertEquals(91, auState.getNumCurrentSuspectVersions()); assertEquals(mau.getAuId(), auState.getArchivalUnit().getAuId()); assertEquals(ListUtil.list("http://foo/"), auState.getCdnStems()); fis = new FileInputStream(xmlFile); baos = new ByteArrayOutputStream(expectedStr.length()); StreamUtil.copy(fis, baos); fis.close(); log.info(baos.toString()); auState = null; auState = repository.loadAuState(); assertEquals(1234, auState.getLastCrawlTime()); assertEquals(4321, auState.getLastCrawlAttempt()); assertEquals(4321, auState.getLastTopLevelPollTime()); assertEquals(5555, auState.getLastPollStart()); assertEquals(13, auState.getNumAgreePeersLastPoR()); assertEquals(31, auState.getNumWillingRepairers()); assertEquals(91, auState.getNumCurrentSuspectVersions()); assertEquals(mau.getAuId(), auState.getArchivalUnit().getAuId()); auState = new AuState( mau, 123, // lastCrawlTime 321, // lastCrawlAttempt -1, // lastCrawlResult null, // lastCrawlResultMsg, 321, // lastTopLevelPoll 333, // lastPollStart -1, // lastPollresult null, // lastPollresultMsg 0, // pollDuration -1, // lastTreeWalk null, // crawlUrls null, // accessType 1, // clockssSubscriptionState 1.0, // v3Agreement 1.0, // highestV3Agreement SubstanceChecker.State.Unknown, null, // substanceVersion null, // metadataVersion -1, // lastMetadataIndex 0, // lastContentChange 444, // lastPoPPoll 8, // lastPoPPollResult -1, // lastLocalHashScan 27, // numAgreePeersLastPoR 72, // numWillingRepairers 19, // numCurrentSuspectVersions ListUtil.list("http://foo/"), // cdnStems repository); repository.storeAuState(auState); fis = new FileInputStream(xmlFile); baos = new ByteArrayOutputStream(expectedStr.length()); StreamUtil.copy(fis, baos); fis.close(); assertEquals(expectedStr, baos.toString()); }
public void testStoreAuState() throws Exception { HashSet strCol = new HashSet(); strCol.add("test"); AuState origState = new AuState( mau, 123000, 123123, 41, "woop woop", 321000, 222000, 3, "pollres", 12345, 456000, strCol, AuState.AccessType.OpenAccess, 2, 1.0, 1.0, SubstanceChecker.State.Yes, "SubstVer3", "MetadatVer7", 111444, 12345, 111222, // lastPoPPoll 7, // lastPoPPollResult 222333, // lastLocalHashScan 444777, // numAgreePeersLastPoR 777444, // numWillingRepairers 747474, // numCurrentSuspectVersions ListUtil.list("http://hos.t/pa/th"), repository); assertEquals("SubstVer3", origState.getFeatureVersion(Plugin.Feature.Substance)); assertEquals("MetadatVer7", origState.getFeatureVersion(Plugin.Feature.Metadata)); assertEquals(111444, origState.getLastMetadataIndex()); repository.storeAuState(origState); String filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath += HistoryRepositoryImpl.AU_FILE_NAME; File xmlFile = new File(filePath); assertTrue(xmlFile.exists()); origState = null; AuState loadedState = repository.loadAuState(); assertEquals(123000, loadedState.getLastCrawlTime()); assertEquals(123123, loadedState.getLastCrawlAttempt()); assertEquals(41, loadedState.getLastCrawlResult()); assertEquals("woop woop", loadedState.getLastCrawlResultMsg()); assertEquals(321000, loadedState.getLastTopLevelPollTime()); assertEquals(222000, loadedState.getLastPollStart()); assertEquals(3, loadedState.getLastPollResult()); assertEquals("Inviting Peers", loadedState.getLastPollResultMsg()); assertEquals(111222, loadedState.getLastPoPPoll()); assertEquals(7, loadedState.getLastPoPPollResult()); assertEquals(222333, loadedState.getLastLocalHashScan()); assertEquals(444777, loadedState.getNumAgreePeersLastPoR()); assertEquals(777444, loadedState.getNumWillingRepairers()); assertEquals(747474, loadedState.getNumCurrentSuspectVersions()); assertEquals(ListUtil.list("http://hos.t/pa/th"), loadedState.getCdnStems()); loadedState.addCdnStem("http://this.is.new/"); assertEquals( ListUtil.list("http://hos.t/pa/th", "http://this.is.new/"), loadedState.getCdnStems()); assertEquals(12345, loadedState.getPollDuration()); assertEquals(2, loadedState.getClockssSubscriptionStatus()); assertEquals(AuState.AccessType.OpenAccess, loadedState.getAccessType()); assertEquals(SubstanceChecker.State.Yes, loadedState.getSubstanceState()); assertEquals("SubstVer3", loadedState.getFeatureVersion(Plugin.Feature.Substance)); assertEquals("MetadatVer7", loadedState.getFeatureVersion(Plugin.Feature.Metadata)); assertEquals(111444, loadedState.getLastMetadataIndex()); assertEquals(12345, loadedState.getLastContentChange()); assertEquals(mau.getAuId(), loadedState.getArchivalUnit().getAuId()); // check crawl urls Collection col = loadedState.getCrawlUrls(); Iterator colIter = col.iterator(); assertTrue(colIter.hasNext()); assertEquals("test", colIter.next()); assertFalse(colIter.hasNext()); }
public void testStorePollHistories() throws Exception { TimeBase.setSimulated(123321); MockCachedUrlSetSpec mspec = new MockCachedUrlSetSpec("http://www.example.com", null); CachedUrlSet mcus = new MockCachedUrlSet(mau, mspec); NodeStateImpl nodeState = new NodeStateImpl(mcus, -1, null, null, repository); List histories = ListUtil.list( createPollHistoryBean(3), createPollHistoryBean(3), createPollHistoryBean(3), createPollHistoryBean(3), createPollHistoryBean(3)); /* * CASTOR: [summary] Rewrite test in non-Castor way * This is obviously not an appropriate way of writing this test, * Right now it creates sample data in Castor format, from legacy * code back when Castor was the built-in serialization engine. * TODO: Rewrite test in non-Castor way */ // nodeState.setPollHistoryBeanList(histories); nodeState.setPollHistoryList(NodeHistoryBean.fromBeanListToList(histories)); repository.storePollHistories(nodeState); String filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath = LockssRepositoryImpl.mapUrlToFileLocation( filePath, "http://www.example.com/" + HistoryRepositoryImpl.HISTORY_FILE_NAME); File xmlFile = new File(filePath); assertTrue(xmlFile.exists()); nodeState.setPollHistoryList(new ArrayList()); repository.loadPollHistories(nodeState); List loadedHistory = nodeState.getPollHistoryList(); assertEquals(histories.size(), loadedHistory.size()); // CASTOR: some Castor-tailored stuff here // PollHistoryBean expect1 = (PollHistoryBean)histories.get(0); // PollHistoryBean elem1 = (PollHistoryBean)loadedHistory.get(0); PollHistory expect1 = (PollHistory) histories.get(0); PollHistory elem1 = (PollHistory) loadedHistory.get(0); assertEquals(expect1.type, elem1.type); assertEquals(expect1.lwrBound, elem1.lwrBound); assertEquals(expect1.uprBound, elem1.uprBound); assertEquals(expect1.status, elem1.status); assertEquals(expect1.startTime, elem1.startTime); assertEquals(expect1.duration, elem1.duration); // CASTOR: some Castor-tailored stuff here // List expectBeans = (List)expect1.getVoteBeans(); // List elemBeans = (List)elem1.getVoteBeans(); Iterator expectIter = (Iterator) expect1.getVotes(); Iterator elemIter = (Iterator) elem1.getVotes(); while (expectIter.hasNext() && elemIter.hasNext()) { Vote expectVote = (Vote) expectIter.next(); Vote elemVote = (Vote) elemIter.next(); assertEquals( expectVote.getVoterIdentity().getIdString(), elemVote.getVoterIdentity().getIdString()); assertEquals(expectVote.isAgreeVote(), elemVote.isAgreeVote()); assertEquals(expectVote.getChallengeString(), elemVote.getChallengeString()); assertEquals(expectVote.getVerifierString(), elemVote.getVerifierString()); assertEquals(expectVote.getHashString(), elemVote.getHashString()); } assertFalse(expectIter.hasNext()); assertFalse(expectIter.hasNext()); TimeBase.setReal(); }