public void testStepperThrows() { final List finished = new ArrayList(); TaskCallback cb = new TaskCallback() { public void taskEvent(SchedulableTask task, Schedule.EventType event) { if (event == Schedule.EventType.FINISH) { finished.add(task); } } }; MyMockStepper stepper = new MyMockStepper(10, -10); stepper.setWhenToThrow(5); StepTask t1 = task(100, 200, 100, cb, stepper); Schedule s = sched(ListUtil.list(t1)); fact.setResult(s); assertTrue(tr.addToSchedule(t1)); TimeBase.setSimulated(101); assertTrue(tr.findTaskToRun()); Interrupter intr = null; try { intr = interruptMeIn(TIMEOUT_SHOULDNT, true); tr.runSteps(new MutableBoolean(true), null); intr.cancel(); } catch (Exception e) { log.error("runSteps threw:", e); } finally { if (intr.did()) { fail("runSteps looped"); } } assertSame(t1, finished.get(0)); assertTrue(t1.e instanceof ExpectedRuntimeException); assertEquals(5, stepper.nSteps); }
// remove task-ending chunk, past task deadline, s.b. Timeout error. public void testRemoveChunkTaskEndTimeout() { final List finished = new ArrayList(); StepTask t1 = task( 100, 200, 100, new TaskCallback() { public void taskEvent(SchedulableTask task, Schedule.EventType event) { if (log.isDebug2()) { log.debug2("testRemoveChunkTaskEndTimeout callback"); } if (event == Schedule.EventType.FINISH) { finished.add(task); } } }); Schedule s = sched(ListUtil.list(t1)); fact.setResult(s); assertTrue(tr.addToSchedule(t1)); Schedule.Chunk chunk = (Schedule.Chunk) s.getEvents().get(0); assertTrue(tr.getCurrentSchedule().getEvents().contains(chunk)); chunk.setTaskEnd(); TimeBase.setSimulated(201); tr.removeChunk(chunk); assertFalse(tr.getCurrentSchedule().getEvents().contains(chunk)); assertSame(t1, finished.get(0)); assertNotNull(t1.e); assertTrue(t1.e.toString(), t1.e instanceof SchedService.Timeout); assertEmpty(tr.getAcceptedTasks()); }
private void assertEqualMessages(V3LcapMessage a, V3LcapMessage b) throws Exception { assertTrue(a.getOriginatorId() == b.getOriginatorId()); assertEquals(a.getOpcode(), b.getOpcode()); assertEquals(a.getTargetUrl(), b.getTargetUrl()); assertEquals(a.getArchivalId(), b.getArchivalId()); assertEquals(a.getProtocolVersion(), b.getProtocolVersion()); assertEquals(a.getPollerNonce(), b.getPollerNonce()); assertEquals(a.getVoterNonce(), b.getVoterNonce()); assertEquals(a.getVoterNonce2(), b.getVoterNonce2()); assertEquals(a.getPluginVersion(), b.getPluginVersion()); assertEquals(a.getHashAlgorithm(), b.getHashAlgorithm()); assertEquals(a.isVoteComplete(), b.isVoteComplete()); assertEquals(a.getRepairDataLength(), b.getRepairDataLength()); assertEquals(a.getLastVoteBlockURL(), b.getLastVoteBlockURL()); assertIsomorphic(a.getNominees(), b.getNominees()); List aBlocks = new ArrayList(); List bBlocks = new ArrayList(); for (VoteBlocksIterator iter = a.getVoteBlockIterator(); iter.hasNext(); ) { aBlocks.add(iter.next()); } for (VoteBlocksIterator iter = b.getVoteBlockIterator(); iter.hasNext(); ) { bBlocks.add(iter.next()); } assertTrue(aBlocks.equals(bBlocks)); // TODO: Figure out how to test time. }
/** * Method that creates a simulated Cached URL from the source code provided by the goodContent * String. It then asserts that the metadata extracted, by using the * MetaPressRisMetadataExtractorFactory, match the metadata in the source code. * * @throws Exception */ public void testExtractGoodRisContent() throws Exception { String goodContent = createGoodRisContent(); log.debug3(goodContent); List<ArticleMetadata> mdlist = setupContentForAU(bau1, RIS_URL, goodContent, false); assertNotEmpty(mdlist); ArticleMetadata md = mdlist.get(0); assertNotNull(md); assertEquals(goodVolume, md.get(MetadataField.FIELD_VOLUME)); assertEquals(goodIssue, md.get(MetadataField.FIELD_ISSUE)); assertEquals(goodStartPage, md.get(MetadataField.FIELD_START_PAGE)); assertEquals(goodEndPage, md.get(MetadataField.FIELD_END_PAGE)); assertEquals(goodIssn, md.get(MetadataField.FIELD_ISSN)); Iterator<String> actAuthIter = md.getList(MetadataField.FIELD_AUTHOR).iterator(); for (String expAuth : goodAuthors) { assertEquals(expAuth, actAuthIter.next()); } assertEquals(goodTitle, md.get(MetadataField.FIELD_ARTICLE_TITLE)); assertEquals(goodJournal, md.get(MetadataField.FIELD_PUBLICATION_TITLE)); assertEquals(goodDate, md.get(MetadataField.FIELD_DATE)); assertEquals(goodPublisher, md.get(MetadataField.FIELD_PUBLISHER)); assertEquals(goodDOI, md.get(MetadataField.FIELD_DOI)); // This shouldn't get set. It will default later to fuill_text_cu assertNotEquals(doiURL, md.get(MetadataField.FIELD_ACCESS_URL)); }
public void setRepoMap(Map<String, PlatformUtil.DF> repoMap) { List repos = new ArrayList(); this.repoMap = repoMap; for (String repo : repoMap.keySet()) { repos.add(repo); } setRepos(repos); }
public void testSimpleMainXML() throws Exception { log.debug3("testSimpleMainXML"); String xml_url = TAR_A_BASE + SUBDIR + "01420615/v64sC/S0142061514004608/main.xml"; List<ArticleMetadata> mdList = extractFromContent(xml_url, "text/xml", simpleMain, nocheck_mle, null); assertEquals(1, mdList.size()); validateSingleMainMetadataRecord(mdList.get(0), "10.1016/j.jidx.2014.07.028", "article"); }
public void testFunctionalFromTarHierarchy() throws Exception { log.debug3("in testFromTarHierarchy"); // load the tarballs InputStream file_input = null; try { file_input = getResourceAsStream(realTARFile_A); // UrlCacher uc = au.makeUrlCacher(TAR_A_BASE); // uc.storeContent(file_input, tarHeader); UrlCacher uc = tarAu.makeUrlCacher(new UrlData(file_input, tarHeader, TAR_A_BASE)); uc.storeContent(); IOUtil.safeClose(file_input); file_input = getResourceAsStream(realTARFile_B); // uc = au.makeUrlCacher(TAR_B_BASE); // uc.storeContent(file_input, tarHeader); uc = tarAu.makeUrlCacher(new UrlData(file_input, tarHeader, TAR_B_BASE)); uc.storeContent(); IOUtil.safeClose(file_input); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtil.safeClose(file_input); } CachedUrlSet cus = tarAu.getAuCachedUrlSet(); for (CachedUrl cu : cus.getCuIterable()) { log.debug3("AU - cu is: " + cu.getUrl()); cu.release(); } // We need to start from the level of the ArticleMetadataExtractor MyListEmitter emitter = new MyListEmitter(); ArticleMetadataExtractor amEx = new ElsevierDeferredArticleMetadataExtractor(ArticleFiles.ROLE_ARTICLE_METADATA); Iterator<ArticleFiles> it = tarAu.getArticleIterator(MetadataTarget.Any()); while (it.hasNext()) { ArticleFiles af = it.next(); log.debug3("Metadata test - articlefiles " + af.toString()); // CachedUrl cu = af.getFullTextCu(); CachedUrl cu = af.getRoleCu(ArticleFiles.ROLE_ARTICLE_METADATA); log.debug3("metadata cu is " + cu.getUrl()); // List<ArticleMetadata> mdlist = mle.extract(MetadataTarget.Any(), cu); amEx.extract(MetadataTarget.Any(), af, emitter); List<ArticleMetadata> returnList = emitter.getAmList(); assertNotNull(returnList); log.debug3("size of returnList is " + returnList.size()); Iterator<ArticleMetadata> mdIt = returnList.iterator(); ArticleMetadata mdRecord = null; while (mdIt.hasNext()) { mdRecord = (ArticleMetadata) mdIt.next(); validateCompleteMetadataRecord(mdRecord); } } }
protected void assertEqualTables(Object[][] a1, List lines) { assertEquals("numrows", a1.length, lines.size() - NUM_HEADER_LINES); for (int irow = 0; irow <= a1.length - 1; irow++) { Object expRow[] = a1[irow]; List row = StringUtil.breakAt((String) lines.get(irow + NUM_HEADER_LINES), ','); assertEquals("numcols", expRow.length, row.size()); assertEquals(("row " + irow), SetUtil.fromArray(expRow), new HashSet(row)); } }
// Break the line at commas, return a map of the resulting strings // broken at equals sign. (<i>Ie</i>, name value pairs.) Map getRow(String line) { Map map = new HashMap(); for (Iterator iter = StringUtil.breakAt(line, ',').iterator(); iter.hasNext(); ) { String item = (String) iter.next(); List pair = StringUtil.breakAt(item, '='); map.put(pair.get(0), pair.get(1)); } return map; }
List<String> auUrls(ArchivalUnit au) { List<String> res = new ArrayList<String>(); for (Iterator iter = au.getAuCachedUrlSet().contentHashIterator(); iter.hasNext(); ) { CachedUrlSetNode cusn = (CachedUrlSetNode) iter.next(); if (cusn.hasContent()) { res.add(cusn.getUrl()); } } return res; }
public boolean createSchedule(Collection tasks) { log.debug("createSchedule(" + tasks + ")"); this.tasks = tasks; createArgs.add(tasks); if (results == null || results.isEmpty()) { lastSched = null; } else { lastSched = (Schedule) results.remove(0); } return lastSched != null; }
void assertPubKs(File file, String pass, List<String> hosts) throws Exception { KeyStore ks = loadKeyStore("jceks", file, pass); List aliases = ListUtil.fromIterator(new EnumerationIterator(ks.aliases())); assertEquals(hosts.size(), aliases.size()); for (String host : hosts) { String alias = host + ".crt"; Certificate cert = ks.getCertificate(alias); assertNotNull(cert); assertEquals("X.509", cert.getType()); } }
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(); }
void assertPrivateKs(File file, String pass, String alias) throws Exception { KeyStore ks = loadKeyStore("jceks", file, alias); List aliases = ListUtil.fromIterator(new EnumerationIterator(ks.aliases())); assertEquals(2, aliases.size()); Certificate cert = ks.getCertificate(alias + ".crt"); assertNotNull(cert); assertEquals("X.509", cert.getType()); assertTrue(ks.isKeyEntry(alias + ".key")); assertTrue(ks.isCertificateEntry(alias + ".crt")); Key key = ks.getKey(alias + ".key", pass.toCharArray()); assertNotNull(key); assertEquals("RSA", key.getAlgorithm()); }
public void testDOIExtraction() throws Exception { List<ArticleMetadata> mdlist = setupContentForAU(bau1, ABS_URL, goodHtmlContentNoDOIorPublisher, true); assertNotEmpty(mdlist); ArticleMetadata md = mdlist.get(0); assertNotNull(md); // gets pulled from the URL if not set in the metadata assertEquals("10.1175/2010WCAS1063.1", md.get(MetadataField.FIELD_DOI)); // gets set manually if not in the metadata // first it would try the TDB assertEquals(goodPublisher, md.get(MetadataField.FIELD_PUBLISHER)); }
private PollHistoryBean createPollHistoryBean(int voteCount) throws Exception { PollState state = new PollState(1, "lwr", "upr", 2, 5, null, false); List votes = new ArrayList(voteCount); for (int ii = 0; ii < voteCount; ii++) { VoteBean bean = new VoteBean(); bean.setId(idKey); bean.setAgreeState(true); bean.setChallengeString("1234"); bean.setHashString("2345"); bean.setVerifierString("3456"); votes.add(bean.getVote()); } return new PollHistoryBean(new PollHistory(state, 0, votes)); }
public void testExtractGoodHtmlContent() throws Exception { List<ArticleMetadata> mdlist = setupContentForAU(bau1, ABS_URL, goodHtmlContent, true); assertNotEmpty(mdlist); ArticleMetadata md = mdlist.get(0); assertNotNull(md); assertEquals(goodPublisher, md.get(MetadataField.FIELD_PUBLISHER)); assertEquals(goodTitle, md.get(MetadataField.DC_FIELD_TITLE)); assertEquals(goodDate, md.get(MetadataField.FIELD_DATE)); assertEquals(goodFormat, md.get(MetadataField.DC_FIELD_FORMAT)); assertEquals(goodType, md.get(MetadataField.DC_FIELD_TYPE)); assertEquals(Arrays.asList(goodAuthors), md.getList(MetadataField.FIELD_AUTHOR)); assertEquals(goodAuthors[0], md.get(MetadataField.DC_FIELD_CREATOR)); }
public void testSimpleDatasetXML() throws Exception { log.debug3("testSimpleDatasetXML"); String file_input = StringUtil.fromInputStream(getResourceAsStream(testDatasetFile)); String xml_url = TAR_A_BASE + SUBDIR + "dataset.xml"; List<ArticleMetadata> mdList = extractFromContent(xml_url, "text/xml", file_input, nocheck_mle, null); assertEquals(6, mdList.size()); Iterator<ArticleMetadata> mdIt = mdList.iterator(); ArticleMetadata mdRecord = null; while (mdIt.hasNext()) { mdRecord = (ArticleMetadata) mdIt.next(); validateDatasetMetadataRecord(mdRecord); } }
public void emitMetadata(ArticleFiles af, ArticleMetadata md) { if (log.isDebug3()) log.debug3("emit(" + af + ", " + md + ")"); if (md != null) { log.debug3("add " + md + " to amlist"); amlst.add(md); } ; }
public void testBaseUrlPath() throws Exception { sau1 = setupSimAu(simAuConfig(tempDirPath)); createContent(sau1); crawlContent(sau1); CachedUrlSet cus1 = sau1.getAuCachedUrlSet(); tempDirPath2 = getTempDir().getAbsolutePath() + File.separator; Configuration config2 = simAuConfig(tempDirPath2); config2.put("base_url", "http://anotherhost.org/some/path/"); SimulatedArchivalUnit sau2 = setupSimAu(config2); createContent(sau2); crawlContent(sau2); CachedUrlSet cus2 = sau1.getAuCachedUrlSet(); List urls1 = auUrls(sau1); List urls2 = auUrls(sau2); Pattern pat1 = Pattern.compile("http://www\\.example\\.com(/.*)$"); Pattern pat2 = Pattern.compile("http://anotherhost\\.org/some/path(/.*)$"); List<String> l1 = auUrls(sau1); List<String> l2 = auUrls(sau2); assertEquals(l1.size(), l2.size()); for (int ix = 0; ix < l1.size(); ix++) { Matcher m1 = pat1.matcher(l1.get(ix)); assertTrue(m1.matches()); Matcher m2 = pat2.matcher(l2.get(ix)); assertTrue(m2.matches()); assertEquals(m1.group(1), m2.group(1)); } }
/** * Method that creates a simulated Cached URL from the source code provided by the goodContent * String. It then asserts that the metadata extracted, by using the * MetaPressRisMetadataExtractorFactory, match the metadata in the source code. * * @throws Exception */ public void testExtractAlternateRisContent() throws Exception { String goodContent = createAlternateRisContent(); log.debug3(goodContent); List<ArticleMetadata> mdlist = setupContentForAU(bau1, RIS_URL, goodContent, false); assertNotEmpty(mdlist); ArticleMetadata md = mdlist.get(0); assertNotNull(md); Iterator<String> actAuthIter = md.getList(MetadataField.FIELD_AUTHOR).iterator(); for (String expAuth : goodAuthors) { assertEquals(expAuth, actAuthIter.next()); } assertEquals(goodTitle, md.get(MetadataField.FIELD_ARTICLE_TITLE)); assertEquals(goodJournal, md.get(MetadataField.FIELD_PUBLICATION_TITLE)); assertEquals(goodDate, md.get(MetadataField.FIELD_DATE)); assertEquals(goodPublisher, md.get(MetadataField.FIELD_PUBLISHER)); }
// make a Schedule with one chunk per task Schedule sched(List tasks) { List events = new ArrayList(); for (Iterator iter = tasks.iterator(); iter.hasNext(); ) { Object obj = iter.next(); if (obj instanceof Schedule.Event) { events.add(obj); } else { SchedulableTask task = (SchedulableTask) obj; if (task.isBackgroundTask()) { events.add(bEvent((BackgroundTask) task, Schedule.EventType.START)); } else { events.add(chunk((StepTask) task)); } } } Schedule s = new Schedule(events); return s; }
public void testFindTaskToRunRemovesExpiredChunks() { assertFalse(tr.findTaskToRun()); StepTask t1 = task(100, 200, 100); StepTask t2 = task(100, 300, 50); StepTask texp1 = task(0, 0, 50); StepTask texp2 = task(0, 0, 50); Schedule s = sched(ListUtil.list(texp1, texp2, t1, t2)); fact.setResults(s, s); assertTrue(tr.addToSchedule(t1)); assertTrue(tr.addToSchedule(t2)); assertFalse(tr.findTaskToRun()); assertEquals(2, removedChunks.size()); assertEquals( SetUtil.set(texp1, texp2), SetUtil.set( ((Schedule.Chunk) removedChunks.get(0)).getTask(), ((Schedule.Chunk) removedChunks.get(1)).getTask())); }
public void testText() throws Exception { MockStatusAccessor statusAccessor = MockStatusAccessor.generateStatusAccessor(colArray1, rowArray1); statusAccessor.setTitle("testtbl", null); statSvc.registerStatusAccessor("testtbl", statusAccessor); WebResponse resp = getTable("testtbl", true); assertResponseOk(resp); assertEquals("Content type", "text/plain", resp.getContentType()); log.debug(resp.getText()); List lines = getLines(resp); assertEquals(rowArray1.length + 3, lines.size()); Map row0 = getRow((String) lines.get(0)); assertEquals("2.4.6.8", row0.get("host")); Map row2 = getRow((String) lines.get(2)); assertEquals("testtbl", row2.get("table")); assertEqualTables(table1, lines); }
public void testRequestMessageCreation() throws Exception { V3LcapMessage reqMsg = new V3LcapMessage( "ArchivalID_2", "key", "Plug42", m_testBytes, m_testBytes, V3LcapMessage.MSG_REPAIR_REQ, 987654321, m_testID, tempDir, theDaemon); reqMsg.setTargetUrl("http://foo.com/"); for (Iterator ix = m_testVoteBlocks.iterator(); ix.hasNext(); ) { reqMsg.addVoteBlock((VoteBlock) ix.next()); } assertEquals(3, reqMsg.getProtocolVersion()); assertEquals("Plug42", reqMsg.getPluginVersion()); assertTrue(m_testID == reqMsg.getOriginatorId()); assertEquals(V3LcapMessage.MSG_REPAIR_REQ, reqMsg.getOpcode()); assertEquals("ArchivalID_2", reqMsg.getArchivalId()); assertEquals("http://foo.com/", reqMsg.getTargetUrl()); assertEquals(m_testBytes, reqMsg.getPollerNonce()); assertEquals(m_testBytes, reqMsg.getVoterNonce()); assertEquals(null, reqMsg.getVoterNonce2()); List aBlocks = new ArrayList(); List bBlocks = new ArrayList(); for (VoteBlocksIterator iter = m_testMsg.getVoteBlockIterator(); iter.hasNext(); ) { aBlocks.add(iter.next()); } for (VoteBlocksIterator iter = reqMsg.getVoteBlockIterator(); iter.hasNext(); ) { bBlocks.add(iter.next()); } assertEquals(aBlocks, bBlocks); // Actual size of test vote blocks is unpredictable assertTrue(reqMsg.getEstimatedEncodedLength() > V3LcapMessage.EST_ENCODED_HEADER_LENGTH); }
public void testNotifyThread() { final List rec = new ArrayList(); final SimpleBinarySemaphore sem = new SimpleBinarySemaphore(); tr.setImmediateNotify(false); TaskCallback cb = new TaskCallback() { public void taskEvent(SchedulableTask task, Schedule.EventType event) { rec.add(new BERec(Deadline.in(0), (BackgroundTask) task, event)); sem.give(); } }; BackgroundTask t1 = btask(100, 200, .1, cb); BackgroundTask t2 = btask(100, 300, .2, cb); tr.notify(t1, Schedule.EventType.START); tr.notify(t1, Schedule.EventType.FINISH); // 2nd finish event should not cause another callback tr.notify(t1, Schedule.EventType.FINISH); tr.notify(t2, Schedule.EventType.START); Interrupter intr = null; try { intr = interruptMeIn(TIMEOUT_SHOULDNT, true); while (rec.size() < 3) { sem.take(); } assertEquals( ListUtil.list( new BERec(0, t1, Schedule.EventType.START), new BERec(0, t1, Schedule.EventType.FINISH), new BERec(0, t2, Schedule.EventType.START)), rec); intr.cancel(); } finally { if (intr.did()) { fail("Notifier didn't run callbacks"); } } }
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 testFindTaskToRunRemovesExpiredOverrunners() { assertFalse(tr.findTaskToRun()); StepTask t1 = task(100, 200, 100); StepTask t2 = task(100, 300, 50); StepTask texp1 = task(0, 0, 50); StepTask texp2 = task(0, 0, 49); Schedule s = sched(ListUtil.list(t1, t2)); fact.setResults(s, s); assertTrue(tr.addToSchedule(t1)); assertTrue(tr.addToSchedule(t2)); tr.addOverrunner(texp1); tr.addOverrunner(texp2); // if this fails, it might be because the sorted list/set is treating // sort-order equivalence as object equality, which we don't want assertEquals(2, tr.getOverrunTasks().size()); assertFalse(tr.findTaskToRun()); assertEquals(0, removedChunks.size()); assertEquals(2, removedTasks.size()); assertEquals( SetUtil.set(texp1, texp2), SetUtil.set((StepTask) removedTasks.get(0), (StepTask) removedTasks.get(1))); }
// test completion & callback public void testDone() throws Exception { HashQueue q = new HashQueue(); final List cookieList = new LinkedList(); final List eList = new LinkedList(); HashService.Callback cb = new HashService.Callback() { public void hashingFinished( CachedUrlSet urlset, long timeUsed, Object cookie, CachedUrlSetHasher hasher, Exception e) { cookieList.add(cookie); eList.add(e); } }; HashQueue.Request r1, r2, r3, r4, r5; r1 = req(2000, 0, 100, cb); r2 = req(10000, 0, 200, cb); r3 = req(20000, 0, 0, cb); r4 = req(50000, 0, 1, cb); assertTrue(q.insert(r1)); assertTrue(q.insert(r2)); assertTrue(q.insert(r4)); assertEquals(0, cookieList.size()); q.removeCompleted(); assertEquals(0, cookieList.size()); // make r1 timeout r1.deadline.expire(); q.removeCompleted(); List exp = ListUtil.list(r1); assertEquals(exp, cookieList); assertEquals(exp, q.getCompletedSnapshot()); // make r2 timeout TimeBase.step(11000); // r3 is finished assertTrue(q.insert(r3)); Exception r4e = new Exception(); // make r4 error r4.e = r4e; q.removeCompleted(); // check that they all finished, and in the right order Object exp2[] = {r1, r2, r3, r4}; assertIsomorphic(exp2, cookieList); assertIsomorphic(exp2, q.getCompletedSnapshot()); // check their exceptions assertTrue(eList.get(0) instanceof HashService.Timeout); assertTrue(eList.get(1) instanceof HashService.Timeout); assertSame(null, eList.get(2)); assertSame(r4e, eList.get(3)); }
public void testBackground() { final List rec = new ArrayList(); TaskCallback cb = new TaskCallback() { public void taskEvent(SchedulableTask task, Schedule.EventType event) { rec.add(new BERec(Deadline.in(0), (BackgroundTask) task, event)); } }; assertFalse(tr.findTaskToRun()); BackgroundTask t1 = btask(100, 200, .1, cb); BackgroundTask t2 = btask(100, 300, .2, cb); BackgroundTask t3 = btask(150, 200, .4, cb); Schedule s = sched( ListUtil.list( bEvent(t1, Schedule.EventType.START), bEvent(t2, Schedule.EventType.START), bEvent(t3, Schedule.EventType.START), bEvent(t1, Schedule.EventType.FINISH), bEvent(t3, Schedule.EventType.FINISH), bEvent(t2, Schedule.EventType.FINISH))); fact.setResults(ListUtil.list(s, s, s)); assertTrue(tr.addToSchedule(t1)); assertTrue(tr.addToSchedule(t2)); assertTrue(tr.addToSchedule(t3)); assertEquals(3, tr.getAcceptedTasks().size()); assertIsomorphic(ListUtil.list(t1, t2, t3), tr.getAcceptedTasks()); assertFalse(tr.findTaskToRun()); assertEquals(0, rec.size()); assertEquals(0, tr.getBackgroundLoadFactor(), .005); assertEquals(Deadline.at(100), tr.runningDeadline); TimeBase.setSimulated(101); assertFalse(tr.findTaskToRun()); assertEquals(2, rec.size()); assertEquals(.3, tr.getBackgroundLoadFactor(), .005); TimeBase.setSimulated(151); assertFalse(tr.findTaskToRun()); assertEquals(3, rec.size()); assertEquals(.7, tr.getBackgroundLoadFactor(), .005); assertEquals(3, tr.getAcceptedTasks().size()); TimeBase.setSimulated(201); assertFalse(tr.findTaskToRun()); assertEquals(5, rec.size()); assertEquals(.2, tr.getBackgroundLoadFactor(), .005); assertEquals(1, tr.getAcceptedTasks().size()); t2.taskIsFinished(); TimeBase.setSimulated(202); assertFalse(tr.findTaskToRun()); assertEquals(6, rec.size()); assertEquals(0, tr.getBackgroundLoadFactor(), .005); assertEquals(0, tr.getAcceptedTasks().size()); TimeBase.setSimulated(301); assertFalse(tr.findTaskToRun()); assertEquals(6, rec.size()); assertEquals(0, tr.getBackgroundLoadFactor(), .005); List exp = ListUtil.list( new BERec(101, t1, Schedule.EventType.START), new BERec(101, t2, Schedule.EventType.START), new BERec(151, t3, Schedule.EventType.START), new BERec(201, t1, Schedule.EventType.FINISH), new BERec(201, t3, Schedule.EventType.FINISH), new BERec(201, t2, Schedule.EventType.FINISH)); assertEquals(exp, rec); }