public void testSimpleSwarmPush() throws Exception { LOG.info("-Testing swarming from two sources, one push..."); GUID guid = new GUID(); RemoteFileDesc rfd1 = newRFDWithURN(PORTS[0], false); AlternateLocation pushLoc = alternateLocationFactory.create( guid.toHexString() + ";127.0.0.1:" + PPORT_2, TestFile.hash()); ((PushAltLoc) pushLoc).updateProxies(true); RemoteFileDesc rfd2 = pushLoc.createRemoteFileDesc(TestFile.length(), remoteFileDescFactory); TestUploader uploader = injector.getInstance(TestUploader.class); uploader.start("push uploader"); uploader.setRate(100); testUploaders[0].setRate(100); RemoteFileDesc[] rfds = {rfd1, rfd2}; testUDPAcceptorFactoryImpl.createTestUDPAcceptor( PPORT_2, networkManager.getPort(), savedFile.getName(), uploader, guid, _currentTestName); tGeneric(rfds); assertLessThan( "u1 did all the work", TestFile.length(), testUploaders[0].fullRequestsUploaded()); assertGreaterThan("pusher did all the work ", 0, testUploaders[0].fullRequestsUploaded()); }
private RemoteFileDescContext newRFDWithURN(String host, int speed) throws Exception { Set set = new HashSet(); try { // for convenience, don't require that they pass the urn. // assume a null one is the TestFile's hash. set.add(TestFile.hash()); } catch (Exception e) { fail("SHA1 not created"); } return toContext( remoteFileDescFactory.createRemoteFileDesc( new ConnectableImpl(host, 1, false), 0, "asdf", TestFile.length(), new byte[16], speed, 4, false, null, set, false, "", -1)); }
/** * 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(); }
private RemoteFileDescContext newRFD(String host, int speed) throws Exception { return toContext( remoteFileDescFactory.createRemoteFileDesc( new ConnectableImpl(host, 1, false), 0, "asdf", TestFile.length(), new byte[16], speed, 4, false, null, URN.NO_URN_SET, false, "", -1)); }