/** Tests that rfds that have urns are prefered to rfds without. */ public void testPrefersRFDWithURN() throws Exception { ranker.addToPool(newRFD("1.2.3.4", 3)); ranker.addToPool(newRFDWithURN("1.2.3.4", 3)); RemoteFileDescContext selected = ranker.getBest(); assertNotNull(selected.getSHA1Urn()); }
/** tests that the ranker exhausts the list of rfds to try */ public void testExhaustsRFDs() throws Exception { ranker.addToPool(newRFD("1.2.3.4", 3)); ranker.addToPool(newRFDWithURN("1.2.3.4", 3)); assertTrue(ranker.hasMore()); ranker.getBest(); ranker.getBest(); assertFalse(ranker.hasMore()); }
/** * tests that when we receive a headpong claiming that it doesn't have the file, we send out an * NAlt for that source */ public void testHeadPongNAlts() throws Exception { testUploaders[0].setRate(100); testUploaders[1].setRate(100); int sleep = DownloadSettings.WORKER_INTERVAL.getValue(); // make sure we use the ping ranker networkManager.setCanReceiveSolicited(true); assertTrue(networkManager.canReceiveSolicited()); assertTrue(sourceRankerFactory.getAppropriateRanker() instanceof FriendsFirstSourceRanker); // create one source that will actually download and another one to which a headping should be // sent RemoteFileDesc rfd = newRFDWithURN(PORTS[0], false); RemoteFileDesc noFile = newRFDWithURN(PORTS[1], false); AlternateLocation toBeDemoted = alternateLocationFactory.create(noFile); // create a listener for the headping TestUDPAcceptor l = testUDPAcceptorFactoryImpl.createTestUDPAcceptor(PORTS[1], _currentTestName); ManagedDownloaderImpl download = (ManagedDownloaderImpl) downloadServices.download( new RemoteFileDesc[] {rfd}, RemoteFileDesc.EMPTY_LIST, null, false); SourceRanker ranker = download.getCurrentSourceRanker(); assertTrue(ranker instanceof FriendsFirstSourceRanker); LOG.debug("started download"); // after a while clear the ranker and add the second host. Thread.sleep((int) (sleep * 1.5)); ranker.stop(); ranker.setMeshHandler(download); download.addDownload(noFile, false); LOG.debug("waiting for download to complete"); waitForComplete(); // the first downloader should have received an NAlt assertTrue(testUploaders[0].getIncomingBadAltLocs().contains(toBeDemoted)); // the first uploader should have uploaded the whole file assertGreaterThan(0, testUploaders[0].getConnections()); assertEquals(TestFile.length(), testUploaders[0].fullRequestsUploaded()); // the second downloader should not be contacted assertEquals(0, testUploaders[1].getConnections()); assertEquals(0, testUploaders[1].getAmountUploaded()); // only one ping should have been sent to the second uploader assertEquals(1, l.pings); l.shutdown(); }
public void testGetShareable() throws Exception { RemoteFileDescContext rfd1, rfd2; rfd1 = newRFD("1.2.3.4", 3); rfd2 = newRFDWithURN("1.2.3.4", 3); ranker.addToPool(rfd1); ranker.addToPool(rfd2); Collection c = ranker.getShareableHosts(); assertTrue(c.contains(rfd1)); assertTrue(c.contains(rfd2)); assertEquals(2, c.size()); }
/** tests that the ranker does not allow duplicate rfds */ public void testDisallowsDuplicates() throws Exception { RemoteFileDescContext rfd1, rfd2; rfd1 = newRFDWithURN("1.2.3.4", 3); rfd2 = newRFDWithURN("1.2.3.4", 3); assertTrue(rfd1.equals(rfd2)); assertEquals(rfd1.hashCode(), rfd2.hashCode()); assertSame(rfd1, rfd2); ranker.addToPool(rfd1); ranker.addToPool(rfd2); assertTrue(ranker.hasMore()); ranker.getBest(); assertFalse(ranker.hasMore()); }