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")); }
public void testSortedRepairCandidates() throws Exception { VersionCounts versionCounts = VersionCounts.make(); VoteBlock vb1 = makeVoteBlock("http://test.com/foo1"); addVersion(vb1, "content 1 for foo1"); VoteBlock vb2 = makeVoteBlock("http://test.com/foo1"); addVersion(vb2, "content 2 for foo1"); VoteBlock vb3 = makeVoteBlock("http://test.com/foo1"); addVersion(vb3, "content 3 for foo1"); addVersion(vb3, "content 2 for foo1"); versionCounts.vote(vb1, participant1); versionCounts.vote(vb2, participant2); versionCounts.vote(vb3, participant3); Map<Integer, Collection<ParticipantUserData>> repairCandidates; repairCandidates = versionCounts.getSortedRepairCandidatesMap(2); assertEquals(SetUtil.set(2), repairCandidates.keySet()); assertSameElements(SetUtil.set(participant2), repairCandidates.get(2)); assertEquals(ListUtil.list(participant2), versionCounts.getSortedRepairCandidates(2)); repairCandidates = versionCounts.getSortedRepairCandidatesMap(1); assertIsomorphic(ListUtil.list(2, 1), repairCandidates.keySet()); assertSameElements(SetUtil.set(participant2), repairCandidates.get(2)); assertSameElements(SetUtil.set(participant1, participant3), repairCandidates.get(1)); List<ParticipantUserData> lst = versionCounts.getSortedRepairCandidates(1); assertTrue( "" + lst, (lst.equals(ListUtil.list(participant2, participant1, participant3)) || lst.equals(ListUtil.list(participant2, participant3, participant1)))); assertEmpty(versionCounts.getSortedRepairCandidatesMap(4)); assertEmpty(versionCounts.getSortedRepairCandidates(4)); }
public void testStoreAuEmptyState() throws Exception { HashSet strCol = new HashSet(); strCol.add("test"); AuState origState = new AuState(mau, repository); repository.storeAuState(origState); AuState loadedState = repository.loadAuState(); assertEquals(-1, loadedState.getLastCrawlTime()); assertEquals(-1, loadedState.getLastCrawlAttempt()); assertEquals(-1, loadedState.getLastCrawlResult()); assertEquals("Unknown code -1", loadedState.getLastCrawlResultMsg()); assertEquals(-1, loadedState.getLastTopLevelPollTime()); assertEquals(-1, loadedState.getLastPollStart()); assertEquals(-1, loadedState.getLastPollResult()); assertEquals(null, loadedState.getLastPollResultMsg()); assertEquals(-1, loadedState.getLastPoPPoll()); assertEquals(-1, loadedState.getLastPoPPollResult()); assertEquals(-1, loadedState.getLastLocalHashScan()); assertEquals(0, loadedState.getNumAgreePeersLastPoR()); assertEquals(0, loadedState.getNumWillingRepairers()); assertEquals(0, loadedState.getNumCurrentSuspectVersions()); assertEmpty(loadedState.getCdnStems()); loadedState.addCdnStem("http://this.is.new/"); assertEquals(ListUtil.list("http://this.is.new/"), loadedState.getCdnStems()); loadedState.addCdnStem("http://this.is.new/"); assertEquals(ListUtil.list("http://this.is.new/"), loadedState.getCdnStems()); assertEquals(0, loadedState.getPollDuration()); assertEquals(0, loadedState.getClockssSubscriptionStatus()); assertEquals(null, loadedState.getAccessType()); assertEquals(SubstanceChecker.State.Unknown, loadedState.getSubstanceState()); assertEquals(null, loadedState.getFeatureVersion(Plugin.Feature.Substance)); assertEquals(null, loadedState.getFeatureVersion(Plugin.Feature.Metadata)); assertEquals(-1, loadedState.getLastMetadataIndex()); assertEquals(0, loadedState.getLastContentChange()); assertEquals(mau.getAuId(), loadedState.getArchivalUnit().getAuId()); }
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(); }